Skip to content

Commit

Permalink
Merge pull request #70 from mash-up-kr/feature/vote-finish-check
Browse files Browse the repository at this point in the history
feat: Vote 마감 상태 조회 API 추가
  • Loading branch information
KimDoubleB authored Jun 29, 2024
2 parents 4efedd5 + e898768 commit 1c6cc83
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,17 +18,28 @@ class VoteService(
roomId: UUID,
votes: List<Vote>,
) {
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 } 존재여부 검증 필요 -> 도현이 작업 완료되면 붙일 예정
voteCommandPort.vote(votes)
}

override fun isVoteFinished(roomId: UUID): Boolean {
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 = "투표가 시작되지 않았습니다"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ interface VoteUseCase {
roomId: UUID,
votes: List<Vote>,
)

fun isVoteFinished(roomId: UUID): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,6 +34,15 @@ class VoteApi(
return ResponseForm.EMPTY_RESPONSE
}

@ResponseStatus(HttpStatus.OK)
@GetMapping
override fun getVoteStatus(
@PathVariable roomId: UUID,
): ResponseForm<VoteStatusResponse> {
val voteFinished = voteUseCase.isVoteFinished(roomId)
return ResponseForm(data = VoteStatusResponse(voteFinished))
}

@ResponseStatus(HttpStatus.CREATED)
@PostMapping
override fun vote(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -32,12 +33,31 @@ interface VoteApiDocs {
) request: VoteDeadlineSetRequest,
): ResponseForm<Unit>

@Operation(summary = "투표 API", description = "투표를 진행합니다")
@Operation(summary = "방 투표 마감 상태조회 API", description = "투표 마감 상태를 조회합니다")
@ApiResponses(
value = [
ApiResponse(
responseCode = "200",
description = "Vote status check succeed",
content = [Content(schema = Schema(implementation = VoteStatusResponse::class))],
),
],
)
fun getVoteStatus(
@Parameter(
name = "roomId",
description = "조회하고자 하는 방 id",
required = true,
`in` = ParameterIn.PATH,
) roomId: UUID,
): ResponseForm<VoteStatusResponse>

@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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.piikii.input.http.dto.response

data class VoteStatusResponse(val voteFinished: Boolean)

0 comments on commit 1c6cc83

Please sign in to comment.