From d0eb52776a9d939b5854ef13f0ccdb6ec7f589f9 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 22:54:54 +0900 Subject: [PATCH 1/4] feat: added Vote status check (finished) API --- .../application/domain/vote/VoteService.kt | 4 ++++ .../application/port/input/vote/VoteUseCase.kt | 2 ++ .../com/piikii/input/http/controller/VoteApi.kt | 11 +++++++++++ .../com/piikii/input/http/docs/VoteApiDocs.kt | 16 ++++++++++++++-- .../input/http/dto/response/VoteResponse.kt | 3 +++ 5 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/response/VoteResponse.kt diff --git a/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt index 8bb91aee..579462b2 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt @@ -27,6 +27,10 @@ class VoteService( voteCommandPort.vote(votes) } + override fun isVoteFinished(roomId: UUID): Boolean { + return !roomQueryPort.retrieve(roomId).isUnavailableToVote() + } + companion object { const val VOTE_ACCESS_DENIED = "투표가 시작되지 않았거나, 마감되었습니다." } diff --git a/piikii-application/src/main/kotlin/com/piikii/application/port/input/vote/VoteUseCase.kt b/piikii-application/src/main/kotlin/com/piikii/application/port/input/vote/VoteUseCase.kt index be26b6ca..b1b47e3b 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/port/input/vote/VoteUseCase.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/port/input/vote/VoteUseCase.kt @@ -8,4 +8,6 @@ interface VoteUseCase { roomId: UUID, votes: List, ) + + fun isVoteFinished(roomId: UUID): Boolean } diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt index 7882a2af..96cf518c 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt @@ -6,7 +6,9 @@ import com.piikii.application.port.input.vote.VoteUseCase import com.piikii.input.http.docs.VoteApiDocs import com.piikii.input.http.dto.ResponseForm import com.piikii.input.http.dto.request.VoteRequest +import com.piikii.input.http.dto.response.VoteStatusResponse import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PatchMapping import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping @@ -32,6 +34,15 @@ class VoteApi( return ResponseForm.EMPTY_RESPONSE } + @ResponseStatus(HttpStatus.OK) + @GetMapping + override fun getVoteStatus( + @PathVariable roomId: UUID, + ): ResponseForm { + val voteFinished = voteUseCase.isVoteFinished(roomId) + return ResponseForm(data = VoteStatusResponse(voteFinished)) + } + @ResponseStatus(HttpStatus.CREATED) @PostMapping override fun vote( diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt index 1d534d59..0dececc5 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt @@ -3,6 +3,7 @@ package com.piikii.input.http.docs import com.piikii.application.port.input.room.dto.request.VoteDeadlineSetRequest import com.piikii.input.http.dto.ResponseForm import com.piikii.input.http.dto.request.VoteRequest +import com.piikii.input.http.dto.response.VoteStatusResponse import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.Parameter import io.swagger.v3.oas.annotations.enums.ParameterIn @@ -32,12 +33,23 @@ interface VoteApiDocs { ) request: VoteDeadlineSetRequest, ): ResponseForm - @Operation(summary = "투표 API", description = "투표를 진행합니다") + @Operation(summary = "방 투표 마감 상태조회 API", description = "투표 마감 상태를 조회합니다") + @ApiResponses(value = [ApiResponse(responseCode = "200", description = "Vote status check succeed")]) + fun getVoteStatus( + @Parameter( + name = "roomId", + description = "조회하고자 하는 방 id", + required = true, + `in` = ParameterIn.PATH, + ) roomId: UUID, + ): ResponseForm + + @Operation(summary = "투표하기 API", description = "투표를 진행합니다") @ApiResponses(value = [ApiResponse(responseCode = "201", description = "Vote succeed")]) fun vote( @Parameter( name = "roomId", - description = "투표하고자 하는 id", + description = "투표하고자 하는 방 id", required = true, `in` = ParameterIn.PATH, ) roomId: UUID, diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/response/VoteResponse.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/response/VoteResponse.kt new file mode 100644 index 00000000..231a6ab3 --- /dev/null +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/response/VoteResponse.kt @@ -0,0 +1,3 @@ +package com.piikii.input.http.dto.response + +data class VoteStatusResponse(val voteFinished: Boolean) From bfbc0b01ed7ef92863a91146fdfa91f8eacdf3e6 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 23:13:22 +0900 Subject: [PATCH 2/4] feat: split vote unavailable - finish --- .../com/piikii/application/domain/room/Room.kt | 2 +- .../application/domain/vote/VoteService.kt | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/piikii-application/src/main/kotlin/com/piikii/application/domain/room/Room.kt b/piikii-application/src/main/kotlin/com/piikii/application/domain/room/Room.kt index 5d673f0f..9b5cfd9f 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/domain/room/Room.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/domain/room/Room.kt @@ -14,7 +14,7 @@ data class Room( val voteDeadline: LocalDateTime?, val roomId: UUID, ) { - fun isUnavailableToVote(): Boolean { + fun isVoteUnavailable(): Boolean { return this.voteDeadline == null || this.voteDeadline.isBefore(LocalDateTime.now()) } } diff --git a/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt index 579462b2..e9027098 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt @@ -6,6 +6,7 @@ import com.piikii.application.port.output.persistence.VoteCommandPort import com.piikii.common.exception.ExceptionCode import com.piikii.common.exception.PiikiiException import org.springframework.stereotype.Service +import java.time.LocalDateTime import java.util.UUID @Service @@ -17,10 +18,10 @@ class VoteService( roomId: UUID, votes: List, ) { - if (roomQueryPort.retrieve(roomId).isUnavailableToVote()) { + if (roomQueryPort.retrieve(roomId).isVoteUnavailable()) { throw PiikiiException( exceptionCode = ExceptionCode.ACCESS_DENIED, - detailMessage = VOTE_ACCESS_DENIED, + detailMessage = VOTE_UNAVAILABLE, ) } // TODO: votes.map { it.roomPlaceId } 존재여부 검증 필요 -> 도현이 작업 완료되면 붙일 예정 @@ -28,10 +29,17 @@ class VoteService( } override fun isVoteFinished(roomId: UUID): Boolean { - return !roomQueryPort.retrieve(roomId).isUnavailableToVote() + val voteDeadline = + roomQueryPort.retrieve(roomId).voteDeadline + ?: throw PiikiiException( + exceptionCode = ExceptionCode.ACCESS_DENIED, + detailMessage = VOTE_NOT_STARTED, + ) + return voteDeadline.isBefore(LocalDateTime.now()) } companion object { - const val VOTE_ACCESS_DENIED = "투표가 시작되지 않았거나, 마감되었습니다." + const val VOTE_UNAVAILABLE = "투표가 시작되지 않았거나, 마감되었습니다" + const val VOTE_NOT_STARTED = "투표가 시작되지 않았습니다" } } From a6f5f52177488d2c7818a1dc7d22a88fccb745cd Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 30 Jun 2024 00:05:36 +0900 Subject: [PATCH 3/4] feat: apply code review - added content option of Swagger ApiResponses --- .../kotlin/com/piikii/input/http/docs/VoteApiDocs.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt index 0dececc5..10c8a5f3 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt @@ -34,7 +34,15 @@ interface VoteApiDocs { ): ResponseForm @Operation(summary = "방 투표 마감 상태조회 API", description = "투표 마감 상태를 조회합니다") - @ApiResponses(value = [ApiResponse(responseCode = "200", description = "Vote status check succeed")]) + @ApiResponses( + value = [ + ApiResponse( + responseCode = "200", + description = "Vote status check succeed", + content = [Content(schema = Schema(implementation = VoteStatusResponse::class))], + ), + ], + ) fun getVoteStatus( @Parameter( name = "roomId", From e898768315d10800e41727be30f8352abda27ef3 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 30 Jun 2024 00:31:23 +0900 Subject: [PATCH 4/4] fix: ktlint error - VoteStatusResponse --- .../http/dto/response/{VoteResponse.kt => VoteStatusResponse.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/response/{VoteResponse.kt => VoteStatusResponse.kt} (100%) diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/response/VoteResponse.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/response/VoteStatusResponse.kt similarity index 100% rename from piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/response/VoteResponse.kt rename to piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/response/VoteStatusResponse.kt