From 6305405962b7ce13f6846662dd288b275af4351f Mon Sep 17 00:00:00 2001 From: HyungJu Date: Wed, 15 May 2024 20:23:09 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9D=B8=EC=A6=9D=EC=84=9C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=A0=95=EB=A0=AC=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/InoculationService.kt | 34 ++++++++++++------- .../presentation/InoculationController.kt | 5 +-- 2 files changed, 25 insertions(+), 14 deletions(-) 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()) }