Skip to content

Commit

Permalink
feat: 인증서 조회 정렬 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
HyungJu committed May 15, 2024
1 parent fc2900e commit 6305405
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ class InoculationService(
}.toList()
}

fun getCertificates(memberId: UUID): List<InoculationCertificateResponse> {
fun getCertificates(
memberId: UUID,
orderBy: String,
): List<InoculationCertificateResponse> {
val inoculations1 = inoculationRepository.findInoculationsByMemberId(memberId)

val group =
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class InoculationController(
@GetMapping("/certificate")
fun getInoculationCertificateResponse(
@AuthId id: UUID,
@RequestParam("orderBy") orderBy: String = "dateDesc",
): ResponseEntity<List<InoculationCertificateResponse>> {
val certificates = inoculationService.getCertificates(id)
val certificates = inoculationService.getCertificates(id, orderBy)
return ResponseEntity.ok(certificates)
}

Expand All @@ -48,7 +49,7 @@ class InoculationController(
@AuthId id: UUID,
@PathVariable("vaccineId") vaccineId: String,
): ResponseEntity<InoculationCertificateResponse> {
val certificates = inoculationService.getCertificates(id)
val certificates = inoculationService.getCertificates(id, "dateDesc")
return ResponseEntity.ok(certificates.filter { it.vaccineId == vaccineId }.first())
}

Expand Down

0 comments on commit 6305405

Please sign in to comment.