Adds login ability, error handling, and logging (#1)
Reviewed-on: #1 Co-authored-by: aarbit <aarbit@gmail.com> Co-committed-by: aarbit <aarbit@gmail.com>
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package net.halfbinary.scavengerhuntapi.service
|
||||
|
||||
import net.halfbinary.scavengerhuntapi.error.exception.LoginFailedException
|
||||
import net.halfbinary.scavengerhuntapi.model.converter.toDomain
|
||||
import net.halfbinary.scavengerhuntapi.model.domain.Hunter
|
||||
import net.halfbinary.scavengerhuntapi.model.domain.Login
|
||||
import net.halfbinary.scavengerhuntapi.repository.HunterRepository
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
class LoginService(private val hunterRepository: HunterRepository) {
|
||||
companion object {
|
||||
private val log = LoggerFactory.getLogger(LoginService::class.java)
|
||||
}
|
||||
fun login(login: Login): Hunter {
|
||||
log.info("Logging in with email: ${login.email}")
|
||||
return hunterRepository.login(login.email, login.password)?.toDomain()?:throw LoginFailedException()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user