2019-04-17 05:51:15 +00:00
|
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
|
|
module Types.Refine where
|
|
|
|
|
|
|
|
import GHC.Generics
|
|
|
|
|
|
|
|
import Web.HttpApiData
|
|
|
|
|
2019-09-11 02:04:06 +00:00
|
|
|
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
|
2019-09-11 02:04:06 +00:00
|
|
|
"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
|
2019-09-11 02:04:06 +00:00
|
|
|
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"
|