diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-14 01:06:28 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-14 01:06:28 +0100 |
commit | d84b462a711ce95593ff05a7581e722562c3835a (patch) | |
tree | 41e5af455fea925b2680b29718b24ba2876e803a /Handler/InventoryListing.hs | |
download | bar-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.hs | 26 |
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 @@ | |||
1 | module Handler.InventoryListing where | ||
2 | |||
3 | import Import | ||
4 | import Handler.Common | ||
5 | |||
6 | getInventoryListingR, postInventoryListingR :: Handler TypedContent | ||
7 | getInventoryListingR = postInventoryListingR | ||
8 | postInventoryListingR = 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 | |||
25 | putInventoryListingR :: Handler Value | ||
26 | putInventoryListingR = returnJson =<< runDB . insertEntity =<< (requireCheckJsonBody :: Handler Item) | ||