summaryrefslogtreecommitdiff
path: root/Handler/InventoryListing.hs
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-03-14 01:06:28 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2017-03-14 01:06:28 +0100
commitd84b462a711ce95593ff05a7581e722562c3835a (patch)
tree41e5af455fea925b2680b29718b24ba2876e803a /Handler/InventoryListing.hs
downloadbar-d84b462a711ce95593ff05a7581e722562c3835a.tar
bar-d84b462a711ce95593ff05a7581e722562c3835a.tar.gz
bar-d84b462a711ce95593ff05a7581e722562c3835a.tar.bz2
bar-d84b462a711ce95593ff05a7581e722562c3835a.tar.xz
bar-d84b462a711ce95593ff05a7581e722562c3835a.zip
Implement old bar.hs
Diffstat (limited to 'Handler/InventoryListing.hs')
-rw-r--r--Handler/InventoryListing.hs26
1 files changed, 26 insertions, 0 deletions
diff --git a/Handler/InventoryListing.hs b/Handler/InventoryListing.hs
new file mode 100644
index 0000000..e3c062e
--- /dev/null
+++ b/Handler/InventoryListing.hs
@@ -0,0 +1,26 @@
1module Handler.InventoryListing where
2
3import Import
4import Handler.Common
5
6getInventoryListingR, postInventoryListingR :: Handler TypedContent
7getInventoryListingR = postInventoryListingR
8postInventoryListingR = do
9 ((insertResult, fsInsertForm), fsInsertEncoding) <- runFormPost $ itemForm Nothing
10
11 mapM_ (addMessage "formError" . toHtml) =<< case insertResult of
12 FormSuccess newItem -> [] <$ runDB (insert newItem)
13 FormFailure errors -> return errors
14 _ -> return []
15
16 (sortOn entityVal -> stock) <- runDB $ selectList [] []
17
18 selectRep $ do
19 provideJson (stock :: [Entity Item])
20 provideRep . defaultLayout $ inventoryListing InventoryState
21 { formState = Just InsertForm{..}
22 , ..
23 }
24
25putInventoryListingR :: Handler Value
26putInventoryListingR = returnJson =<< runDB . insertEntity =<< (requireCheckJsonBody :: Handler Item)