mateamt/src/Types/Refine.hs

42 lines
1 KiB
Haskell
Raw Normal View History

2019-04-17 05:51:15 +00:00
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module Types.Refine where
import GHC.Generics
import Web.HttpApiData
2019-09-09 10:57:08 +00:00
data UserRefine = AllUsers | OldUsers
2019-04-17 05:51:15 +00:00
deriving (Generic, Show, Enum)
2019-09-09 10:57:08 +00:00
instance FromHttpApiData UserRefine where
2019-04-17 05:51:15 +00:00
parseQueryParam t =
case t of
2019-09-09 10:57:08 +00:00
"all" -> Right AllUsers
"old" -> Right OldUsers
2019-04-17 05:51:15 +00:00
x -> Left ("Error: Unknown refine " <> x)
2019-09-09 10:57:08 +00:00
instance ToHttpApiData UserRefine where
toUrlPiece x = case x of
AllUsers -> "all"
OldUsers -> "old"
data ProductRefine = AllProducts | AvailableProducts | DepletedProducts
deriving (Generic, Show, Enum)
instance FromHttpApiData ProductRefine where
parseQueryParam t =
case t of
"all" -> Right AllProducts
"available" -> Right AvailableProducts
"depleted" -> Right DepletedProducts
x -> Left ("Error: Unknown refine " <> x)
instance ToHttpApiData ProductRefine where
toUrlPiece x = case x of
AllProducts -> "all"
AvailableProducts -> "available"
DepletedProducts -> "depleted"