]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blobdiff - src/TSN/XML/AutoRacingSchedule.hs
Make the AutoRacingSchedule status optional.
[dead/htsn-import.git] / src / TSN / XML / AutoRacingSchedule.hs
index 1f459860244b33d0e5c7b6b1d907e074a40e200b..69b9b35d4219166c4b33f29fd2f1f4e2ae8106b8 100644 (file)
@@ -59,6 +59,7 @@ import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate )
 import TSN.Picklers ( xp_date_padded, xp_tba_time, xp_time_stamp )
 import TSN.XmlImport ( XmlImport(..), XmlImportFk(..) )
 import Xml (
+  Child(..),
   FromXml(..),
   FromXmlFk(..),
   ToDb(..),
@@ -140,7 +141,7 @@ instance XmlImport Message
 -- * AutoRacingScheduleListing/AutoRacingScheduleListingXml
 
 -- | Database representation of a \<Listing\> contained within a
---   \<Message\>. We combine the race date/time into a single
+--   \<message\>. We combine the race date/time into a single
 --   race_time, drop the race results list, and add a foreign key to
 --   our parent.
 --
@@ -192,12 +193,15 @@ instance ToDb AutoRacingScheduleListingXml where
   --
   type Db AutoRacingScheduleListingXml = AutoRacingScheduleListing
 
-instance FromXmlFk AutoRacingScheduleListingXml where
+
+instance Child AutoRacingScheduleListingXml where
   -- | Each 'AutoRacingScheduleListingXml' is contained in (i.e. has a
   --   foreign key to) a 'AutoRacingSchedule'.
   --
   type Parent AutoRacingScheduleListingXml = AutoRacingSchedule
 
+
+instance FromXmlFk AutoRacingScheduleListingXml where
   -- | To convert an 'AutoRacingScheduleListingXml' to an
   --   'AutoRacingScheduleListing', we add the foreign key and drop
   --   the 'xml_race_results'. We also mash the date/time together
@@ -244,8 +248,7 @@ newtype AutoRacingScheduleListingRaceResult =
   deriving (Eq, Show)
 
 
--- * AutoRacingScheduleListingRaceResultRaceResultListing /
---   AutoRacingScheduleListingRaceResultRaceResultListingXml
+-- * AutoRacingScheduleListingRaceResultRaceResultListing / AutoRacingScheduleListingRaceResultRaceResultListingXml
 --
 --   Sorry about the names yo.
 --
@@ -263,7 +266,8 @@ data AutoRacingScheduleListingRaceResultRaceResultListing =
     db_leading_laps :: Int,
     db_listing_laps :: Int, -- ^ Avoid clash with race's \"laps\" field.
     db_earnings :: String,  -- ^ This should be an Int, but can have commas.
-    db_status :: String }
+    db_status :: Maybe String -- ^ They can be empty
+    }
 
 
 -- | XML Representation of an
@@ -277,7 +281,8 @@ data AutoRacingScheduleListingRaceResultRaceResultListingXml =
     xml_leading_laps :: Int,
     xml_listing_laps :: Int, -- ^ Avoid clash with race's \"laps\" field.
     xml_earnings :: String,  -- ^ Should be an 'Int', but can have commas.
-    xml_status :: String }
+    xml_status :: Maybe String -- ^ They can be empty
+    }
   deriving (Eq, Show)
 
 
@@ -290,7 +295,7 @@ instance ToDb AutoRacingScheduleListingRaceResultRaceResultListingXml where
     AutoRacingScheduleListingRaceResultRaceResultListing
 
 
-instance FromXmlFk AutoRacingScheduleListingRaceResultRaceResultListingXml where
+instance Child AutoRacingScheduleListingRaceResultRaceResultListingXml where
   -- | Each 'AutoRacingScheduleListingRaceResultRaceResultListingXml'
   --   is contained in (i.e. has a foreign key to) an
   --   'AutoRacingScheduleListing'. We skip the intermediate
@@ -299,6 +304,8 @@ instance FromXmlFk AutoRacingScheduleListingRaceResultRaceResultListingXml where
   type Parent AutoRacingScheduleListingRaceResultRaceResultListingXml =
     AutoRacingScheduleListing
 
+
+instance FromXmlFk AutoRacingScheduleListingRaceResultRaceResultListingXml where
   -- | To convert an
   --   'AutoRacingScheduleListingRaceResultRaceResultListingXml' to an
   --   'AutoRacingScheduleListingRaceResultRaceResultListing', we just
@@ -313,7 +320,7 @@ instance FromXmlFk AutoRacingScheduleListingRaceResultRaceResultListingXml where
       db_leading_laps = xml_leading_laps,
       db_listing_laps = xml_listing_laps,
       db_earnings = xml_earnings,
-      db_status = xml_earnings }
+      db_status = xml_status }
 
 
 -- | This allows us to insert the XML representation
@@ -469,7 +476,7 @@ pickle_race_results_listing =
                (xpElem "LeadingLaps" xpInt)
                (xpElem "Laps" xpInt)
                (xpElem "Earnings" xpText)
-               (xpElem "Status" xpText)
+               (xpElem "Status" (xpOption xpText))
   where
     from_tuple =
       uncurryN AutoRacingScheduleListingRaceResultRaceResultListingXml