From 38f58ae566f15ba9b5bbd8658858f7bb7147bf1f Mon Sep 17 00:00:00 2001 From: thguss Date: Tue, 3 Sep 2024 00:51:27 +0900 Subject: [PATCH] add: added response dto --- .../domain/schedule/ScheduleService.kt | 10 +++++----- .../application/port/input/ScheduleUseCase.kt | 2 +- .../port/input/dto/response/ScheduleResponse.kt | 2 +- .../port/output/persistence/SchedulePort.kt | 4 ++-- .../piikii/input/http/controller/ScheduleApi.kt | 7 ++++--- .../input/http/controller/docs/ScheduleApiDocs.kt | 7 ++++--- .../postgresql/adapter/ScheduleAdapter.kt | 15 +++++++-------- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/piikii-application/src/main/kotlin/com/piikii/application/domain/schedule/ScheduleService.kt b/piikii-application/src/main/kotlin/com/piikii/application/domain/schedule/ScheduleService.kt index 1e5448d0..e9965303 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/domain/schedule/ScheduleService.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/domain/schedule/ScheduleService.kt @@ -19,13 +19,13 @@ class ScheduleService( override fun registerSchedules( roomUid: UuidTypeId, request: RegisterSchedulesRequest, - ) { + ): SchedulesResponse { val schedulesToRegister = request.toDomains(roomUid) deleteSchedules(roomUid, schedulesToRegister) - schedulesToRegister.partition { it.id.getValue() == 0L }.let { (newSchedules, updatedSchedules) -> - scheduleCommandPort.saveSchedules(newSchedules) - scheduleCommandPort.updateSchedules(updatedSchedules) - } + val (newSchedules, changedSchedules) = schedulesToRegister.partition { it.id.getValue() == 0L } + val savedSchedules = scheduleCommandPort.saveSchedules(newSchedules) + val updatedSchedules = scheduleCommandPort.updateSchedules(changedSchedules) + return SchedulesResponse.from(savedSchedules + updatedSchedules) } override fun getSchedules(roomUid: UuidTypeId): SchedulesResponse { diff --git a/piikii-application/src/main/kotlin/com/piikii/application/port/input/ScheduleUseCase.kt b/piikii-application/src/main/kotlin/com/piikii/application/port/input/ScheduleUseCase.kt index a0d70692..dfbf8dbb 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/port/input/ScheduleUseCase.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/port/input/ScheduleUseCase.kt @@ -8,7 +8,7 @@ interface ScheduleUseCase { fun registerSchedules( roomUid: UuidTypeId, request: RegisterSchedulesRequest, - ) + ): SchedulesResponse fun getSchedules(roomUid: UuidTypeId): SchedulesResponse } diff --git a/piikii-application/src/main/kotlin/com/piikii/application/port/input/dto/response/ScheduleResponse.kt b/piikii-application/src/main/kotlin/com/piikii/application/port/input/dto/response/ScheduleResponse.kt index 952ccb43..471f78d2 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/port/input/dto/response/ScheduleResponse.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/port/input/dto/response/ScheduleResponse.kt @@ -14,7 +14,7 @@ data class SchedulesResponse( companion object { fun from(schedules: List): SchedulesResponse { return SchedulesResponse( - schedules.map { ScheduleResponse.from(it) }, + schedules.map { ScheduleResponse.from(it) }.sortedBy { it.sequence }, ) } } 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 0fb763f0..022f72de 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 @@ -13,9 +13,9 @@ interface ScheduleQueryPort { } interface ScheduleCommandPort { - fun saveSchedules(schedules: List) + fun saveSchedules(schedules: List): List fun deleteSchedules(scheduleIds: List) - fun updateSchedules(schedules: List) + fun updateSchedules(schedules: List): List } diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/ScheduleApi.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/ScheduleApi.kt index 233d7146..5e67c6c0 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/ScheduleApi.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/ScheduleApi.kt @@ -30,9 +30,10 @@ class ScheduleApi( override fun registerSchedules( @NotNull @PathVariable roomUid: UUID, @Valid @NotNull @RequestBody request: RegisterSchedulesRequest, - ): ResponseForm { - scheduleUseCase.registerSchedules(UuidTypeId(roomUid), request) - return ResponseForm.EMPTY_RESPONSE + ): ResponseForm { + return ResponseForm( + data = scheduleUseCase.registerSchedules(UuidTypeId(roomUid), request), + ) } @ResponseStatus(HttpStatus.OK) diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/docs/ScheduleApiDocs.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/docs/ScheduleApiDocs.kt index 4215f7f0..abd285c7 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/docs/ScheduleApiDocs.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/docs/ScheduleApiDocs.kt @@ -8,6 +8,7 @@ import io.swagger.v3.oas.annotations.Parameter import io.swagger.v3.oas.annotations.enums.ParameterIn import io.swagger.v3.oas.annotations.media.Content import io.swagger.v3.oas.annotations.media.Schema +import io.swagger.v3.oas.annotations.parameters.RequestBody import io.swagger.v3.oas.annotations.responses.ApiResponse import io.swagger.v3.oas.annotations.responses.ApiResponses import io.swagger.v3.oas.annotations.tags.Tag @@ -25,7 +26,7 @@ interface ScheduleApiDocs { ApiResponse( responseCode = "200", description = "OK success", - content = [Content(schema = Schema(implementation = ResponseForm::class))], + content = [Content(schema = Schema(implementation = SuccessSchedulesResponse::class))], ), ], ) @@ -44,9 +45,9 @@ interface ScheduleApiDocs { ) @Valid @NotNull - @io.swagger.v3.oas.annotations.parameters.RequestBody + @RequestBody request: RegisterSchedulesRequest, - ): ResponseForm + ): ResponseForm @Operation(summary = "스케줄 조회 API", description = "스케줄을 조회합니다.") @ApiResponses( 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 bbb90833..1cd2dafd 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 @@ -21,10 +21,10 @@ class ScheduleAdapter( private val placeRepository: PlaceRepository, ) : ScheduleCommandPort, ScheduleQueryPort { @Transactional - override fun saveSchedules(schedules: List) { - scheduleRepository.saveAll( + override fun saveSchedules(schedules: List): List { + return scheduleRepository.saveAll( schedules.map { ScheduleEntity(it) }, - ) + ).map { it.toDomain() } } @Transactional @@ -36,13 +36,11 @@ class ScheduleAdapter( } @Transactional - override fun updateSchedules(schedules: List) { - for (schedule in schedules) { - updateSchedule(schedule) - } + override fun updateSchedules(schedules: List): List { + return schedules.map { updateSchedule(it) } } - private fun updateSchedule(schedule: Schedule) { + private fun updateSchedule(schedule: Schedule): Schedule { val scheduleId = requireNotNull(schedule.id) { throw PiikiiException( @@ -52,6 +50,7 @@ class ScheduleAdapter( } val scheduleEntity = findScheduleEntityById(scheduleId) scheduleEntity.update(schedule) + return scheduleEntity.toDomain() } override fun findAllByRoomUid(roomUid: UuidTypeId): List {