diff options
author | Yuchen Pei <hi@ypei.me> | 2022-09-13 13:10:32 +1000 |
---|---|---|
committer | Yuchen Pei <hi@ypei.me> | 2022-09-13 13:10:32 +1000 |
commit | e1e795e8152c435ca408de3c373c6687f4bf415e (patch) | |
tree | 682102787d89e105a48aa61f7db1920e2fc2e434 /src | |
parent | e61c4e2ad09772108efa4407ecaa371f3f26beae (diff) |
separating out video type
Diffstat (limited to 'src')
-rw-r--r-- | src/Servall/Types.hs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/Servall/Types.hs b/src/Servall/Types.hs index e179e2c..69c2045 100644 --- a/src/Servall/Types.hs +++ b/src/Servall/Types.hs @@ -1,7 +1,16 @@ +{-# LANGUAGE OverloadedStrings #-} module Servall.Types ( WikiTemplate(..) + , Video(..) ) where +import Data.Aeson ( (.:) + , (.=) + , FromJSON(..) + , ToJSON(..) + , Value(..) + , object + ) import qualified Data.HashMap.Lazy as HM import Data.Text ( Text ) @@ -11,3 +20,31 @@ data WikiTemplate = WikiTemplate , wtFields :: HM.HashMap Text Text } deriving Show + +data Video = Video + { vid :: Text + , vtitle :: Text + , vdesc :: Text + , vduration :: Int + } + deriving (Eq, Show) + +instance FromJSON Video where + parseJSON (Object o) = + Video + <$> o + .: "id" + <*> o + .: "title" + <*> o + .: "description" + <*> o + .: "duration" + +instance ToJSON Video where + toJSON (Video vid title desc duration) = object + [ "id" .= vid + , "title" .= title + , "description" .= desc + , "duration" .= duration + ] |