summaryrefslogtreecommitdiff
path: root/Handler/ReferenceListing.hs
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-03-15 14:47:31 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2017-03-15 14:47:31 +0100
commitfe5cd6ad6c61eb13ca99acd1b69cd09b84051404 (patch)
tree4afc8cb5ae4171047d6af17082fb74d49c726abe /Handler/ReferenceListing.hs
parent668961c90368b55a3409ae93b96e288f8ebe33a4 (diff)
downloadbar-fe5cd6ad6c61eb13ca99acd1b69cd09b84051404.tar
bar-fe5cd6ad6c61eb13ca99acd1b69cd09b84051404.tar.gz
bar-fe5cd6ad6c61eb13ca99acd1b69cd09b84051404.tar.bz2
bar-fe5cd6ad6c61eb13ca99acd1b69cd09b84051404.tar.xz
bar-fe5cd6ad6c61eb13ca99acd1b69cd09b84051404.zip
Support types
Diffstat (limited to 'Handler/ReferenceListing.hs')
-rw-r--r--Handler/ReferenceListing.hs21
1 files changed, 14 insertions, 7 deletions
diff --git a/Handler/ReferenceListing.hs b/Handler/ReferenceListing.hs
index 0f777ee..0b89a20 100644
--- a/Handler/ReferenceListing.hs
+++ b/Handler/ReferenceListing.hs
@@ -9,19 +9,26 @@ getReferenceListingR = postReferenceListingR
9postReferenceListingR = do 9postReferenceListingR = do
10 ((insertResult, fsInsertForm), fsInsertEncoding) <- runFormPost $ referenceForm Nothing 10 ((insertResult, fsInsertForm), fsInsertEncoding) <- runFormPost $ referenceForm Nothing
11 11
12 mapM_ (addMessage "formError" . toHtml) =<< case insertResult of 12 case insertResult of
13 FormSuccess newReference -> [] <$ runDB (insert newReference) 13 FormSuccess (Reference{..} `WithType` t) -> runDB $ do
14 FormFailure errors -> return errors 14 upsertBy (UniqueKind referenceNormKind) (Kind referenceNormKind t) [ KindType =. t ]
15 _ -> return [] 15 insert Reference{..}
16 return ()
17 FormFailure errors -> mapM_ (addMessage "formError" . toHtml) errors
18 _ -> return ()
16 19
17 reference <- runDB $ selectList [] [Asc ReferenceKind] 20 reference <- runDB $ mapM withType =<< selectList [] [Asc ReferenceKind]
18 21
19 selectRep $ do 22 selectRep $ do
20 provideJson (reference :: [Entity Reference]) 23 provideJson (reference :: [WithType (Entity Reference)])
21 provideRep . defaultLayout $ referenceListing ReferenceState 24 provideRep . defaultLayout $ referenceListing ReferenceState
22 { refFormState = Just InsertForm{..} 25 { refFormState = Just InsertForm{..}
23 , .. 26 , ..
24 } 27 }
25 28
26putReferenceListingR :: Handler Value 29putReferenceListingR :: Handler Value
27putReferenceListingR = returnJson =<< runDB . insertEntity =<< (requireCheckJsonBody :: Handler Reference) 30putReferenceListingR = do
31 (Reference{..} `WithType` referenceType) <- requireCheckJsonBody
32 returnJson <=< runDB $ do
33 upsertBy (UniqueKind referenceNormKind) (Kind referenceNormKind referenceType) [ KindType =. referenceType ]
34 withType =<< insertEntity Reference{..}