blob: 87030bb437e866cdc132935096e7dc75d18229f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
module Handler.Item where
import Import
getItemR :: ItemId -> Handler TypedContent
getItemR itemId = do
eLookup <- runDB $ fmap (Entity itemId) <$> get itemId
case eLookup of
Nothing -> notFound
Just entity -> selectRep $ do
provideJson entity
provideRep (redirect $ InventoryListingR :#: itemId :: Handler Html)
putItemR :: ItemId -> Handler Value
putItemR itemId = do
Item{..} <- requireCheckJsonBody
returnJson . Entity itemId =<< runDB
(updateGet itemId [ ItemKind =. itemKind
, ItemNormKind =. itemNormKind
, ItemBought =. itemBought
, ItemExpires =. itemExpires
, ItemOpened =. itemOpened
])
patchItemR :: ItemId -> Handler Value
patchItemR itemId = do
diffs <- (requireCheckJsonBody :: Handler ItemDiffs)
returnJson . Entity itemId =<< runDB (updateGet itemId $ toUpdate diffs)
deleteItemR :: ItemId -> Handler ()
deleteItemR = runDB . delete
|