module Handler.ReferenceListing where import Import import Handler.Common getReferenceListingR, postReferenceListingR :: Handler TypedContent getReferenceListingR = postReferenceListingR postReferenceListingR = do ((insertResult, fsInsertForm), fsInsertEncoding) <- runFormPost $ referenceForm Nothing mapM_ (addMessage "formError" . toHtml) =<< case insertResult of FormSuccess newReference -> [] <$ runDB (insert newReference) FormFailure errors -> return errors _ -> return [] reference <- runDB $ selectList [] [Asc ReferenceKind] selectRep $ do provideJson (reference :: [Entity Reference]) provideRep . defaultLayout $ referenceListing ReferenceState { refFormState = Just InsertForm{..} , .. } putReferenceListingR :: Handler Value putReferenceListingR = returnJson =<< runDB . insertEntity =<< (requireCheckJsonBody :: Handler Reference)