diff --git a/piikii-application/src/main/kotlin/com/piikii/application/domain/place/PlaceService.kt b/piikii-application/src/main/kotlin/com/piikii/application/domain/place/PlaceService.kt index e9a94791..e61e941e 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/domain/place/PlaceService.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/domain/place/PlaceService.kt @@ -33,7 +33,7 @@ class PlaceService( targetRoomUid: UuidTypeId, addPlaceRequest: AddPlaceRequest, placeImages: List?, - ): PlaceResponse { + ): List { val imageUrls = placeImages?.let { objectStoragePort.uploadAll( @@ -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 { diff --git a/piikii-application/src/main/kotlin/com/piikii/application/port/input/PlaceUseCase.kt b/piikii-application/src/main/kotlin/com/piikii/application/port/input/PlaceUseCase.kt index 1adcde15..7c29202d 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/port/input/PlaceUseCase.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/port/input/PlaceUseCase.kt @@ -13,7 +13,7 @@ interface PlaceUseCase { targetRoomUid: UuidTypeId, addPlaceRequest: AddPlaceRequest, placeImages: List?, - ): PlaceResponse + ): List fun findAllByRoomUidGroupByPlaceType(roomUid: UuidTypeId): List diff --git a/piikii-application/src/main/kotlin/com/piikii/application/port/input/dto/request/PlaceRequest.kt b/piikii-application/src/main/kotlin/com/piikii/application/port/input/dto/request/PlaceRequest.kt index a3328aa5..da7b0bc8 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/port/input/dto/request/PlaceRequest.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/port/input/dto/request/PlaceRequest.kt @@ -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, @field:NotNull(message = "일정 타입은 필수입니다.") @field:Schema( description = "스케줄 타입", diff --git a/piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/PlacePort.kt b/piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/PlacePort.kt index 1abf6522..d6fb41ad 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/PlacePort.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/PlacePort.kt @@ -21,6 +21,12 @@ interface PlaceCommandPort { place: Place, ): Place + fun saveAll( + roomUid: UuidTypeId, + scheduleIds: List, + places: List, + ): List + fun update( targetPlaceId: LongTypeId, place: Place, diff --git a/piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/SchedulePort.kt b/piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/SchedulePort.kt index 501b364f..0fb763f0 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/SchedulePort.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/SchedulePort.kt @@ -7,7 +7,9 @@ import com.piikii.application.domain.schedule.Schedule interface ScheduleQueryPort { fun findAllByRoomUid(roomUid: UuidTypeId): List - fun findScheduleById(id: LongTypeId): Schedule + fun findById(id: LongTypeId): Schedule + + fun findAllByIds(ids: List): List } interface ScheduleCommandPort { diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/PlaceApi.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/PlaceApi.kt index d63582c6..adbd1ed6 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/PlaceApi.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/PlaceApi.kt @@ -38,7 +38,7 @@ class PlaceApi( @NotNull @PathVariable roomUid: UUID, @Valid @NotNull @RequestPart addPlaceRequest: AddPlaceRequest, @RequestPart(required = false) placeImages: List?, - ): ResponseForm { + ): ResponseForm> { return ResponseForm(placeUseCase.addPlace(UuidTypeId(roomUid), addPlaceRequest, placeImages)) } diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/docs/PlaceDocs.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/docs/PlaceDocs.kt index 737a6532..278a4d10 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/docs/PlaceDocs.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/docs/PlaceDocs.kt @@ -20,7 +20,7 @@ import java.util.UUID @Tag(name = "Place Api", description = "방 장소 관련 API") interface PlaceDocs { - class SuccessPlaceResponse : ResponseForm() + class SuccessPlaceResponse : ResponseForm>() class SuccessPlaceTypeGroupResponse : ResponseForm() @@ -56,7 +56,7 @@ interface PlaceDocs { description = "장소 이미지 파일들", required = false, ) placeImages: List?, - ): ResponseForm + ): ResponseForm> @Operation(summary = "방 장소 조회 API", description = "방에 등록된 장소를 모두 조회합니다.") @ApiResponses( diff --git a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/PlaceAdapter.kt b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/PlaceAdapter.kt index a9f2e047..7eae93f2 100644 --- a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/PlaceAdapter.kt +++ b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/PlaceAdapter.kt @@ -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, + places: List, + ): List { + 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, diff --git a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/ScheduleAdapter.kt b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/ScheduleAdapter.kt index 7acaf331..bbb90833 100644 --- a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/ScheduleAdapter.kt +++ b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/ScheduleAdapter.kt @@ -58,7 +58,7 @@ 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, @@ -66,6 +66,10 @@ class ScheduleAdapter( ) } + override fun findAllByIds(ids: List): List { + return scheduleRepository.findAllById(ids.map { it.getValue() }).map { it.toDomain() } + } + private fun findScheduleEntityById(id: LongTypeId): ScheduleEntity { return scheduleRepository.findByIdOrNull(id.getValue()) ?: throw PiikiiException(