99package infrastructure.api.routes
1010
1111import application.controller.UserController
12+ import entity.user.User
1213import infrastructure.provider.Provider
1314import io.ktor.http.HttpStatusCode
1415import io.ktor.server.application.call
16+ import io.ktor.server.request.receive
17+ import io.ktor.server.request.receiveText
1518import io.ktor.server.response.respond
1619import io.ktor.server.routing.Route
1720import io.ktor.server.routing.post
@@ -22,15 +25,18 @@ import usecase.AuthenticationUseCase
2225 */
2326fun Route.authAPI (provider : Provider , apiPath : String ) {
2427 post(" $apiPath /auth" ) {
25- if (AuthenticationUseCase (
26- call.parameters[" userId" ].toString(),
27- call.parameters[" password" ].toString(),
28- UserController (provider.userDatabaseManager),
29- ).execute()
30- ) {
31- call.respond(HttpStatusCode .OK )
32- } else {
33- call.respond(HttpStatusCode .Unauthorized , " Error: wrong credentials!" )
28+ call.receive<User >().run {
29+ if (AuthenticationUseCase (
30+ this .userId,
31+ this .password,
32+ UserController (provider.userDatabaseManager),
33+ ).execute()
34+ ) {
35+ call.respond(HttpStatusCode .OK )
36+ } else {
37+ call.respond(HttpStatusCode .Unauthorized , " Error: wrong credentials!" )
38+ }
3439 }
40+
3541 }
3642}
0 commit comments