Skip to content

Commit

Permalink
Merge pull request #161 from mash-up-kr/fix/#158
Browse files Browse the repository at this point in the history
fix: 방 장소 추가 시 여러 개의 Schedule을 받을 수 있도록 수정
  • Loading branch information
K-Diger authored Aug 20, 2024
2 parents e1402f9 + b886325 commit 4b30f88
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PlaceService(
targetRoomUid: UuidTypeId,
addPlaceRequest: AddPlaceRequest,
placeImages: List<MultipartFile>?,
): PlaceResponse {
): List<PlaceResponse> {
val imageUrls =
placeImages?.let {
objectStoragePort.uploadAll(
Expand All @@ -43,22 +43,22 @@ class PlaceService(
} ?: listOf()

val room = roomQueryPort.findById(targetRoomUid)
val schedule = scheduleQueryPort.findScheduleById(LongTypeId(addPlaceRequest.scheduleId))
val place =
addPlaceRequest.toDomain(
roomUid = room.roomUid,
// TODO 이거 좀 예쁘게 처리하는법 알아보기
scheduleId = schedule.id,
imageUrls = imageUrls,
)
val schedules = scheduleQueryPort.findAllByIds(addPlaceRequest.scheduleIds.map(::LongTypeId))

return PlaceResponse(
placeCommandPort.save(
roomUid = room.roomUid,
scheduleId = schedule.id,
place = place,
),
)
val places =
schedules.map { schedule ->
addPlaceRequest.toDomain(
roomUid = room.roomUid,
scheduleId = schedule.id,
imageUrls = imageUrls,
)
}

return placeCommandPort.saveAll(
roomUid = room.roomUid,
scheduleIds = schedules.map { it.id },
places = places,
).map(::PlaceResponse)
}

override fun findAllByRoomUidGroupByPlaceType(roomUid: UuidTypeId): List<ScheduleTypeGroupResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface PlaceUseCase {
targetRoomUid: UuidTypeId,
addPlaceRequest: AddPlaceRequest,
placeImages: List<MultipartFile>?,
): PlaceResponse
): List<PlaceResponse>

fun findAllByRoomUidGroupByPlaceType(roomUid: UuidTypeId): List<ScheduleTypeGroupResponse>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import jakarta.validation.constraints.Size

data class AddPlaceRequest(
@field:NotNull(message = "일정 ID는 필수입니다.")
@field:Schema(description = "일정 ID", example = "1")
val scheduleId: Long,
@field:Schema(description = "일정 ID", example = "[1, 2, 3]")
val scheduleIds: List<Long>,
@field:NotNull(message = "일정 타입은 필수입니다.")
@field:Schema(
description = "스케줄 타입",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ interface PlaceCommandPort {
place: Place,
): Place

fun saveAll(
roomUid: UuidTypeId,
scheduleIds: List<LongTypeId>,
places: List<Place>,
): List<Place>

fun update(
targetPlaceId: LongTypeId,
place: Place,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import com.piikii.application.domain.schedule.Schedule
interface ScheduleQueryPort {
fun findAllByRoomUid(roomUid: UuidTypeId): List<Schedule>

fun findScheduleById(id: LongTypeId): Schedule
fun findById(id: LongTypeId): Schedule

fun findAllByIds(ids: List<LongTypeId>): List<Schedule>
}

interface ScheduleCommandPort {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PlaceApi(
@NotNull @PathVariable roomUid: UUID,
@Valid @NotNull @RequestPart addPlaceRequest: AddPlaceRequest,
@RequestPart(required = false) placeImages: List<MultipartFile>?,
): ResponseForm<PlaceResponse> {
): ResponseForm<List<PlaceResponse>> {
return ResponseForm(placeUseCase.addPlace(UuidTypeId(roomUid), addPlaceRequest, placeImages))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import java.util.UUID

@Tag(name = "Place Api", description = "방 장소 관련 API")
interface PlaceDocs {
class SuccessPlaceResponse : ResponseForm<PlaceResponse>()
class SuccessPlaceResponse : ResponseForm<List<PlaceResponse>>()

class SuccessPlaceTypeGroupResponse : ResponseForm<ScheduleTypeGroupResponse>()

Expand Down Expand Up @@ -56,7 +56,7 @@ interface PlaceDocs {
description = "장소 이미지 파일들",
required = false,
) placeImages: List<MultipartFile>?,
): ResponseForm<PlaceResponse>
): ResponseForm<List<PlaceResponse>>

@Operation(summary = "방 장소 조회 API", description = "방에 등록된 장소를 모두 조회합니다.")
@ApiResponses(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,28 @@ class PlaceAdapter(
val placeEntity =
PlaceEntity(
roomUid = roomUid,
scheduleId = scheduleId,
scheduleId = place.id,
place = place,
)
return placeRepository.save(placeEntity).toDomain()
}

override fun saveAll(
roomUid: UuidTypeId,
scheduleIds: List<LongTypeId>,
places: List<Place>,
): List<Place> {
val placeEntities =
places.map {
PlaceEntity(
roomUid = roomUid,
scheduleId = it.id,
place = it,
)
}
return placeRepository.saveAll(placeEntities).map { it.toDomain() }
}

@Transactional
override fun update(
targetPlaceId: LongTypeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,18 @@ class ScheduleAdapter(
return scheduleRepository.findByroomUidOrderBySequenceAsc(roomUid.getValue()).map { it.toDomain() }
}

override fun findScheduleById(id: LongTypeId): Schedule {
override fun findById(id: LongTypeId): Schedule {
return scheduleRepository.findByIdOrNull(id.getValue())?.toDomain()
?: throw PiikiiException(
exceptionCode = ExceptionCode.NOT_FOUNDED,
detailMessage = "Schedule ID: $id",
)
}

override fun findAllByIds(ids: List<LongTypeId>): List<Schedule> {
return scheduleRepository.findAllById(ids.map { it.getValue() }).map { it.toDomain() }
}

private fun findScheduleEntityById(id: LongTypeId): ScheduleEntity {
return scheduleRepository.findByIdOrNull(id.getValue())
?: throw PiikiiException(
Expand Down

0 comments on commit 4b30f88

Please sign in to comment.