From e8bf2c61c85175fe14d3f6458c42dc3a2d73dffc Mon Sep 17 00:00:00 2001 From: Haebin Date: Sun, 24 Mar 2024 03:17:04 +0900 Subject: [PATCH] feat: throw Exception Handling --- .../auth/application/VacgomSignupService.kt | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/com/vacgom/backend/auth/application/VacgomSignupService.kt b/src/main/kotlin/com/vacgom/backend/auth/application/VacgomSignupService.kt index 211395c..39e6a45 100644 --- a/src/main/kotlin/com/vacgom/backend/auth/application/VacgomSignupService.kt +++ b/src/main/kotlin/com/vacgom/backend/auth/application/VacgomSignupService.kt @@ -8,7 +8,6 @@ import com.vacgom.backend.auth.domain.constants.Role import com.vacgom.backend.global.exception.error.BusinessException import com.vacgom.backend.global.security.jwt.JwtFactory import com.vacgom.backend.inoculation.domain.Inoculation -import com.vacgom.backend.inoculation.exception.VaccineError import com.vacgom.backend.inoculation.infrastructure.persistence.InoculationRepository import com.vacgom.backend.inoculation.infrastructure.persistence.VaccinationRepository import com.vacgom.backend.member.domain.HealthProfile @@ -26,12 +25,12 @@ import java.util.* @Service @Transactional class VacgomSignupService( - private val memberRepository: MemberRepository, - private val healthProfileRepository: HealthProfileRepository, - private val inoculationRepository: InoculationRepository, - private val vaccinationRepository: VaccinationRepository, - private val log: Logger, - private val jwtFactory: JwtFactory + private val memberRepository: MemberRepository, + private val healthProfileRepository: HealthProfileRepository, + private val inoculationRepository: InoculationRepository, + private val vaccinationRepository: VaccinationRepository, + private val log: Logger, + private val jwtFactory: JwtFactory ) { fun validateNickname(id: String) { val nickname = Nickname(id) @@ -40,9 +39,9 @@ class VacgomSignupService( } fun signUpVacgom( - memberId: UUID, - request: SignUpRequest - ): AuthResponse { + memberId: UUID, + request: SignUpRequest + ): AuthResponse? { val (nickname, healthConditions) = request.memberInfo val (name, birthday, sex, vaccines) = request.vaccinationInfo @@ -55,19 +54,33 @@ class VacgomSignupService( member.updateRole(Role.ROLE_USER) val healthProfiles = healthConditions.stream() - .map { condition -> - HealthProfile(member, condition) - }.toList() + .map { condition -> + HealthProfile(member, condition) + }.toList() healthProfileRepository.saveAll(healthProfiles) val memberResponse = MemberResponse(member.id!!, member.role) val tokenResponse = TokenResponse(jwtFactory.createAccessToken(member)) val inoculations = request.vaccinationInfo.vaccineList - .map { vaccine -> - val vaccination = vaccinationRepository.findByVaccineName(vaccine.vaccineType) - ?: throw BusinessException(VaccineError.UNKNOWN_VACCINE_REQUESTED).also { log.warn("추가되지 않은 백신: {$vaccine.vaccineType}") } - Inoculation(vaccine.inoculationOrder, vaccine.inoculationOrderString, vaccine.date, vaccine.agency, vaccine.vaccineName, vaccine.vaccineBrandName, vaccine.lotNumber, member, vaccination) - }.toList() + .map { vaccine -> + val vaccination = vaccinationRepository.findByVaccineName(vaccine.vaccineType) ?: return null + if (vaccination != null) { + Inoculation( + vaccine.inoculationOrder, + vaccine.inoculationOrderString, + vaccine.date, + vaccine.agency, + vaccine.vaccineName, + vaccine.vaccineBrandName, + vaccine.lotNumber, + member, + vaccination + ) + } else { + log.warn("추가해야 하는 백신 : {} {} {}",vaccine.vaccineType, vaccine, vaccine.vaccineName) + null + } + }.filterNotNull().toList() inoculationRepository.saveAll(inoculations) member.addInoculations(inoculations)