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/Item.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/Item.hs')
-rw-r--r-- | Handler/Item.hs | 31 |
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 @@ | |||
1 | module Handler.Item where | ||
2 | |||
3 | import Import | ||
4 | |||
5 | getItemR :: ItemId -> Handler TypedContent | ||
6 | getItemR 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 | |||
14 | putItemR :: ItemId -> Handler Value | ||
15 | putItemR 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 | |||
25 | patchItemR :: ItemId -> Handler Value | ||
26 | patchItemR itemId = do | ||
27 | diffs <- (requireCheckJsonBody :: Handler ItemDiffs) | ||
28 | returnJson . Entity itemId =<< runDB (updateGet itemId $ toUpdate diffs) | ||
29 | |||
30 | deleteItemR :: ItemId -> Handler () | ||
31 | deleteItemR = runDB . delete | ||