summaryrefslogtreecommitdiff
path: root/Handler/Item.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/Item.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/Item.hs')
-rw-r--r--Handler/Item.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/Handler/Item.hs b/Handler/Item.hs
new file mode 100644
index 0000000..87030bb
--- /dev/null
+++ b/Handler/Item.hs
@@ -0,0 +1,31 @@
1module Handler.Item where
2
3import Import
4
5getItemR :: ItemId -> Handler TypedContent
6getItemR itemId = do
7 eLookup <- runDB $ fmap (Entity itemId) <$> get itemId
8 case eLookup of
9 Nothing -> notFound
10 Just entity -> selectRep $ do
11 provideJson entity
12 provideRep (redirect $ InventoryListingR :#: itemId :: Handler Html)
13
14putItemR :: ItemId -> Handler Value
15putItemR itemId = do
16 Item{..} <- requireCheckJsonBody
17 returnJson . Entity itemId =<< runDB
18 (updateGet itemId [ ItemKind =. itemKind
19 , ItemNormKind =. itemNormKind
20 , ItemBought =. itemBought
21 , ItemExpires =. itemExpires
22 , ItemOpened =. itemOpened
23 ])
24
25patchItemR :: ItemId -> Handler Value
26patchItemR itemId = do
27 diffs <- (requireCheckJsonBody :: Handler ItemDiffs)
28 returnJson . Entity itemId =<< runDB (updateGet itemId $ toUpdate diffs)
29
30deleteItemR :: ItemId -> Handler ()
31deleteItemR = runDB . delete