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:
@@ -6,17 +6,26 @@ import net.halfbinary.scavengerhuntapi.model.converter.toRecord
|
||||
import net.halfbinary.scavengerhuntapi.model.domain.Hunter
|
||||
import net.halfbinary.scavengerhuntapi.repository.HunterRepository
|
||||
import org.apache.commons.validator.routines.EmailValidator
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
class SignupService(private val hunterRepository: HunterRepository) {
|
||||
|
||||
companion object {
|
||||
private val log = LoggerFactory.getLogger(SignupService::class.java)
|
||||
}
|
||||
fun createNewHunter(hunter: Hunter) {
|
||||
log.info("Creating new Hunter with email: ${hunter.email}...")
|
||||
if (!EmailValidator.getInstance().isValid(hunter.email)) {
|
||||
log.error("Invalid email ${hunter.email}")
|
||||
throw InvalidEmailException(hunter.email)
|
||||
}
|
||||
if (hunterRepository.findByEmail(hunter.email) != null) {
|
||||
log.error("Hunter ${hunter.email} already exists")
|
||||
throw PreexistingAccountException()
|
||||
}
|
||||
hunterRepository.save(hunter.toRecord())
|
||||
log.info("...Created new Hunter with email: ${hunter.email}")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user