Skip to content

Commit

Permalink
feat: 전체 백신 조회 api 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
HyungJu committed May 14, 2024
1 parent 29d24a8 commit a1706cb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<VaccineResponse> {
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,
)
}
}
Original file line number Diff line number Diff line change
@@ -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<Long>,
val id: String?,
val name: String,
val diseases: List<Long>,
val diseaseName: String,
val type: VaccinationType,
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ class VaccineController(
): ResponseEntity<VaccineResponse> {
return ResponseEntity.ok(vaccineService.getVaccine(id))
}

@GetMapping()
fun getAllVaccines(): ResponseEntity<List<VaccineResponse>> {
return ResponseEntity.ok(vaccineService.getAllVaccines())
}
}

0 comments on commit a1706cb

Please sign in to comment.