diff --git a/src/main/kotlin/com/vacgom/backend/inoculation/application/VaccineService.kt b/src/main/kotlin/com/vacgom/backend/inoculation/application/VaccineService.kt index 3dea030..7de9c16 100644 --- a/src/main/kotlin/com/vacgom/backend/inoculation/application/VaccineService.kt +++ b/src/main/kotlin/com/vacgom/backend/inoculation/application/VaccineService.kt @@ -10,23 +10,43 @@ import java.util.* @Service class VaccineService( - val vaccineRepository: VaccinationRepository, - val diseaseService: DiseaseService, + val vaccineRepository: VaccinationRepository, + val diseaseService: DiseaseService, ) { + fun getAllVaccines(): List { + val vaccines = this.vaccineRepository.findAll() + val diseases = this.diseaseService.findAll() + + return vaccines.map { vaccine -> + VaccineResponse( + id = vaccine.id?.toString(), + name = vaccine.vaccineName, + diseases = + diseases.filter { vaccine.diseaseName.contains(it.name) } + .mapNotNull { it.id } + .toList(), + diseaseName = vaccine.diseaseName, + type = vaccine.vaccinationType, + ) + } + } + fun getVaccine(id: String): VaccineResponse { val vaccine = - vaccineRepository.findById(UUID.fromString(id)) - .orElseThrow { throw BusinessException(VaccineError.UNKNOWN_VACCINE_REQUESTED) } + vaccineRepository.findById(UUID.fromString(id)) + .orElseThrow { throw BusinessException(VaccineError.UNKNOWN_VACCINE_REQUESTED) } val diseases = diseaseService.findAll() return VaccineResponse( - id = vaccine.id?.toString(), - name = vaccine.vaccineName, - diseases = + id = vaccine.id?.toString(), + name = vaccine.vaccineName, + diseases = diseases.filter { vaccine.diseaseName.contains(it.name) } - .mapNotNull { it.id } - .toList(), + .mapNotNull { it.id } + .toList(), + diseaseName = vaccine.diseaseName, + type = vaccine.vaccinationType, ) } } diff --git a/src/main/kotlin/com/vacgom/backend/inoculation/application/dto/response/VaccineResponse.kt b/src/main/kotlin/com/vacgom/backend/inoculation/application/dto/response/VaccineResponse.kt index 943fe6f..ead891c 100644 --- a/src/main/kotlin/com/vacgom/backend/inoculation/application/dto/response/VaccineResponse.kt +++ b/src/main/kotlin/com/vacgom/backend/inoculation/application/dto/response/VaccineResponse.kt @@ -1,7 +1,11 @@ package com.vacgom.backend.inoculation.application.dto.response +import com.vacgom.backend.inoculation.domain.constants.VaccinationType + class VaccineResponse( - val id: String?, - val name: String, - val diseases: List, + val id: String?, + val name: String, + val diseases: List, + val diseaseName: String, + val type: VaccinationType, ) diff --git a/src/main/kotlin/com/vacgom/backend/vaccine/presentation/VaccineController.kt b/src/main/kotlin/com/vacgom/backend/vaccine/presentation/VaccineController.kt index 20f2511..a9feb9b 100644 --- a/src/main/kotlin/com/vacgom/backend/vaccine/presentation/VaccineController.kt +++ b/src/main/kotlin/com/vacgom/backend/vaccine/presentation/VaccineController.kt @@ -19,4 +19,9 @@ class VaccineController( ): ResponseEntity { return ResponseEntity.ok(vaccineService.getVaccine(id)) } + + @GetMapping() + fun getAllVaccines(): ResponseEntity> { + return ResponseEntity.ok(vaccineService.getAllVaccines()) + } }