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