module Handler.ReferenceItem where import Import getReferenceItemR :: ReferenceId -> Handler TypedContent getReferenceItemR referenceId = do entity <- runDB $ withType =<< Entity referenceId <$> get404 referenceId selectRep $ do provideJson entity provideRep (redirect $ ReferenceListingR :#: referenceId :: Handler Html) putReferenceItemR :: ReferenceId -> Handler Value putReferenceItemR referenceId = do (Reference{..} `WithType` t) <- requireCheckJsonBody returnJson <=< runDB $ do entity <- Entity referenceId <$> updateGet referenceId [ ReferenceKind =. referenceKind , ReferenceNormKind =. referenceNormKind ] update (referenceFkType $ entityVal entity) [ KindType =. t ] withType entity deleteReferenceItemR :: ReferenceId -> Handler () deleteReferenceItemR = runDB . delete