refactor(lms): encode bool by 0 and 1 in lms csv export/import
This commit is contained in:
parent
aa54bba62b
commit
7b8e566f65
@ -39,6 +39,7 @@ derivePersistFieldJSON ''LmsStatus
|
|||||||
|
|
||||||
|
|
||||||
-- LMS Interface requires Bool to be encoded by 0 or 1 only
|
-- LMS Interface requires Bool to be encoded by 0 or 1 only
|
||||||
|
{-
|
||||||
data LmsBool = LmsUnset | LmsSet
|
data LmsBool = LmsUnset | LmsSet
|
||||||
deriving (Eq, Ord, Read, Show, Generic, Typeable, NFData)
|
deriving (Eq, Ord, Read, Show, Generic, Typeable, NFData)
|
||||||
|
|
||||||
@ -61,3 +62,20 @@ instance Csv.FromField LmsBool where
|
|||||||
| i == "0" = pure LmsUnset
|
| i == "0" = pure LmsUnset
|
||||||
| i == "1" = pure LmsSet
|
| i == "1" = pure LmsSet
|
||||||
| otherwise = empty
|
| otherwise = empty
|
||||||
|
-}
|
||||||
|
|
||||||
|
newtype LmsBool = LmsBool { lms2bool :: Bool }
|
||||||
|
deriving (Eq, Ord, Read, Show, Generic, Typeable)
|
||||||
|
|
||||||
|
_lmsBool :: Iso' Bool LmsBool
|
||||||
|
_lmsBool = iso LmsBool lms2bool
|
||||||
|
|
||||||
|
instance Csv.ToField LmsBool where
|
||||||
|
toField (LmsBool False) = "0"
|
||||||
|
toField (LmsBool True ) = "1"
|
||||||
|
|
||||||
|
instance Csv.FromField LmsBool where
|
||||||
|
parseField i
|
||||||
|
| i == "0" = pure $ LmsBool False
|
||||||
|
| i == "1" = pure $ LmsBool True
|
||||||
|
| otherwise = empty
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user