From d84b462a711ce95593ff05a7581e722562c3835a Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 14 Mar 2017 01:06:28 +0100 Subject: Implement old bar.hs --- Handler/Item.hs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Handler/Item.hs (limited to 'Handler/Item.hs') diff --git a/Handler/Item.hs b/Handler/Item.hs new file mode 100644 index 0000000..87030bb --- /dev/null +++ b/Handler/Item.hs @@ -0,0 +1,31 @@ +module Handler.Item where + +import Import + +getItemR :: ItemId -> Handler TypedContent +getItemR itemId = do + eLookup <- runDB $ fmap (Entity itemId) <$> get itemId + case eLookup of + Nothing -> notFound + Just entity -> selectRep $ do + provideJson entity + provideRep (redirect $ InventoryListingR :#: itemId :: Handler Html) + +putItemR :: ItemId -> Handler Value +putItemR itemId = do + Item{..} <- requireCheckJsonBody + returnJson . Entity itemId =<< runDB + (updateGet itemId [ ItemKind =. itemKind + , ItemNormKind =. itemNormKind + , ItemBought =. itemBought + , ItemExpires =. itemExpires + , ItemOpened =. itemOpened + ]) + +patchItemR :: ItemId -> Handler Value +patchItemR itemId = do + diffs <- (requireCheckJsonBody :: Handler ItemDiffs) + returnJson . Entity itemId =<< runDB (updateGet itemId $ toUpdate diffs) + +deleteItemR :: ItemId -> Handler () +deleteItemR = runDB . delete -- cgit v1.2.3