Support GET /trips

In the spirit of support CRUDL, I added a GET /trips, which lists all of the
trips in the Trips table.
This commit is contained in:
William Carroll 2020-07-28 10:13:38 +01:00
parent 2f73d1db6c
commit 0637da36cc
3 changed files with 15 additions and 0 deletions

View file

@ -20,10 +20,12 @@ server :: FilePath -> Server API
server dbFile = userAddH
:<|> userGetH
:<|> createTripH
:<|> listTripsH
where
userAddH newUser = liftIO $ userAdd newUser
userGetH name = liftIO $ userGet name
createTripH trip = liftIO $ createTrip trip
listTripsH = liftIO $ listTrips
-- TODO(wpcarro): Handle failed CONSTRAINTs instead of sending 500s
userAdd :: T.Account -> IO (Maybe T.Session)
@ -48,6 +50,9 @@ server dbFile = userAddH
(trip & T.tripFields)
pure NoContent
listTrips :: IO [T.Trip]
listTrips = withConnection dbFile $ \conn -> do
query_ conn "SELECT * FROM Trips"
mkApp :: FilePath -> IO Application
mkApp dbFile = do
pure $ serve (Proxy @ API) $ server dbFile