Skip to content

Commit

Permalink
little clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
battermann committed Sep 20, 2022
1 parent c5ce0ff commit 45a8d52
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions libs/wire-api/src/Wire/API/User/Password.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ instance Schema.ToSchema NewPasswordReset where
schema =
Schema.objectWithDocModifier "NewPasswordReset" objectDesc $
NewPasswordReset
<$> (toTuple . getNewPasswordReset) Schema..= newPasswordResetObjectSchema
<$> (toTuple . unNewPasswordReset) Schema..= newPasswordResetObjectSchema
where
getNewPasswordReset :: NewPasswordReset -> Either Email Phone
getNewPasswordReset (NewPasswordReset v) = v
unNewPasswordReset :: NewPasswordReset -> Either Email Phone
unNewPasswordReset (NewPasswordReset v) = v

objectDesc :: Schema.NamedSwaggerDoc -> Schema.NamedSwaggerDoc
objectDesc = Schema.description ?~ "Data to initiate a password reset"

newPasswordResetObjectSchema :: Schema.ObjectSchemaP Schema.SwaggerDoc (Maybe Email, Maybe Phone) (Either Email Phone)
newPasswordResetObjectSchema = Schema.withParser newPasswordResetTupleObjectSchema maybeNewPasswordResetFromTuple
newPasswordResetObjectSchema = Schema.withParser newPasswordResetTupleObjectSchema fromTuple
where
newPasswordResetTupleObjectSchema :: Schema.ObjectSchema Schema.SwaggerDoc (Maybe Email, Maybe Phone)
newPasswordResetTupleObjectSchema =
Expand All @@ -84,12 +84,12 @@ instance Schema.ToSchema NewPasswordReset where
phoneDocs :: Schema.NamedSwaggerDoc -> Schema.NamedSwaggerDoc
phoneDocs = Schema.description ?~ "Phone"

maybeNewPasswordResetFromTuple :: (Maybe Email, Maybe Phone) -> Parser (Either Email Phone)
maybeNewPasswordResetFromTuple = \case
(Just _, Just _) -> fail "Only one of 'email' or 'phone' allowed."
(Just email, Nothing) -> pure $ Left email
(Nothing, Just phone) -> pure $ Right phone
(Nothing, Nothing) -> fail "One of 'email' or 'phone' required."
fromTuple :: (Maybe Email, Maybe Phone) -> Parser (Either Email Phone)
fromTuple = \case
(Just _, Just _) -> fail "Only one of 'email' or 'phone' allowed."
(Just email, Nothing) -> pure $ Left email
(Nothing, Just phone) -> pure $ Right phone
(Nothing, Nothing) -> fail "One of 'email' or 'phone' required."

toTuple :: Either Email Phone -> (Maybe Email, Maybe Phone)
toTuple = \case
Expand Down

0 comments on commit 45a8d52

Please sign in to comment.