diff options
Diffstat (limited to 'src/App.hs')
-rw-r--r-- | src/App.hs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/App.hs b/src/App.hs index b80a3ba4f619..20d99e385ad2 100644 --- a/src/App.hs +++ b/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 |