blob: 12f36ba519f762123e6820c7a0fae87f5e6009f9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
module Handler.InventoryListing where
import Import
import Handler.Common
getInventoryListingR, postInventoryListingR :: Handler TypedContent
getInventoryListingR = postInventoryListingR
postInventoryListingR = do
((insertResult, fsInsertForm), fsInsertEncoding) <- runFormPost $ itemForm Nothing
mapM_ (addMessage "formError" . toHtml) =<< case insertResult of
FormSuccess newItem -> [] <$ runDB (insert newItem)
FormFailure errors -> return errors
_ -> return []
(sortOn entityVal -> stock) <- runDB $ selectList [] []
selectRep $ do
provideJson (stock :: [Entity Item])
provideRep . defaultLayout $ inventoryListing InventoryState
{ invFormState = Just InsertForm{..}
, ..
}
putInventoryListingR :: Handler Value
putInventoryListingR = returnJson =<< runDB . insertEntity =<< (requireCheckJsonBody :: Handler Item)
|