diff --git a/src/main/kotlin/com/vacgom/backend/inoculation/application/InoculationService.kt b/src/main/kotlin/com/vacgom/backend/inoculation/application/InoculationService.kt index f65bf9d..cad20d6 100644 --- a/src/main/kotlin/com/vacgom/backend/inoculation/application/InoculationService.kt +++ b/src/main/kotlin/com/vacgom/backend/inoculation/application/InoculationService.kt @@ -113,7 +113,10 @@ class InoculationService( }.toList() } - fun getCertificates(memberId: UUID): List { + fun getCertificates( + memberId: UUID, + orderBy: String, + ): List { val inoculations1 = inoculationRepository.findInoculationsByMemberId(memberId) val group = @@ -123,17 +126,24 @@ class InoculationService( it.value.last() } - return group.map { - InoculationCertificateResponse( - memberId.toString(), - it.vaccination.id.toString(), - it.vaccination.diseaseName, - it.vaccination.vaccineName, - it.date, - it.vaccination.certificationIcon, - it.vaccination.vaccinationType, - ) - }.toList() + val result = + group.map { + InoculationCertificateResponse( + memberId.toString(), + it.vaccination.id.toString(), + it.vaccination.diseaseName, + it.vaccination.vaccineName, + it.date, + it.vaccination.certificationIcon, + it.vaccination.vaccinationType, + ) + }.toList() + + return when (orderBy) { + "dateDesc" -> result.sortedByDescending { it.inoculatedDate } + "dateAsc" -> result.sortedBy { it.inoculatedDate } + else -> result + } } fun getCertificateImage( diff --git a/src/main/kotlin/com/vacgom/backend/inoculation/presentation/InoculationController.kt b/src/main/kotlin/com/vacgom/backend/inoculation/presentation/InoculationController.kt index 1de1dbf..cdd30b7 100644 --- a/src/main/kotlin/com/vacgom/backend/inoculation/presentation/InoculationController.kt +++ b/src/main/kotlin/com/vacgom/backend/inoculation/presentation/InoculationController.kt @@ -38,8 +38,9 @@ class InoculationController( @GetMapping("/certificate") fun getInoculationCertificateResponse( @AuthId id: UUID, + @RequestParam("orderBy") orderBy: String = "dateDesc", ): ResponseEntity> { - val certificates = inoculationService.getCertificates(id) + val certificates = inoculationService.getCertificates(id, orderBy) return ResponseEntity.ok(certificates) } @@ -48,7 +49,7 @@ class InoculationController( @AuthId id: UUID, @PathVariable("vaccineId") vaccineId: String, ): ResponseEntity { - val certificates = inoculationService.getCertificates(id) + val certificates = inoculationService.getCertificates(id, "dateDesc") return ResponseEntity.ok(certificates.filter { it.vaccineId == vaccineId }.first()) }