diff --git a/src/main/kotlin/com/vacgom/backend/disease/domain/constants/AgeCondition.kt b/src/main/kotlin/com/vacgom/backend/disease/domain/constants/AgeCondition.kt index eb9d093..b7faebe 100644 --- a/src/main/kotlin/com/vacgom/backend/disease/domain/constants/AgeCondition.kt +++ b/src/main/kotlin/com/vacgom/backend/disease/domain/constants/AgeCondition.kt @@ -12,13 +12,17 @@ enum class AgeCondition( AGE60TO64("만 60-64세", 0b000010), AGEOVER65("만 65세 이상", 0b000001); - fun isMatching(value: Int): Boolean { - return value and this.value == this.value - } - companion object { - fun getConditions(value: Int): List { - return entries.filter { it.isMatching(value) } + fun getAgeCondition(value: Int): AgeCondition { + return when { + value in 19..29 -> AGE19TO29 + value in 30..39 -> AGE30TO39 + value in 40..49 -> AGE40TO49 + value in 50..59 -> AGE50TO59 + value in 60..64 -> AGE60TO64 + value >= 65 -> AGEOVER65 + else -> AGE19TO29 + } } } } diff --git a/src/main/kotlin/com/vacgom/backend/search/application/SearchService.kt b/src/main/kotlin/com/vacgom/backend/search/application/SearchService.kt index ae69c09..56a3d39 100644 --- a/src/main/kotlin/com/vacgom/backend/search/application/SearchService.kt +++ b/src/main/kotlin/com/vacgom/backend/search/application/SearchService.kt @@ -14,6 +14,7 @@ import com.vacgom.backend.member.infrastructure.persistence.MemberRepository import com.vacgom.backend.search.application.dto.DiseaseSearchResponse import com.vacgom.backend.search.application.dto.VaccinationSearchResponse import org.springframework.stereotype.Service +import java.time.LocalDate import java.util.* @@ -51,15 +52,16 @@ class SearchService( } fun searchRecommendVaccination(memberId: UUID): List { - val ageCondition = AgeCondition.AGE19TO29 + val member = memberRepository.findById(memberId).orElseThrow { + BusinessException(MemberError.NOT_FOUND) + } + val ageCondition = AgeCondition.getAgeCondition(member.memberDetails?.birthday?.year!!.minus(LocalDate.now().year)) val vaccinations = findAllVaccinations() val inoculatedDiseaseName = inoculationRepository.findDistinctDiseaseNameByMemberId(memberId).flatMap { it.split("·") }.toSet() val recommendedVaccinations = vaccinations.filter { vaccination -> !inoculatedDiseaseName.contains(vaccination.vaccineName) } - val healthProfiles = memberRepository.findById(memberId).orElseThrow { - BusinessException(MemberError.NOT_FOUND) - }.healthProfiles.map { it.healthCondition }.toList() + val healthProfiles = member.healthProfiles.map { it.healthCondition }.toList() val diseases = this.searchDisease(listOf(ageCondition), healthProfiles).filter { response -> !inoculatedDiseaseName.contains(response.name)