about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-07-31T10·27+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-07-31T10·27+0100
commit43eff5f1d037b3e45a3b7a274048527e2a95103d (patch)
tree5825ad44271b7710af157216a3f7adcac596ffa0
parented557fb6be749b0b06666674e35db4a75655af08 (diff)
Prefer RecordWildCards for FromJSON instances
Stylistically, I think this looks cleaner.
-rw-r--r--src/Types.hs46
1 files changed, 18 insertions, 28 deletions
diff --git a/src/Types.hs b/src/Types.hs
index 273d4aecca70..485111f38bac 100644
--- a/src/Types.hs
+++ b/src/Types.hs
@@ -250,13 +250,10 @@ tripPKFields (TripPK{ tripPKUsername
 
 instance FromJSON TripPK where
   parseJSON = withObject "TripPK" $ \x -> do
-    username <- x .: "username"
-    destination <- x .: "destination"
-    startDate <- x .: "startDate"
-    pure TripPK{ tripPKUsername = username
-               , tripPKDestination = destination
-               , tripPKStartDate = startDate
-               }
+    tripPKUsername    <- x .: "username"
+    tripPKDestination <- x .: "destination"
+    tripPKStartDate   <- x .: "startDate"
+    pure TripPK{..}
 
 -- | Return the tuple representation of a Trip record for SQL.
 tripFields :: Trip -> (Username, Destination, Date, Date, Comment)
@@ -284,17 +281,12 @@ instance ToJSON Trip where
 
 instance FromJSON Trip where
   parseJSON = withObject "Trip" $ \x -> do
-    username <- x .: "username"
-    destination <- x .: "destination"
-    startDate <- x .: "startDate"
-    endDate <- x .: "endDate"
-    comment <- x .: "comment"
-    pure Trip{ tripUsername = username
-             , tripDestination = destination
-             , tripStartDate = startDate
-             , tripEndDate = endDate
-             , tripComment = comment
-             }
+    tripUsername    <- x .: "username"
+    tripDestination <- x .: "destination"
+    tripStartDate   <- x .: "startDate"
+    tripEndDate     <- x .: "endDate"
+    tripComment     <- x .: "comment"
+    pure Trip{..}
 
 -- | Users and Accounts both refer to the same underlying entities; however,
 -- Users model the user-facing Account details, hiding sensitive details like
@@ -328,11 +320,9 @@ data AccountCredentials = AccountCredentials
 
 instance FromJSON AccountCredentials where
   parseJSON = withObject "AccountCredentials" $ \x -> do
-    username <- x.: "username"
-    password <- x.: "password"
-    pure AccountCredentials{ accountCredentialsUsername = username
-                           , accountCredentialsPassword = password
-                           }
+    accountCredentialsUsername <- x.: "username"
+    accountCredentialsPassword <- x.: "password"
+    pure AccountCredentials{..}
 
 
 -- | Hash password `x`.
@@ -355,11 +345,11 @@ data CreateAccountRequest = CreateAccountRequest
 
 instance FromJSON CreateAccountRequest where
   parseJSON = withObject "CreateAccountRequest" $ \x -> do
-    username <- x .: "username"
-    password <- x .: "password"
-    email <- x .: "email"
-    role <- x .: "role"
-    pure $ CreateAccountRequest username password email role
+    createAccountRequestUsername <- x .: "username"
+    createAccountRequestPassword <- x .: "password"
+    createAccountRequestEmail <- x .: "email"
+    createAccountRequestRole <- x .: "role"
+    pure $ CreateAccountRequest{..}
 
 createAccountRequestFields :: CreateAccountRequest -> (Username, ClearTextPassword, Email, Role)
 createAccountRequestFields request =