-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tapir based secuirty #794
Tapir based secuirty #794
Changes from 4 commits
b1aa580
52f9c9e
4659470
cfe008e
8903507
6137447
b75ba4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
version=3.3.3 | ||
maxColumn = 140 | ||
runner.dialect = scala213 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,36 +44,36 @@ class UserApi(http: Http, auth: Auth[ApiKey], userService: UserService, xa: Tran | |
} | ||
|
||
private val changePasswordEndpoint = secureEndpoint.post | ||
.in(UserPath / "changepassword") | ||
.securityIn(UserPath / "changepassword") | ||
.in(jsonBody[ChangePassword_IN]) | ||
.out(jsonBody[ChangePassword_OUT]) | ||
.serverLogic { case (authData, data) => | ||
.serverSecurityLogic(authData => auth.applyEither(authData).map(_.left.map(exceptionToErrorOut))) | ||
.serverLogic(id => data => | ||
(for { | ||
userId <- auth(authData) | ||
_ <- userService.changePassword(userId, data.currentPassword, data.newPassword).transact(xa) | ||
_ <- userService.changePassword(id, data.currentPassword, data.newPassword).transact(xa) | ||
} yield ChangePassword_OUT()).toOut | ||
} | ||
) | ||
|
||
private val getUserEndpoint = secureEndpoint.get | ||
.in(UserPath) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now I am not sure if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah you're right it's fine to keep them all in the regular inputs. The path matching is done on both anyway |
||
.out(jsonBody[GetUser_OUT]) | ||
.serverLogic { authData => | ||
.serverSecurityLogic(authData => auth.applyEither(authData).map(_.left.map(exceptionToErrorOut))) | ||
.serverLogic(id => (_: Unit) => | ||
(for { | ||
userId <- auth(authData) | ||
user <- userService.findById(userId).transact(xa) | ||
user <- userService.findById(id).transact(xa) | ||
} yield GetUser_OUT(user.login, user.emailLowerCased, user.createdOn)).toOut | ||
} | ||
) | ||
|
||
private val updateUserEndpoint = secureEndpoint.post | ||
.in(UserPath) | ||
.in(jsonBody[UpdateUser_IN]) | ||
.out(jsonBody[UpdateUser_OUT]) | ||
.serverLogic { case (authData, data) => | ||
.serverSecurityLogic(authData => auth.applyEither(authData).map(_.left.map(exceptionToErrorOut))) | ||
.serverLogic(id => data => | ||
(for { | ||
userId <- auth(authData) | ||
_ <- userService.changeUser(userId, data.login, data.email).transact(xa) | ||
_ <- userService.changeUser(id, data.login, data.email).transact(xa) | ||
} yield UpdateUser_OUT()).toOut | ||
} | ||
) | ||
|
||
val endpoints: ServerEndpoints = | ||
NonEmptyList | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we use
.toOut
here as for server logic?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not if I understand it correctly here we just mapping left while
.toOut
perform mapping on both left and right, in fact.toOut
maps whole IO[] we just need to map the left of EitherThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't understand correctly fixed