summaryrefslogtreecommitdiff
path: root/Handler/UpdateItem.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/UpdateItem.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/UpdateItem.hs')
-rw-r--r--Handler/UpdateItem.hs33
1 files changed, 33 insertions, 0 deletions
diff --git a/Handler/UpdateItem.hs b/Handler/UpdateItem.hs
new file mode 100644
index 0000000..353572b
--- /dev/null
+++ b/Handler/UpdateItem.hs
@@ -0,0 +1,33 @@
1module Handler.UpdateItem where
2
3import Import
4
5import Handler.Common
6
7getUpdateItemR, postUpdateItemR :: ItemId -> Handler TypedContent
8getUpdateItemR = postUpdateItemR
9postUpdateItemR fsUpdateItem = do
10 Just entity <- fmap (Entity fsUpdateItem) <$> runDB (get fsUpdateItem)
11
12 ((updateResult, fsUpdateForm), fsUpdateEncoding) <- runFormPost . itemForm . Just $ entityVal entity
13
14 mapM_ (addMessage "formError" . toHtml) =<< case updateResult of
15 FormSuccess Item{..} -> [] <$ runDB (update fsUpdateItem [ ItemKind =. itemKind
16 , ItemNormKind =. normalizeKind itemKind
17 , ItemBought =. itemBought
18 , ItemExpires =. itemExpires
19 , ItemOpened =. itemOpened
20 ])
21 FormFailure errors -> return errors
22 _ -> return []
23
24 selectRep $ do
25 provideRep $ case updateResult of
26 FormSuccess _ -> redirect $ InventoryListingR :#: fsUpdateItem :: Handler Html
27 _ -> do
28 (sortOn entityVal -> stock) <- runDB $ selectList [] []
29 defaultLayout $ inventoryListing InventoryState
30 { formState = Just UpdateForm{..}
31 , ..
32 }
33 provideJson ()