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/InventoryListing.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/InventoryListing.hs')
-rw-r--r-- | Handler/InventoryListing.hs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/Handler/InventoryListing.hs b/Handler/InventoryListing.hs index 12f36ba..6d4d8fa 100644 --- a/Handler/InventoryListing.hs +++ b/Handler/InventoryListing.hs | |||
@@ -8,19 +8,26 @@ getInventoryListingR = postInventoryListingR | |||
8 | postInventoryListingR = do | 8 | postInventoryListingR = do |
9 | ((insertResult, fsInsertForm), fsInsertEncoding) <- runFormPost $ itemForm Nothing | 9 | ((insertResult, fsInsertForm), fsInsertEncoding) <- runFormPost $ itemForm Nothing |
10 | 10 | ||
11 | mapM_ (addMessage "formError" . toHtml) =<< case insertResult of | 11 | case insertResult of |
12 | FormSuccess newItem -> [] <$ runDB (insert newItem) | 12 | FormSuccess (Item{..} `WithType` t) -> runDB $ do |
13 | FormFailure errors -> return errors | 13 | upsertBy (UniqueKind itemNormKind) (Kind itemNormKind t) [ KindType =. t ] |
14 | _ -> return [] | 14 | insert Item{..} |
15 | return () | ||
16 | FormFailure errors -> mapM_ (addMessage "formError" . toHtml) errors | ||
17 | _ -> return () | ||
15 | 18 | ||
16 | (sortOn entityVal -> stock) <- runDB $ selectList [] [] | 19 | (sortOn (entityVal . typedVal) -> stock) <- runDB $ mapM withType =<< selectList [] [] |
17 | 20 | ||
18 | selectRep $ do | 21 | selectRep $ do |
19 | provideJson (stock :: [Entity Item]) | 22 | provideJson (stock :: [WithType (Entity Item)]) |
20 | provideRep . defaultLayout $ inventoryListing InventoryState | 23 | provideRep . defaultLayout $ inventoryListing InventoryState |
21 | { invFormState = Just InsertForm{..} | 24 | { invFormState = Just InsertForm{..} |
22 | , .. | 25 | , .. |
23 | } | 26 | } |
24 | 27 | ||
25 | putInventoryListingR :: Handler Value | 28 | putInventoryListingR :: Handler Value |
26 | putInventoryListingR = returnJson =<< runDB . insertEntity =<< (requireCheckJsonBody :: Handler Item) | 29 | putInventoryListingR = do |
30 | (Item{..} `WithType` t) <- requireCheckJsonBody | ||
31 | returnJson <=< runDB $ do | ||
32 | upsertBy (UniqueKind itemNormKind) (Kind itemNormKind t) [ KindType =. t ] | ||
33 | withType =<< insertEntity Item{..} | ||