Skip to content

Commit

Permalink
Merge pull request #76 from mash-up-kr/feature/place-verify
Browse files Browse the repository at this point in the history
feat: 투표 시, 투표하는 Place(장소) 데이터가 올바른지 검증
  • Loading branch information
KimDoubleB authored Jul 4, 2024
2 parents 4e7f4a6 + 5a9ea1f commit 09f36a3
Show file tree
Hide file tree
Showing 18 changed files with 321 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.piikii.application.domain.place
import com.piikii.application.domain.generic.Source
import com.piikii.application.domain.generic.ThumbnailLinks
import com.piikii.application.domain.schedule.PlaceType
import java.util.UUID

data class Place(
val id: Long? = 0L,
Expand All @@ -13,4 +14,5 @@ data class Place(
val phoneNumber: String? = null,
val starGrade: Float? = null,
val source: Source,
val roomId: UUID,
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,30 @@ class PlaceService(
) : PlaceUseCase {
@Transactional
override fun addPlace(
targetRoomId: UUID,
roomId: UUID,
addPlaceRequest: AddPlaceRequest,
): PlaceResponse {
return PlaceResponse(
placeCommandPort.save(
targetRoomId = targetRoomId,
place = addPlaceRequest.toDomain(),
targetRoomId = roomId,
place = addPlaceRequest.toDomain(roomId),
),
)
}

override fun retrieveAllByRoomId(roomId: UUID): List<PlaceTypeGroupResponse> {
override fun findAllByRoomId(roomId: UUID): List<PlaceTypeGroupResponse> {
return groupingByPlaceType(placeQueryPort.retrieveAllByRoomId(roomId))
}

@Transactional
override fun modify(
targetRoomId: Long,
roomId: UUID,
targetPlaceId: Long,
modifyPlaceRequest: ModifyPlaceRequest,
) {
placeCommandPort.update(
targetPlaceId = targetRoomId,
place = modifyPlaceRequest.toDomain(targetRoomId),
targetPlaceId = targetPlaceId,
place = modifyPlaceRequest.toDomain(roomId, targetPlaceId),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ class RoomService(
roomCommandPort.delete(roomId)
}

override fun search(roomId: UUID): RoomResponse {
val retrievedRoom = roomQueryPort.retrieve(roomId)
return RoomResponse.fromDomain(retrievedRoom)
override fun findById(roomId: UUID): RoomResponse {
val retrievedRoom = roomQueryPort.findById(roomId)
return RoomResponse.from(retrievedRoom)
}

override fun changeVoteDeadline(
roomId: UUID,
password: Password,
voteDeadline: LocalDateTime,
) {
roomQueryPort.retrieve(roomId).let { room ->
roomQueryPort.findById(roomId).let { room ->
verifyPassword(room, password)
roomCommandPort.update(room.copy(voteDeadline = voteDeadline))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.piikii.application.domain.vote

import com.piikii.application.port.input.VoteUseCase
import com.piikii.application.port.output.persistence.PlaceQueryPort
import com.piikii.application.port.output.persistence.RoomQueryPort
import com.piikii.application.port.output.persistence.VoteCommandPort
import com.piikii.common.exception.ExceptionCode
Expand All @@ -13,24 +14,32 @@ import java.util.UUID
class VoteService(
private val voteCommandPort: VoteCommandPort,
private val roomQueryPort: RoomQueryPort,
private val placeQueryPort: PlaceQueryPort,
) : VoteUseCase {
override fun vote(
roomId: UUID,
votes: List<Vote>,
) {
if (roomQueryPort.retrieve(roomId).isVoteUnavailable()) {
val room = roomQueryPort.findById(roomId)
require(!room.isVoteUnavailable()) {
throw PiikiiException(
exceptionCode = ExceptionCode.ACCESS_DENIED,
detailMessage = VOTE_UNAVAILABLE,
)
}
// TODO: votes.map { it.placeId } 존재여부 검증 필요 -> 도현이 작업 완료되면 붙일 예정

val placeIds = votes.map { it.placeId }
val placesOfRoom = placeQueryPort.findAllByPlaceIds(placeIds).filter { it.roomId == roomId }
require(placesOfRoom.count() == votes.size) {
throw PiikiiException(exceptionCode = ExceptionCode.VOTE_PLACE_ID_INVALID)
}

voteCommandPort.vote(votes)
}

override fun isVoteFinished(roomId: UUID): Boolean {
val voteDeadline =
roomQueryPort.retrieve(roomId).voteDeadline
roomQueryPort.findById(roomId).voteDeadline
?: throw PiikiiException(
exceptionCode = ExceptionCode.ACCESS_DENIED,
detailMessage = VOTE_NOT_STARTED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import java.util.UUID

interface PlaceUseCase {
fun addPlace(
targetRoomId: UUID,
roomId: UUID,
addPlaceRequest: AddPlaceRequest,
): PlaceResponse

fun retrieveAllByRoomId(roomId: UUID): List<PlaceTypeGroupResponse>
fun findAllByRoomId(roomId: UUID): List<PlaceTypeGroupResponse>

fun modify(
roomId: UUID,
targetPlaceId: Long,
modifyPlaceRequest: ModifyPlaceRequest,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface RoomUseCase {

fun remove(roomId: UUID)

fun search(roomId: UUID): RoomResponse
fun findById(roomId: UUID): RoomResponse

fun changeVoteDeadline(
roomId: UUID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.piikii.application.domain.generic.Source
import com.piikii.application.domain.generic.ThumbnailLinks
import com.piikii.application.domain.place.Place
import com.piikii.application.domain.schedule.PlaceType
import java.util.UUID

data class AddPlaceRequest(
val url: String? = null,
Expand All @@ -14,7 +15,7 @@ data class AddPlaceRequest(
val source: Source,
val placeType: PlaceType,
) {
fun toDomain(): Place {
fun toDomain(roomId: UUID): Place {
return Place(
id = null,
url = url,
Expand All @@ -24,6 +25,7 @@ data class AddPlaceRequest(
starGrade = starGrade,
source = source,
placeType = placeType,
roomId = roomId,
)
}
}
Expand All @@ -37,7 +39,10 @@ data class ModifyPlaceRequest(
val source: Source,
val placeType: PlaceType,
) {
fun toDomain(targetPlaceId: Long): Place {
fun toDomain(
roomId: UUID,
targetPlaceId: Long,
): Place {
return Place(
id = targetPlaceId,
url = url,
Expand All @@ -47,6 +52,7 @@ data class ModifyPlaceRequest(
starGrade = starGrade,
source = source,
placeType = placeType,
roomId = roomId,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data class RoomResponse(
val roomId: UUID,
) {
companion object {
fun fromDomain(room: Room): RoomResponse {
fun from(room: Room): RoomResponse {
return RoomResponse(
meetingName = room.meetingName,
message = room.message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import com.piikii.application.domain.place.Place
import java.util.UUID

interface PlaceQueryPort {
fun retrieveByPlaceId(placeId: Long): Place?
fun findByPlaceId(placeId: Long): Place?

fun findAllByPlaceIds(placeIds: List<Long>): List<Place>

fun retrieveAllByRoomId(roomId: UUID): List<Place>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.piikii.application.domain.room.Room
import java.util.UUID

interface RoomQueryPort {
fun retrieve(roomId: UUID): Room
fun findById(roomId: UUID): Room
}

interface RoomCommandPort {
Expand Down
Loading

0 comments on commit 09f36a3

Please sign in to comment.