Skip to content

Commit

Permalink
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ import com.piikii.application.port.input.room.dto.response.RoomGetResponseForm
import com.piikii.application.port.input.room.dto.response.RoomSaveResponseForm
import com.piikii.application.port.output.persistence.RoomCommandPort
import com.piikii.application.port.output.persistence.RoomQueryPort
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
@@ -36,9 +38,21 @@ class RoomService(

override fun changeVoteDeadline(
roomId: UUID,
password: Password,
voteDeadline: LocalDateTime,
) {
val room = roomQueryPort.retrieve(roomId).copy(voteDeadline = voteDeadline)
roomCommandPort.update(room)
roomQueryPort.retrieve(roomId).let { room ->
verifyPassword(room, password)
roomCommandPort.update(room.copy(voteDeadline = voteDeadline))
}
}

private fun verifyPassword(
room: Room,
password: Password,
) {
require(room.isPasswordValid(password)) {
throw PiikiiException(ExceptionCode.ROOM_PASSWORD_INVALID)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.piikii.application.port.input.room

import com.piikii.application.domain.room.Password
import com.piikii.application.port.input.room.dto.request.RoomSaveRequestForm
import com.piikii.application.port.input.room.dto.request.RoomUpdateRequestForm
import com.piikii.application.port.input.room.dto.response.RoomGetResponseForm
@@ -18,6 +19,7 @@ interface RoomUseCase {

fun changeVoteDeadline(
roomId: UUID,
password: Password,
voteDeadline: LocalDateTime,
)
}
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ class VoteApi(
@PathVariable roomId: UUID,
@Validated @RequestBody request: VoteDeadlineSetRequest,
): ResponseForm<Unit> {
roomUseCase.changeVoteDeadline(roomId, request.voteDeadline)
roomUseCase.changeVoteDeadline(roomId, request.password, request.voteDeadline)
return ResponseForm.EMPTY_RESPONSE
}

0 comments on commit c5b079c

Please sign in to comment.