Created
September 24, 2014 15:24
-
-
Save prasmussen/212e25acc1343311bfe0 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
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