Allow API users to create Trip entries
Next up: - list trips - update existing trip entries - delete existing trip entries
This commit is contained in:
parent
475f62fb16
commit
52ac4d79bd
3 changed files with 79 additions and 3 deletions
12
src/App.hs
12
src/App.hs
|
|
@ -17,11 +17,13 @@ import qualified Types as T
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
server :: FilePath -> Server API
|
||||
server dbFile =
|
||||
userAddH :<|> userGetH
|
||||
server dbFile = userAddH
|
||||
:<|> userGetH
|
||||
:<|> createTripH
|
||||
where
|
||||
userAddH newUser = liftIO $ userAdd newUser
|
||||
userGetH name = liftIO $ userGet name
|
||||
createTripH trip = liftIO $ createTrip trip
|
||||
|
||||
-- TODO(wpcarro): Handle failed CONSTRAINTs instead of sending 500s
|
||||
userAdd :: T.Account -> IO (Maybe T.Session)
|
||||
|
|
@ -40,6 +42,12 @@ server dbFile =
|
|||
[x] -> pure (Just x)
|
||||
_ -> pure Nothing
|
||||
|
||||
createTrip :: T.Trip -> IO Bool
|
||||
createTrip trip = withConnection dbFile $ \conn -> do
|
||||
execute conn "INSERT INTO Trips (username,destination,startDate,endDate,comment) VALUES (?,?,?,?,?)"
|
||||
(trip & T.tripFields)
|
||||
pure True
|
||||
|
||||
mkApp :: FilePath -> IO Application
|
||||
mkApp dbFile = do
|
||||
pure $ serve (Proxy @ API) $ server dbFile
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue