Created
July 12, 2011 14:37
-
-
Save ocharles/1078098 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This changes bookAuthorCredit from AuthorCreditReference to AuthorCredit | |
loadAuthorCredit :: Book -> Model Book | |
-- This changes all PersonReference's in an AuthorCredit to just Person | |
loadForAuthorCredits :: AuthorCredit -> Model AuthorCredit | |
-- This gets the AuthorCredit for a Book | |
bookAuthorCredit :: Book -> AuthorCredit | |
-- This 'sets' the AuthorCredit for a Book (returning a new Book) | |
setAuthorCredit :: Book -> AuthorCredit -> Book | |
--- | |
do | |
book <- loadAuthorCredit book | |
book <- setAuthorCredit book <$> (loadForAuthorCredits $ bookAuthorCredit book) | |
-- | |
bookResource :: Controller () | |
bookResource = do | |
maybeGid <- (fromString . unpack . fromJust) <$> getParam "gid" | |
case maybeGid of | |
Nothing -> genericError 400 "Invalid BBID" | |
Just gid -> do | |
maybeBook <- model $ getBook gid | |
case maybeBook of | |
Nothing -> generic404 "The request book could not be found" | |
Just book -> do | |
book <- model $ loadAuthorCredit book | |
book <- model $ set lBookAuthorCredit book <$> (loadForAuthorCredits $ bookAuthorCredit book) | |
editions <- model $ findBookEditions book | |
output $ showBook book editions | |
where set field on = \val -> setL field val on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment