From 65f21f876e49c154f5b8d1bbac709ca37921c78a Mon Sep 17 00:00:00 2001 From: Haebin Date: Sat, 23 Mar 2024 17:24:13 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=A0=91=EC=A2=85=20=EC=9D=B8=EC=A6=9D?= =?UTF-8?q?=EC=84=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=B0=8F=20AuthResponse=20=EC=8A=A4=ED=8E=99=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/auth/application/AuthService.kt | 2 +- .../auth/application/VacgomSignupService.kt | 2 +- .../application/dto/response/AuthResponse.kt | 1 + .../application/InoculationService.kt | 19 ++++++++++++------- .../InoculationCertificateResponse.kt | 10 ++++++++++ .../backend/inoculation/domain/Vaccination.kt | 1 + .../persistence/InoculationRepository.kt | 10 ++++------ .../presentation/InoculationController.kt | 7 +++++++ 8 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 src/main/kotlin/com/vacgom/backend/inoculation/application/dto/response/InoculationCertificateResponse.kt diff --git a/src/main/kotlin/com/vacgom/backend/auth/application/AuthService.kt b/src/main/kotlin/com/vacgom/backend/auth/application/AuthService.kt index 32c6dd7..c3c042a 100644 --- a/src/main/kotlin/com/vacgom/backend/auth/application/AuthService.kt +++ b/src/main/kotlin/com/vacgom/backend/auth/application/AuthService.kt @@ -42,7 +42,7 @@ class AuthService( val memberResponse = MemberResponse(member.id!!, member.role) val tokenResponse = TokenResponse(jwtFactory.createAccessToken(member)) - return AuthResponse(memberResponse, tokenResponse) + return AuthResponse(true, memberResponse, tokenResponse) } private fun findOrCreateMember( diff --git a/src/main/kotlin/com/vacgom/backend/auth/application/VacgomSignupService.kt b/src/main/kotlin/com/vacgom/backend/auth/application/VacgomSignupService.kt index bc76123..211395c 100644 --- a/src/main/kotlin/com/vacgom/backend/auth/application/VacgomSignupService.kt +++ b/src/main/kotlin/com/vacgom/backend/auth/application/VacgomSignupService.kt @@ -71,6 +71,6 @@ class VacgomSignupService( inoculationRepository.saveAll(inoculations) member.addInoculations(inoculations) - return AuthResponse(memberResponse, tokenResponse) + return AuthResponse(true, memberResponse, tokenResponse) } } diff --git a/src/main/kotlin/com/vacgom/backend/auth/application/dto/response/AuthResponse.kt b/src/main/kotlin/com/vacgom/backend/auth/application/dto/response/AuthResponse.kt index 92cb739..1d24db7 100644 --- a/src/main/kotlin/com/vacgom/backend/auth/application/dto/response/AuthResponse.kt +++ b/src/main/kotlin/com/vacgom/backend/auth/application/dto/response/AuthResponse.kt @@ -1,6 +1,7 @@ package com.vacgom.backend.auth.application.dto.response data class AuthResponse( + val success: Boolean, val member: MemberResponse, val token: TokenResponse ) 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 f2fbe93..dcabb5d 100644 --- a/src/main/kotlin/com/vacgom/backend/inoculation/application/InoculationService.kt +++ b/src/main/kotlin/com/vacgom/backend/inoculation/application/InoculationService.kt @@ -3,6 +3,7 @@ package com.vacgom.backend.inoculation.application import com.vacgom.backend.global.exception.error.BusinessException import com.vacgom.backend.global.exception.error.GlobalError import com.vacgom.backend.inoculation.application.dto.request.DiseaseNameRequest +import com.vacgom.backend.inoculation.application.dto.response.InoculationCertificateResponse import com.vacgom.backend.inoculation.application.dto.response.InoculationDetailResponse import com.vacgom.backend.inoculation.application.dto.response.InoculationSimpleResponse import com.vacgom.backend.inoculation.domain.constants.VaccinationType @@ -78,12 +79,16 @@ class InoculationService( }.toList() } - fun getCertificates(memberId: UUID) { - val findDistinctLatestInoculationsByMemberId = - inoculationRepository.findDistinctLatestInoculationsByMemberId(memberId) - - findDistinctLatestInoculationsByMemberId.forEach { lis -> - log.warn("{}, lis") - } + fun getCertificates(memberId: UUID): List { + val inoculations = inoculationRepository.findDistinctLatestInoculationsByMemberId(memberId) + val sortedByDescending = inoculations.sortedByDescending { it.date } + return sortedByDescending.map { + InoculationCertificateResponse( + it.vaccination.diseaseName, + it.vaccination.vaccineName, + it.date, + it.vaccination.certificationIcon + ) + }.toList() } } diff --git a/src/main/kotlin/com/vacgom/backend/inoculation/application/dto/response/InoculationCertificateResponse.kt b/src/main/kotlin/com/vacgom/backend/inoculation/application/dto/response/InoculationCertificateResponse.kt new file mode 100644 index 0000000..e6a0f04 --- /dev/null +++ b/src/main/kotlin/com/vacgom/backend/inoculation/application/dto/response/InoculationCertificateResponse.kt @@ -0,0 +1,10 @@ +package com.vacgom.backend.inoculation.application.dto.response + +import java.time.LocalDate + +data class InoculationCertificateResponse( + val diseaseName: String, + val vaccineName: String, + val inoculatedDate: LocalDate, + val iconImage: String +) diff --git a/src/main/kotlin/com/vacgom/backend/inoculation/domain/Vaccination.kt b/src/main/kotlin/com/vacgom/backend/inoculation/domain/Vaccination.kt index f775292..7f17470 100644 --- a/src/main/kotlin/com/vacgom/backend/inoculation/domain/Vaccination.kt +++ b/src/main/kotlin/com/vacgom/backend/inoculation/domain/Vaccination.kt @@ -14,6 +14,7 @@ class Vaccination( val minOrder: Long, val maxOrder: Long, val icon: String, + val certificationIcon: String, @Enumerated(EnumType.STRING) val vaccinationType: VaccinationType, ) : BaseEntity() { @Id diff --git a/src/main/kotlin/com/vacgom/backend/inoculation/infrastructure/persistence/InoculationRepository.kt b/src/main/kotlin/com/vacgom/backend/inoculation/infrastructure/persistence/InoculationRepository.kt index 95a9f8f..1279537 100644 --- a/src/main/kotlin/com/vacgom/backend/inoculation/infrastructure/persistence/InoculationRepository.kt +++ b/src/main/kotlin/com/vacgom/backend/inoculation/infrastructure/persistence/InoculationRepository.kt @@ -40,11 +40,9 @@ interface InoculationRepository : JpaRepository { ): List? - @Query( - "select i " + - "from Inoculation i " + - "where (i.vaccination.diseaseName, i.inoculationOrder) in " + - "(select iv.vaccination.diseaseName, max(iv.inoculationOrder) from Inoculation iv where iv.member.id = :memberId group by iv.vaccination.diseaseName)" - ) + @Query("SELECT i " + + "FROM Inoculation i JOIN i.vaccination v " + + "GROUP BY i.vaccination.id " + + "ORDER BY i.inoculationOrder DESC") fun findDistinctLatestInoculationsByMemberId(memberId: UUID): List } 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 1508eea..f6b11b1 100644 --- a/src/main/kotlin/com/vacgom/backend/inoculation/presentation/InoculationController.kt +++ b/src/main/kotlin/com/vacgom/backend/inoculation/presentation/InoculationController.kt @@ -3,6 +3,7 @@ package com.vacgom.backend.inoculation.presentation import com.vacgom.backend.global.security.annotation.AuthId import com.vacgom.backend.inoculation.application.InoculationService import com.vacgom.backend.inoculation.application.dto.request.DiseaseNameRequest +import com.vacgom.backend.inoculation.application.dto.response.InoculationCertificateResponse import com.vacgom.backend.inoculation.application.dto.response.InoculationDetailResponse import com.vacgom.backend.inoculation.application.dto.response.InoculationSimpleResponse import org.springframework.http.ResponseEntity @@ -32,4 +33,10 @@ class InoculationController( val responses = inoculationService.getInoculationDetailResponse(id, request, type) return ResponseEntity.ok(responses) } + + @GetMapping("/certificate") + fun getInoculationCertificateResponse(@AuthId id: UUID): ResponseEntity> { + val certificates = inoculationService.getCertificates(id) + return ResponseEntity.ok(certificates) + } }