start refining product overviews

This commit is contained in:
nek0 2019-09-09 12:57:08 +02:00
parent 3167a638df
commit 886651cac2
3 changed files with 32 additions and 8 deletions

View file

@ -41,7 +41,8 @@ type MateAPI =
:> ReqBody '[JSON] [AmountRefill] :> Patch '[JSON] ()
:<|> "product" :> AuthProtect "header-auth"
:> ReqBody '[JSON] [AmountUpdate] :> Put '[JSON] ()
:<|> "product" :> "list" :> Get '[JSON] [ProductOverview]
:<|> "product" :> "list" :> QueryParam "refine" ProductRefine
:> Get '[JSON] [ProductOverview]
:<|> "buy" :> AuthProtect "header-auth" :> ReqBody '[JSON] [PurchaseDetail]
:> Post '[JSON] PurchaseResult

View file

@ -56,7 +56,7 @@ productStockUpdate Nothing _ =
{ errBody = "No Authentication present."
}
productList :: MateHandler [ProductOverview]
productList = do
productList :: Maybe ProductRefine :> MateHandler [ProductOverview]
productList mrefine = do
conn <- rsConnection <$> ask
productOverviewSelect conn
productOverviewSelect (fromMaybe AvailableProducts mrefine) conn

View file

@ -7,12 +7,35 @@ import GHC.Generics
import Web.HttpApiData
data Refine = All | Old
data UserRefine = AllUsers | OldUsers
deriving (Generic, Show, Enum)
instance FromHttpApiData Refine where
instance FromHttpApiData UserRefine where
parseQueryParam t =
case t of
"all" -> Right All
"old" -> Right Old
"all" -> Right AllUsers
"old" -> Right OldUsers
x -> Left ("Error: Unknown refine " <> x)
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"