xpOption,
xpPair,
xpText,
- xpTriple,
xpWrap )
-- Local imports.
import TSN.Database ( insert_or_select )
import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate )
import TSN.Picklers ( xp_time_stamp )
-import TSN.Location ( Location(..) )
+import TSN.Location ( Location(..), pickle_location )
import TSN.XmlImport ( XmlImport(..) )
import Xml (
FromXml(..),
xml_sport :: String,
xml_url :: Maybe String,
xml_teams :: [NewsTeam],
- xml_locations :: [NewsLocationXml],
+ xml_locations :: [Location],
xml_sms :: String,
xml_editor :: Maybe String,
xml_text :: Maybe String, -- Text and continue seem to show up in pairs,
(DefaultKey NewsTeam)
--- * NewsLocationXml
-
--- | The XML type for locations as they show up in the news. The
--- associated database type comes from "TSN.Location".
---
-data NewsLocationXml =
- NewsLocationXml {
- xml_city :: Maybe String,
- xml_state :: Maybe String,
- xml_country :: String }
- deriving (Eq, Show)
-
-
-instance ToDb NewsLocationXml where
- -- | The database analogue of a NewsLocationXml is a Location.
- type Db NewsLocationXml = Location
-
-
-instance FromXml NewsLocationXml where
- -- | To convert from the XML representation to the database one, we
- -- don't have to do anything. Just copy the fields.
- --
- from_xml NewsLocationXml{..} =
- Location xml_city xml_state xml_country
-
-
--- | Allow us to import the XML representation directly into the
--- database, without having to perform the conversion manually first.
---
-instance XmlImport NewsLocationXml
-
-
-- * News_Location
-- | Mapping between 'News' records and 'Location' records in the
mapM_ insert_ news_news_teams
-- Do all of that over again for the Locations.
- loc_ids <- mapM insert_xml_or_select (xml_locations message)
+ loc_ids <- mapM insert_or_select (xml_locations message)
let news_news_locations = map (News_Location news_id) loc_ids
mapM_ insert_ news_news_locations
to_tuple m = (db_msg_id m, db_event_id m)
--- | Convert a 'NewsLocationXml' to/from XML.
---
-pickle_location :: PU NewsLocationXml
-pickle_location =
- xpElem "location" $
- xpWrap (from_tuple, to_tuple) $
- xpTriple (xpOption (xpElem "city" xpText))
- (xpOption (xpElem "state" xpText))
- (xpElem "country" xpText)
- where
- from_tuple =
- uncurryN NewsLocationXml
- to_tuple l = (xml_city l, xml_state l, xml_country l)
-
-- | Convert a 'Message' to/from XML.
--