start refining product overviews
This commit is contained in:
parent
3167a638df
commit
886651cac2
3 changed files with 32 additions and 8 deletions
|
@ -41,7 +41,8 @@ type MateAPI =
|
||||||
:> ReqBody '[JSON] [AmountRefill] :> Patch '[JSON] ()
|
:> ReqBody '[JSON] [AmountRefill] :> Patch '[JSON] ()
|
||||||
:<|> "product" :> AuthProtect "header-auth"
|
:<|> "product" :> AuthProtect "header-auth"
|
||||||
:> ReqBody '[JSON] [AmountUpdate] :> Put '[JSON] ()
|
:> 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]
|
:<|> "buy" :> AuthProtect "header-auth" :> ReqBody '[JSON] [PurchaseDetail]
|
||||||
:> Post '[JSON] PurchaseResult
|
:> Post '[JSON] PurchaseResult
|
||||||
|
|
|
@ -56,7 +56,7 @@ productStockUpdate Nothing _ =
|
||||||
{ errBody = "No Authentication present."
|
{ errBody = "No Authentication present."
|
||||||
}
|
}
|
||||||
|
|
||||||
productList :: MateHandler [ProductOverview]
|
productList :: Maybe ProductRefine :> MateHandler [ProductOverview]
|
||||||
productList = do
|
productList mrefine = do
|
||||||
conn <- rsConnection <$> ask
|
conn <- rsConnection <$> ask
|
||||||
productOverviewSelect conn
|
productOverviewSelect (fromMaybe AvailableProducts mrefine) conn
|
||||||
|
|
|
@ -7,12 +7,35 @@ import GHC.Generics
|
||||||
|
|
||||||
import Web.HttpApiData
|
import Web.HttpApiData
|
||||||
|
|
||||||
data Refine = All | Old
|
data UserRefine = AllUsers | OldUsers
|
||||||
deriving (Generic, Show, Enum)
|
deriving (Generic, Show, Enum)
|
||||||
|
|
||||||
instance FromHttpApiData Refine where
|
instance FromHttpApiData UserRefine where
|
||||||
parseQueryParam t =
|
parseQueryParam t =
|
||||||
case t of
|
case t of
|
||||||
"all" -> Right All
|
"all" -> Right AllUsers
|
||||||
"old" -> Right Old
|
"old" -> Right OldUsers
|
||||||
x -> Left ("Error: Unknown refine " <> x)
|
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"
|
||||||
|
|
Loading…
Reference in a new issue