summaryrefslogtreecommitdiff
path: root/Handler/Item.hs
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-03-15 14:47:31 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2017-03-15 14:47:31 +0100
commitfe5cd6ad6c61eb13ca99acd1b69cd09b84051404 (patch)
tree4afc8cb5ae4171047d6af17082fb74d49c726abe /Handler/Item.hs
parent668961c90368b55a3409ae93b96e288f8ebe33a4 (diff)
downloadbar-fe5cd6ad6c61eb13ca99acd1b69cd09b84051404.tar
bar-fe5cd6ad6c61eb13ca99acd1b69cd09b84051404.tar.gz
bar-fe5cd6ad6c61eb13ca99acd1b69cd09b84051404.tar.bz2
bar-fe5cd6ad6c61eb13ca99acd1b69cd09b84051404.tar.xz
bar-fe5cd6ad6c61eb13ca99acd1b69cd09b84051404.zip
Support types
Diffstat (limited to 'Handler/Item.hs')
-rw-r--r--Handler/Item.hs27
1 files changed, 16 insertions, 11 deletions
diff --git a/Handler/Item.hs b/Handler/Item.hs
index 0f48261..abb1b12 100644
--- a/Handler/Item.hs
+++ b/Handler/Item.hs
@@ -4,26 +4,31 @@ import Import
4 4
5getItemR :: ItemId -> Handler TypedContent 5getItemR :: ItemId -> Handler TypedContent
6getItemR itemId = do 6getItemR itemId = do
7 entity <- runDB $ Entity itemId <$> get404 itemId 7 entity <- runDB $ withType =<< Entity itemId <$> get404 itemId
8 selectRep $ do 8 selectRep $ do
9 provideJson entity 9 provideJson entity
10 provideRep (redirect $ InventoryListingR :#: itemId :: Handler Html) 10 provideRep (redirect $ InventoryListingR :#: itemId :: Handler Html)
11 11
12putItemR :: ItemId -> Handler Value 12putItemR :: ItemId -> Handler Value
13putItemR itemId = do 13putItemR itemId = do
14 Item{..} <- requireCheckJsonBody 14 (Item{..} `WithType` t) <- requireCheckJsonBody
15 returnJson . Entity itemId =<< runDB 15 returnJson <=< runDB $ do
16 (updateGet itemId [ ItemKind =. itemKind 16 entity <- Entity itemId <$> (updateGet itemId [ ItemKind =. itemKind
17 , ItemNormKind =. itemNormKind 17 , ItemNormKind =. itemNormKind
18 , ItemBought =. itemBought 18 , ItemBought =. itemBought
19 , ItemExpires =. itemExpires 19 , ItemExpires =. itemExpires
20 , ItemOpened =. itemOpened 20 , ItemOpened =. itemOpened
21 ]) 21 ])
22 update (itemFkType $ entityVal entity) [ KindType =. t ]
23 withType entity
22 24
23patchItemR :: ItemId -> Handler Value 25patchItemR :: ItemId -> Handler Value
24patchItemR itemId = do 26patchItemR itemId = do
25 diffs <- (requireCheckJsonBody :: Handler ItemDiffs) 27 (itemUpdates, typeUpdates) <- toUpdate <$> (requireCheckJsonBody :: Handler ItemDiffs)
26 returnJson . Entity itemId =<< runDB (updateGet itemId $ toUpdate diffs) 28 returnJson <=< runDB $ do
29 entity <- Entity itemId <$> updateGet itemId itemUpdates
30 update (itemFkType $ entityVal entity) typeUpdates
31 withType entity
27 32
28deleteItemR :: ItemId -> Handler () 33deleteItemR :: ItemId -> Handler ()
29deleteItemR = runDB . delete 34deleteItemR = runDB . delete