diff options
author | William Carroll <wpcarro@gmail.com> | 2020-07-28T09·14+0100 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-07-28T09·14+0100 |
commit | 6d9e76313d1f89dcf4c1adb7bfabd811a65bd83a (patch) | |
tree | 65b41771610fb43c4f6cc81c6b958c9acf5ee4bf /src/App.hs | |
parent | 0637da36ccac7e609041bc8999e3da348171f95f (diff) |
Partially support DELETE /trips
Allow a user to delete a trip entry from the Trips table using the Primary Key. While this type-checks and compiles, it doesn't appear to be working as intended. Perhaps I should use an auto-incrementing integer as the Primary Key. I'm not sure how I want to handle this, so I'm punting for now.
Diffstat (limited to 'src/App.hs')
-rw-r--r-- | src/App.hs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/App.hs b/src/App.hs index c4203137a4fc..7747951922fa 100644 --- a/src/App.hs +++ b/src/App.hs @@ -21,11 +21,13 @@ server dbFile = userAddH :<|> userGetH :<|> createTripH :<|> listTripsH + :<|> deleteTripH where - userAddH newUser = liftIO $ userAdd newUser - userGetH name = liftIO $ userGet name - createTripH trip = liftIO $ createTrip trip + userAddH newUser = liftIO $ userAdd newUser + userGetH name = liftIO $ userGet name + createTripH trip = liftIO $ createTrip trip listTripsH = liftIO $ listTrips + deleteTripH tripPK = liftIO $ deleteTrip tripPK -- TODO(wpcarro): Handle failed CONSTRAINTs instead of sending 500s userAdd :: T.Account -> IO (Maybe T.Session) @@ -53,6 +55,15 @@ server dbFile = userAddH listTrips :: IO [T.Trip] listTrips = withConnection dbFile $ \conn -> do query_ conn "SELECT * FROM Trips" + + -- TODO(wpcarro): Validate incoming data like startDate. + deleteTrip :: T.TripPK -> IO NoContent + deleteTrip tripPK = + withConnection dbFile $ \conn -> do + execute conn "DELETE FROM Trips WHERE username = ? AND destination = ? and startDate = ?" + (tripPK & T.tripPKFields) + pure NoContent + mkApp :: FilePath -> IO Application mkApp dbFile = do pure $ serve (Proxy @ API) $ server dbFile |