module Handler.InventoryListing where import Import import Handler.Common getInventoryListingR, postInventoryListingR :: Handler TypedContent getInventoryListingR = postInventoryListingR postInventoryListingR = do ((insertResult, fsInsertForm), fsInsertEncoding) <- runFormPost $ itemForm Nothing case insertResult of FormSuccess (Item{..} `WithType` t) -> runDB $ do upsertBy (UniqueKind itemNormKind) (Kind itemNormKind t) [ KindType =. t ] insert Item{..} return () FormFailure errors -> mapM_ (addMessage "formError" . toHtml) errors _ -> return () (sortOn (entityVal . typedVal) -> stock) <- runDB $ mapM withType =<< selectList [] [] selectRep $ do provideJson (stock :: [WithType (Entity Item)]) provideRep . defaultLayout $ inventoryListing InventoryState { invFormState = Just InsertForm{..} , .. } putInventoryListingR :: Handler Value putInventoryListingR = do (Item{..} `WithType` t) <- requireCheckJsonBody returnJson <=< runDB $ do upsertBy (UniqueKind itemNormKind) (Kind itemNormKind t) [ KindType =. t ] withType =<< insertEntity Item{..}