Skip to content

Commit

Permalink
feat: throw Exception Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
h-beeen committed Mar 23, 2024
1 parent f9e7437 commit e8bf2c6
Showing 1 changed file with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit e8bf2c6

Please sign in to comment.