about summary refs log tree commit diff
path: root/src/Types.hs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-07-28T09·14+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-07-28T09·14+0100
commit6d9e76313d1f89dcf4c1adb7bfabd811a65bd83a (patch)
tree65b41771610fb43c4f6cc81c6b958c9acf5ee4bf /src/Types.hs
parent0637da36ccac7e609041bc8999e3da348171f95f (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/Types.hs')
-rw-r--r--src/Types.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Types.hs b/src/Types.hs
index 112b17c53ab2..6d6b83347931 100644
--- a/src/Types.hs
+++ b/src/Types.hs
@@ -199,6 +199,24 @@ instance FromRow Trip where
                  <*> field
                  <*> field
 
+-- | The fields used as the Primary Key for a Trip entry.
+data TripPK = TripPK
+  { tripPKUsername :: Username
+  , tripPKDestination :: Destination
+  , tripPKStartDate :: Date
+  } deriving (Eq, Show, Generic)
+
+tripPKFields :: TripPK -> (Username, Destination, Date)
+tripPKFields (TripPK{ tripPKUsername
+                    , tripPKDestination
+                    , tripPKStartDate
+                    })
+  = (tripPKUsername, tripPKDestination, tripPKStartDate)
+
+-- TODO(wpcarro): Prefer shorter JSON fields like username instead of
+-- tripPKUsername.
+instance FromJSON TripPK
+
 -- | Return the tuple representation of a Trip record for SQL.
 tripFields :: Trip -> (Username, Destination, Date, Date, Comment)
 tripFields (Trip{ tripUsername