diff --git a/src/main/kotlin/gomushin/backend/couple/dto/response/AnniversaryDetailResponse.kt b/src/main/kotlin/gomushin/backend/couple/dto/response/AnniversaryDetailResponse.kt new file mode 100644 index 00000000..817d64e8 --- /dev/null +++ b/src/main/kotlin/gomushin/backend/couple/dto/response/AnniversaryDetailResponse.kt @@ -0,0 +1,20 @@ +package gomushin.backend.couple.dto.response + +import gomushin.backend.couple.domain.entity.Anniversary +import java.time.LocalDate + +data class AnniversaryDetailResponse( + val id: Long, + val title: String, + val anniversaryDate: LocalDate, +) { + companion object { + fun of(anniversary: Anniversary): AnniversaryDetailResponse { + return AnniversaryDetailResponse( + id = anniversary.id, + title = anniversary.title, + anniversaryDate = anniversary.anniversaryDate, + ) + } + } +} diff --git a/src/main/kotlin/gomushin/backend/couple/facade/AnniversaryFacade.kt b/src/main/kotlin/gomushin/backend/couple/facade/AnniversaryFacade.kt index d9c8a489..9d80cf2e 100644 --- a/src/main/kotlin/gomushin/backend/couple/facade/AnniversaryFacade.kt +++ b/src/main/kotlin/gomushin/backend/couple/facade/AnniversaryFacade.kt @@ -2,7 +2,9 @@ package gomushin.backend.couple.facade import gomushin.backend.core.CustomUserDetails import gomushin.backend.core.common.web.PageResponse +import gomushin.backend.core.infrastructure.exception.BadRequestException import gomushin.backend.couple.domain.service.AnniversaryService +import gomushin.backend.couple.dto.response.AnniversaryDetailResponse import gomushin.backend.couple.dto.response.MainAnniversaryResponse import gomushin.backend.couple.dto.response.TotalAnniversaryResponse import org.springframework.data.domain.PageRequest @@ -32,7 +34,17 @@ class AnniversaryFacade( return PageResponse.from(anniversaryResponses) } + fun get(customUserDetails: CustomUserDetails, anniversaryId: Long): AnniversaryDetailResponse { + val anniversary = anniversaryService.getById(anniversaryId) + if (anniversary.coupleId != customUserDetails.getCouple().id) { + throw BadRequestException("sarangggun.anniversary.unauthorized") + } + return AnniversaryDetailResponse.of(anniversary) + } + fun delete(customUserDetails: CustomUserDetails, anniversaryId: Long) { anniversaryService.delete(customUserDetails.getCouple(), anniversaryId) } + + } diff --git a/src/main/kotlin/gomushin/backend/couple/presentation/AnniversaryController.kt b/src/main/kotlin/gomushin/backend/couple/presentation/AnniversaryController.kt index 0fb1afc1..86c703d5 100644 --- a/src/main/kotlin/gomushin/backend/couple/presentation/AnniversaryController.kt +++ b/src/main/kotlin/gomushin/backend/couple/presentation/AnniversaryController.kt @@ -4,6 +4,7 @@ import gomushin.backend.core.CustomUserDetails import gomushin.backend.core.common.web.PageResponse import gomushin.backend.core.common.web.response.ApiResponse import gomushin.backend.couple.dto.request.GenerateAnniversaryRequest +import gomushin.backend.couple.dto.response.AnniversaryDetailResponse import gomushin.backend.couple.dto.response.MainAnniversaryResponse import gomushin.backend.couple.dto.response.TotalAnniversaryResponse import gomushin.backend.couple.facade.AnniversaryFacade @@ -15,7 +16,7 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal import org.springframework.web.bind.annotation.* @RestController -@Tag(name = "기념일 생성", description = "AnniversaryController") +@Tag(name = "기념일", description = "AnniversaryController") class AnniversaryController( private val coupleFacade: CoupleFacade, private val anniversaryFacade: AnniversaryFacade @@ -74,4 +75,20 @@ class AnniversaryController( val anniversaries = anniversaryFacade.getAnniversaryList(customUserDetails, safePage, size) return anniversaries } + + @ResponseStatus(HttpStatus.OK) + @GetMapping(ApiPath.ANNIVERSARY) + @Operation( + summary = "기념일 상세 조회", + description = "getAnniversary" + ) + fun getAnniversary( + @AuthenticationPrincipal customUserDetails: CustomUserDetails, + @PathVariable anniversaryId: Long + ): ApiResponse { + val anniversary = anniversaryFacade.get(customUserDetails, anniversaryId) + return ApiResponse.success(anniversary) + } + + }