From 93b028f865ab2c307c247cc9056af8c7e66e552e Mon Sep 17 00:00:00 2001 From: woonseok105 Date: Thu, 14 Dec 2023 22:29:26 +0900 Subject: [PATCH] =?UTF-8?q?feat=20::=20=EC=A3=BC=EA=B0=84=20=EC=97=85?= =?UTF-8?q?=EB=AC=B4=20=EB=B3=B4=EA=B3=A0=20=EC=88=98=EC=A0=95=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/UpdateWorkReportRequest.kt | 15 +++++++ .../exception/WorkDetailNotFoundException.kt | 8 ++++ .../exception/error/WorkReportErrorCode.kt | 3 +- .../domain/work_report/model/WorkDetail.kt | 15 ++++++- .../domain/work_report/model/WorkReport.kt | 9 +++- .../domain/work_report/spi/WorkDetailPort.kt | 2 + .../domain/work_report/spi/WorkReportPort.kt | 2 +- .../usecase/UpdateWorkReportUseCase.kt | 32 ++++++++++++++ .../WorkDetailPersistenceAdapter.kt | 15 ++++++- .../WorkReportPersistenceAdapter.kt | 15 +++---- .../repository/WorkReportRepository.kt | 2 +- .../presentation/WorkReportWebAdapter.kt | 12 +++++- .../dto/UpdateWorkReportWebRequest.kt | 42 +++++++++++++++++++ 13 files changed, 156 insertions(+), 16 deletions(-) create mode 100644 JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/dto/request/UpdateWorkReportRequest.kt create mode 100644 JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/exception/WorkDetailNotFoundException.kt create mode 100644 JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/usecase/UpdateWorkReportUseCase.kt create mode 100644 JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/presentation/dto/UpdateWorkReportWebRequest.kt diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/dto/request/UpdateWorkReportRequest.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/dto/request/UpdateWorkReportRequest.kt new file mode 100644 index 0000000..d7c49e5 --- /dev/null +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/dto/request/UpdateWorkReportRequest.kt @@ -0,0 +1,15 @@ +package com.kodomo.juganbbojjak.domain.work_report.dto.request + +import java.util.UUID + +data class UpdateWorkReportRequest( + val workReportId: UUID, + val title: String, + val workReportDetails: List +) + +data class UpdateWorkReportDetailsRequest( + val workDetailId: UUID, + val contentKey: String, + val contentValue: String +) \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/exception/WorkDetailNotFoundException.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/exception/WorkDetailNotFoundException.kt new file mode 100644 index 0000000..014f311 --- /dev/null +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/exception/WorkDetailNotFoundException.kt @@ -0,0 +1,8 @@ +package com.kodomo.juganbbojjak.domain.work_report.exception + +import com.kodomo.juganbbojjak.common.error.JuGanBbojjakException +import com.kodomo.juganbbojjak.domain.work_report.exception.error.WorkReportErrorCode + +object WorkDetailNotFoundException : JuGanBbojjakException( + WorkReportErrorCode.WORK_DETAIL_NOT_FOUND +) \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/exception/error/WorkReportErrorCode.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/exception/error/WorkReportErrorCode.kt index 11e7aae..0c7d713 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/exception/error/WorkReportErrorCode.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/exception/error/WorkReportErrorCode.kt @@ -8,5 +8,6 @@ enum class WorkReportErrorCode( ) : ErrorProperty { WEEKLY_WORK_REPORT_NOT_FOUND(404, "Weekly Work Report Not Found"), - WORK_REPORT_NOT_FOUND(404, "Work Report Not Found") + WORK_REPORT_NOT_FOUND(404, "Work Report Not Found"), + WORK_DETAIL_NOT_FOUND(404, "Work Detail Not Found") } \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/model/WorkDetail.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/model/WorkDetail.kt index 77f50f4..8c13dcb 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/model/WorkDetail.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/model/WorkDetail.kt @@ -1,10 +1,11 @@ package com.kodomo.juganbbojjak.domain.work_report.model import com.kodomo.juganbbojjak.common.annotation.Aggregate +import com.kodomo.juganbbojjak.domain.work_report.dto.request.UpdateWorkReportDetailsRequest import java.util.UUID @Aggregate -class WorkDetail( +data class WorkDetail( val id: UUID = UUID.randomUUID(), @@ -15,4 +16,14 @@ class WorkDetail( val type: WorkDetailType, val workReportId: UUID -) \ No newline at end of file +) { + + fun updateWorkDetail(updateWorkReportDetails: UpdateWorkReportDetailsRequest): WorkDetail = + WorkDetail( + id = id, + title = updateWorkReportDetails.contentKey, + content = updateWorkReportDetails.contentValue, + workReportId = workReportId, + type = type + ) +} \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/model/WorkReport.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/model/WorkReport.kt index fc967d2..c1925d8 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/model/WorkReport.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/model/WorkReport.kt @@ -4,7 +4,7 @@ import com.kodomo.juganbbojjak.common.annotation.Aggregate import java.util.UUID @Aggregate -class WorkReport ( +data class WorkReport( val id: UUID = UUID.randomUUID(), @@ -13,4 +13,9 @@ class WorkReport ( val weeklyWorkReportId: UUID, val userId: UUID -) \ No newline at end of file +) { + + fun updateWorkReport(title: String) = this.copy( + title = title + ) +} \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/spi/WorkDetailPort.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/spi/WorkDetailPort.kt index 93e6e37..6d0f704 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/spi/WorkDetailPort.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/spi/WorkDetailPort.kt @@ -8,8 +8,10 @@ interface WorkDetailPort : CommandWorkDetailPort, QueryWorkDetailPort interface CommandWorkDetailPort{ fun saveAllWorkDetails(workDetails: List) + fun saveWorkDetail(workDetail: WorkDetail) } interface QueryWorkDetailPort{ fun queryWorkDetailByWeeklyWorkReportId(weeklyWorkReportId: UUID, userId: UUID?): List + fun queryWorkDetailById(workDetailIdList: UUID): WorkDetail } \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/spi/WorkReportPort.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/spi/WorkReportPort.kt index c00817f..2140a0f 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/spi/WorkReportPort.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/spi/WorkReportPort.kt @@ -10,5 +10,5 @@ interface CommandWorkReportPort { } interface QueryWorkReportPort { - + fun queryWorkReportById(workReportId: UUID): WorkReport } \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/usecase/UpdateWorkReportUseCase.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/usecase/UpdateWorkReportUseCase.kt new file mode 100644 index 0000000..8fe5af7 --- /dev/null +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/usecase/UpdateWorkReportUseCase.kt @@ -0,0 +1,32 @@ +package com.kodomo.juganbbojjak.domain.work_report.usecase + +import com.kodomo.juganbbojjak.common.annotation.UseCase +import com.kodomo.juganbbojjak.domain.work_report.dto.request.UpdateWorkReportRequest +import com.kodomo.juganbbojjak.domain.work_report.spi.CommandWorkDetailPort +import com.kodomo.juganbbojjak.domain.work_report.spi.CommandWorkReportPort +import com.kodomo.juganbbojjak.domain.work_report.spi.QueryWorkDetailPort +import com.kodomo.juganbbojjak.domain.work_report.spi.QueryWorkReportPort + +@UseCase +class UpdateWorkReportUseCase( + private val queryWorkReportPort: QueryWorkReportPort, + private val commandWorkReportPort: CommandWorkReportPort, + private val queryWorkDetailPort: QueryWorkDetailPort, + private val commandWorkDetailPort: CommandWorkDetailPort +) { + + fun execute(request: UpdateWorkReportRequest) { + val workReportEntity = queryWorkReportPort.queryWorkReportById(request.workReportId) + + commandWorkReportPort.saveWorkReport(workReportEntity.updateWorkReport(request.title)) + + request.workReportDetails.forEach { workReportDetails -> + val workDetailList = + queryWorkDetailPort.queryWorkDetailById(workReportDetails.workDetailId) + + commandWorkDetailPort.saveWorkDetail( + workDetailList.updateWorkDetail(workReportDetails) + ) + } + } +} \ No newline at end of file diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/WorkDetailPersistenceAdapter.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/WorkDetailPersistenceAdapter.kt index 14e8074..29d556e 100644 --- a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/WorkDetailPersistenceAdapter.kt +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/WorkDetailPersistenceAdapter.kt @@ -1,5 +1,6 @@ package com.kodomo.juganbbojjak.domain.work_report.persistence +import com.kodomo.juganbbojjak.domain.work_report.exception.WorkDetailNotFoundException import com.kodomo.juganbbojjak.domain.work_report.model.WorkDetail import com.kodomo.juganbbojjak.domain.work_report.persistence.entity.QWorkDetailEntity.workDetailEntity import com.kodomo.juganbbojjak.domain.work_report.persistence.entity.QWorkReportEntity.workReportEntity @@ -9,11 +10,11 @@ import com.kodomo.juganbbojjak.domain.work_report.persistence.vo.QQueryWorkRepor import com.kodomo.juganbbojjak.domain.work_report.spi.WorkDetailPort import com.kodomo.juganbbojjak.domain.work_report.spi.vo.WorkReportDetailsVO import com.kodomo.juganbbojjak.global.annotation.Adapter -import com.querydsl.core.group.GroupBy import com.querydsl.core.group.GroupBy.groupBy import com.querydsl.core.group.GroupBy.list import com.querydsl.core.types.dsl.BooleanExpression import com.querydsl.jpa.impl.JPAQueryFactory +import org.springframework.data.repository.findByIdOrNull import java.util.* @Adapter @@ -57,5 +58,17 @@ class WorkDetailPersistenceAdapter( workReportEntity.userEntity.id.eq(userId) else null + override fun queryWorkDetailById(workDetailIdList: UUID): WorkDetail { + return workDetailMapper.toDomain( + workDetailRepository.findByIdOrNull(workDetailIdList) + ?: throw WorkDetailNotFoundException + ) + + } + override fun saveWorkDetail(workDetail: WorkDetail) { + workDetailRepository.save( + workDetailMapper.toEntity(workDetail) + ) + } } \ No newline at end of file diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/WorkReportPersistenceAdapter.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/WorkReportPersistenceAdapter.kt index e6984b7..a9587eb 100644 --- a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/WorkReportPersistenceAdapter.kt +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/WorkReportPersistenceAdapter.kt @@ -1,23 +1,18 @@ package com.kodomo.juganbbojjak.domain.work_report.persistence +import com.kodomo.juganbbojjak.domain.work_report.exception.WorkReportNotFoundException import com.kodomo.juganbbojjak.domain.work_report.model.WorkReport -import com.kodomo.juganbbojjak.domain.work_report.persistence.entity.QWorkReportEntity.workReportEntity import com.kodomo.juganbbojjak.domain.work_report.persistence.mapper.WorkReportMapper import com.kodomo.juganbbojjak.domain.work_report.persistence.repository.WorkReportRepository -import com.kodomo.juganbbojjak.domain.work_report.persistence.vo.QQueryWorkReportDetailsVO import com.kodomo.juganbbojjak.domain.work_report.spi.WorkReportPort -import com.kodomo.juganbbojjak.domain.work_report.spi.vo.WorkReportDetailsVO import com.kodomo.juganbbojjak.global.annotation.Adapter -import com.querydsl.core.types.dsl.BooleanExpression -import com.querydsl.jpa.impl.JPAQueryFactory +import org.springframework.data.repository.findByIdOrNull import java.util.* -import kotlin.collections.List @Adapter class WorkReportPersistenceAdapter( private val workReportRepository: WorkReportRepository, private val workReportMapper: WorkReportMapper, - private val queryFactory: JPAQueryFactory ) : WorkReportPort { override fun saveWorkReport(workReport: WorkReport): WorkReport = @@ -27,4 +22,10 @@ class WorkReportPersistenceAdapter( ) ) + override fun queryWorkReportById(workReportId: UUID): WorkReport = + workReportMapper.toDomain( + workReportRepository.findByIdOrNull(workReportId) + ?: throw WorkReportNotFoundException + ) + } \ No newline at end of file diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/repository/WorkReportRepository.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/repository/WorkReportRepository.kt index 8b70e2f..cbdde01 100644 --- a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/repository/WorkReportRepository.kt +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/repository/WorkReportRepository.kt @@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository import java.util.UUID interface WorkReportRepository : JpaRepository { - fun findByWeeklyWorkReportEntityId(weeklyWorkReportId: UUID): WorkReportEntity + } \ No newline at end of file diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/presentation/WorkReportWebAdapter.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/presentation/WorkReportWebAdapter.kt index d6a94d5..acec02e 100644 --- a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/presentation/WorkReportWebAdapter.kt +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/presentation/WorkReportWebAdapter.kt @@ -2,13 +2,16 @@ package com.kodomo.juganbbojjak.domain.work_report.presentation import com.kodomo.juganbbojjak.domain.work_report.dto.response.QueryWorkReportDetailsResponse import com.kodomo.juganbbojjak.domain.work_report.presentation.dto.CreateWorkReportWebRequest +import com.kodomo.juganbbojjak.domain.work_report.presentation.dto.UpdateWorkReportWebRequest import com.kodomo.juganbbojjak.domain.work_report.usecase.CreateWorkReportUseCase import com.kodomo.juganbbojjak.domain.work_report.usecase.QueryWorkReportDetailsUseCase +import com.kodomo.juganbbojjak.domain.work_report.usecase.UpdateWorkReportUseCase import jakarta.validation.Valid import org.springframework.http.HttpStatus import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.PutMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.ResponseStatus @@ -19,7 +22,8 @@ import java.util.UUID @RestController class WorkReportWebAdapter( private val createWorkReportUseCase: CreateWorkReportUseCase, - private val queryWorkReportDetailsUseCase: QueryWorkReportDetailsUseCase + private val queryWorkReportDetailsUseCase: QueryWorkReportDetailsUseCase, + private val updateWorkReportUseCase: UpdateWorkReportUseCase ) { @ResponseStatus(HttpStatus.CREATED) @@ -35,4 +39,10 @@ class WorkReportWebAdapter( fun queryWorkDetails(@PathVariable("weekly-work-report-id") weeklyWorkReportId: UUID): QueryWorkReportDetailsResponse = queryWorkReportDetailsUseCase.execute(weeklyWorkReportId) + @ResponseStatus(HttpStatus.NO_CONTENT) + @PutMapping + fun updateWorkReport(@RequestBody request: UpdateWorkReportWebRequest) { + updateWorkReportUseCase.execute(request.toDomainRequest()) + } + } \ No newline at end of file diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/presentation/dto/UpdateWorkReportWebRequest.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/presentation/dto/UpdateWorkReportWebRequest.kt new file mode 100644 index 0000000..38bbb8e --- /dev/null +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/presentation/dto/UpdateWorkReportWebRequest.kt @@ -0,0 +1,42 @@ +package com.kodomo.juganbbojjak.domain.work_report.presentation.dto + +import com.kodomo.juganbbojjak.domain.work_report.dto.request.UpdateWorkReportDetailsRequest +import com.kodomo.juganbbojjak.domain.work_report.dto.request.UpdateWorkReportRequest +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.NotNull +import java.util.* + +data class UpdateWorkReportWebRequest( + + @NotBlank + val workReportId: UUID, + + @NotBlank + val title: String, + + val workReportDetails: List<@NotNull UpdateWorkReportDetailsWebRequest> +) { + fun toDomainRequest() = UpdateWorkReportRequest( + workReportId = workReportId, + title = title, + workReportDetails = workReportDetails.map { + UpdateWorkReportDetailsRequest( + workDetailId = it.workDetailId, + contentKey = it.contentKey, + contentValue = it.contentValue + ) + } + ) +} + +data class UpdateWorkReportDetailsWebRequest( + + @NotBlank + val workDetailId: UUID, + + @NotBlank + val contentKey: String, + + @NotBlank + val contentValue: String +) \ No newline at end of file