mateamt/src/Types/Refine.hs

44 lines
1.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
data UserRefine = AllUsers | ActiveUsers | 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
"all" -> Right AllUsers
"active" -> Right ActiveUsers
"old" -> Right OldUsers
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"
ActiveUsers -> "active"
OldUsers -> "old"
2019-09-09 10:57:08 +00:00
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"