diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-15 14:47:31 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-15 14:47:31 +0100 |
commit | fe5cd6ad6c61eb13ca99acd1b69cd09b84051404 (patch) | |
tree | 4afc8cb5ae4171047d6af17082fb74d49c726abe /Handler/Item.hs | |
parent | 668961c90368b55a3409ae93b96e288f8ebe33a4 (diff) | |
download | bar-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.hs | 27 |
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 | ||
5 | getItemR :: ItemId -> Handler TypedContent | 5 | getItemR :: ItemId -> Handler TypedContent |
6 | getItemR itemId = do | 6 | getItemR 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 | ||
12 | putItemR :: ItemId -> Handler Value | 12 | putItemR :: ItemId -> Handler Value |
13 | putItemR itemId = do | 13 | putItemR 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 | ||
23 | patchItemR :: ItemId -> Handler Value | 25 | patchItemR :: ItemId -> Handler Value |
24 | patchItemR itemId = do | 26 | patchItemR 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 | ||
28 | deleteItemR :: ItemId -> Handler () | 33 | deleteItemR :: ItemId -> Handler () |
29 | deleteItemR = runDB . delete | 34 | deleteItemR = runDB . delete |