update answer login
This commit is contained in:
parent
4ce6cc2a90
commit
43b51d756d
@ -3,7 +3,14 @@ package org.yobble.scala_monolith.api.dto
|
|||||||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
|
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
|
||||||
import io.circe.{Decoder, Encoder}
|
import io.circe.{Decoder, Encoder}
|
||||||
|
|
||||||
case class LoginResponse(accessToken: String, refreshToken: String)
|
case class Tokens(accessToken: String, refreshToken: String)
|
||||||
|
|
||||||
|
object Tokens {
|
||||||
|
implicit val decoder: Decoder[Tokens] = deriveDecoder[Tokens]
|
||||||
|
implicit val encoder: Encoder[Tokens] = deriveEncoder[Tokens]
|
||||||
|
}
|
||||||
|
|
||||||
|
case class LoginResponse(status: String = "fine", message: Tokens)
|
||||||
|
|
||||||
object LoginResponse {
|
object LoginResponse {
|
||||||
implicit val decoder: Decoder[LoginResponse] = deriveDecoder[LoginResponse]
|
implicit val decoder: Decoder[LoginResponse] = deriveDecoder[LoginResponse]
|
||||||
|
|||||||
@ -14,13 +14,7 @@ import org.yobble.scala_monolith.api.util.errorByStatus
|
|||||||
object AllServerEndpoints {
|
object AllServerEndpoints {
|
||||||
def all(transactor: Transactor[IO]): List[ServerEndpoint[Any, IO]] = {
|
def all(transactor: Transactor[IO]): List[ServerEndpoint[Any, IO]] = {
|
||||||
|
|
||||||
val authService = new AuthService(new UserRepositoryImpl(transactor))
|
val infoEndpoints: List[ServerEndpoint[Any, IO]] = List(
|
||||||
|
|
||||||
val authEndpoints = List(
|
|
||||||
AuthEndpoints.loginEndpoint.serverLogic(authService.login)
|
|
||||||
)
|
|
||||||
|
|
||||||
val otherEndpoints: List[ServerEndpoint[Any, IO]] = List(
|
|
||||||
PingEndpoint.pingEndpoint.serverLogicSuccess(_ => IO.pure(BaseResponse(message = "pong"))),
|
PingEndpoint.pingEndpoint.serverLogicSuccess(_ => IO.pure(BaseResponse(message = "pong"))),
|
||||||
ErrorsEndpoint.errorsEndpoint.serverLogicSuccess(_ => IO.pure(BaseResponse(message = "errors"))),
|
ErrorsEndpoint.errorsEndpoint.serverLogicSuccess(_ => IO.pure(BaseResponse(message = "errors"))),
|
||||||
TestErrorEndpoint.testErrorEndpoint.serverLogic(code => {
|
TestErrorEndpoint.testErrorEndpoint.serverLogic(code => {
|
||||||
@ -28,6 +22,12 @@ object AllServerEndpoints {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
authEndpoints ++ otherEndpoints
|
val authService = new AuthService(new UserRepositoryImpl(transactor))
|
||||||
|
|
||||||
|
val authEndpoints = List(
|
||||||
|
AuthEndpoints.loginEndpoint.serverLogic(authService.login)
|
||||||
|
)
|
||||||
|
|
||||||
|
infoEndpoints ++ authEndpoints
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package org.yobble.scala_monolith.service
|
|||||||
|
|
||||||
import at.favre.lib.crypto.bcrypt.BCrypt
|
import at.favre.lib.crypto.bcrypt.BCrypt
|
||||||
import cats.effect.IO
|
import cats.effect.IO
|
||||||
import org.yobble.scala_monolith.api.dto.{LoginRequest, LoginResponse}
|
import org.yobble.scala_monolith.api.dto.{LoginRequest, LoginResponse, Tokens}
|
||||||
import org.yobble.scala_monolith.api.response.ErrorResponse
|
import org.yobble.scala_monolith.api.response.ErrorResponse
|
||||||
import org.yobble.scala_monolith.api.util.ErrorUtils
|
import org.yobble.scala_monolith.api.util.ErrorUtils
|
||||||
import org.yobble.scala_monolith.repository.UserRepository
|
import org.yobble.scala_monolith.repository.UserRepository
|
||||||
@ -21,7 +21,7 @@ class AuthService(userRepository: UserRepository) {
|
|||||||
Left(ErrorUtils.forbidden("User account is deleted"))
|
Left(ErrorUtils.forbidden("User account is deleted"))
|
||||||
} else {
|
} else {
|
||||||
// TODO: Implement real token generation
|
// TODO: Implement real token generation
|
||||||
Right(LoginResponse(accessToken = "fake-access-token", refreshToken = "fake-refresh-token"))
|
Right(LoginResponse(message = Tokens(accessToken = "fake-access-token", refreshToken = "fake-refresh-token")))
|
||||||
}
|
}
|
||||||
case None =>
|
case None =>
|
||||||
Left(ErrorUtils.unauthorized("Invalid login or password"))
|
Left(ErrorUtils.unauthorized("Invalid login or password"))
|
||||||
|
|||||||
Reference in New Issue
Block a user