Skip to content

Instantly share code, notes, and snippets.

@ocharles
Created July 12, 2011 15:39
Show Gist options
  • Save ocharles/1078227 to your computer and use it in GitHub Desktop.
Save ocharles/1078227 to your computer and use it in GitHub Desktop.
bookResource :: Controller ()
bookResource = do
gid <- ((fromString . unpack . fromJust) <$> getParam "gid") >>= (\gid' -> gid' `onNothing` "Invalid BBID")
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 onNothing (Just a) _ = return a
onNothing Nothing message = throwError message
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