module Handler.UpdateItem where import Import import Handler.Common getUpdateItemR, postUpdateItemR :: ItemId -> Handler TypedContent getUpdateItemR = postUpdateItemR postUpdateItemR fsUpdateId = do Just entity <- fmap (Entity fsUpdateId) <$> runDB (get fsUpdateId) ((updateResult, fsUpdateForm), fsUpdateEncoding) <- runFormPost . itemForm . Just $ entityVal entity mapM_ (addMessage "formError" . toHtml) =<< case updateResult of FormSuccess Item{..} -> [] <$ runDB (update fsUpdateId [ ItemKind =. itemKind , ItemNormKind =. normalizeKind itemKind , ItemBought =. itemBought , ItemExpires =. itemExpires , ItemOpened =. itemOpened ]) FormFailure errors -> return errors _ -> return [] selectRep $ do provideRep $ case updateResult of FormSuccess _ -> redirect $ InventoryListingR :#: fsUpdateId :: Handler Html _ -> do (sortOn entityVal -> stock) <- runDB $ selectList [] [] defaultLayout $ inventoryListing InventoryState { invFormState = Just UpdateForm{..} , .. } provideJson ()