From a1706cb0ebcb4e3aedb8eb9dd2d67e2e3121b58a Mon Sep 17 00:00:00 2001 From: HyungJu Date: Tue, 14 May 2024 20:58:02 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=A0=84=EC=B2=B4=20=EB=B0=B1=EC=8B=A0?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inoculation/application/VaccineService.kt | 38 ++++++++++++++----- .../dto/response/VaccineResponse.kt | 10 +++-- .../vaccine/presentation/VaccineController.kt | 5 +++ 3 files changed, 41 insertions(+), 12 deletions(-) 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()) + } }