Skip to content

Instantly share code, notes, and snippets.

@prasmussen
Created September 24, 2014 15:24
Show Gist options
  • Save prasmussen/212e25acc1343311bfe0 to your computer and use it in GitHub Desktop.
Save prasmussen/212e25acc1343311bfe0 to your computer and use it in GitHub Desktop.
data DesignData = DesignData {
getName :: Text,
getAge :: Int
} deriving Show
instance FromJSON DesignData where
parseJSON (Object obj) =
DesignData <$>
obj .: "name" <*>
obj .: "age"
parseJSON _ = mzero
createDesign :: Handler Value
createDesign = do
uid <- requireAuthId
payload <- requireJsonBody :: Handler DesignData
now <- liftIO getCurrentTime
designId <- runDB $ insert $ Design uid (getName payload) (getAge payload) now
return $ object ["id" .= designId]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment