diff options
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 | ||