From 6513352252dad52fdabe80f05712cd2824a96245 Mon Sep 17 00:00:00 2001 From: woonseok105 Date: Tue, 12 Dec 2023 21:08:33 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat=20::=20=EC=A3=BC=EA=B0=84=20=EC=97=85?= =?UTF-8?q?=EB=AC=B4=EB=B3=B4=EA=B3=A0=20=EC=83=81=EC=84=B8=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reponse/QueryWorkReportDetailsResponse.kt | 14 ++++++ .../domain/work_report/spi/WorkDetailPort.kt | 9 +++- .../domain/work_report/spi/WorkReportPort.kt | 7 ++- .../usecase/QueryWorkReportDetailsUseCase.kt | 45 +++++++++++++++++++ .../WorkDetailPersistenceAdapter.kt | 17 ++++++- .../WorkReportPersistenceAdapter.kt | 31 ++++++++++++- .../repository/WorkReportRepository.kt | 1 + .../presentation/WorkReportWebAdapter.kt | 11 ++++- 8 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/dto/reponse/QueryWorkReportDetailsResponse.kt create mode 100644 JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/usecase/QueryWorkReportDetailsUseCase.kt diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/dto/reponse/QueryWorkReportDetailsResponse.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/dto/reponse/QueryWorkReportDetailsResponse.kt new file mode 100644 index 0000000..cbb5415 --- /dev/null +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/dto/reponse/QueryWorkReportDetailsResponse.kt @@ -0,0 +1,14 @@ +package com.kodomo.juganbbojjak.domain.work_report.dto.reponse + +import com.kodomo.juganbbojjak.domain.work_report.model.WorkDetailType + +data class QueryWorkReportDetailsResponse( + val title: String, + val workReportList: List +) + +data class WorkReportListResponse( + val contentKey: String, + val contentValue: String, + val contentType: WorkDetailType +) \ 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 cb41cad..05a4c73 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 @@ -1,9 +1,14 @@ package com.kodomo.juganbbojjak.domain.work_report.spi import com.kodomo.juganbbojjak.domain.work_report.model.WorkDetail +import java.util.UUID -interface WorkDetailPort : CommandWorkDetail +interface WorkDetailPort : CommandWorkDetailPort, QueryWorkDetailPort -interface CommandWorkDetail{ +interface CommandWorkDetailPort{ fun saveAllWorkDetails(workDetails: List) } + +interface QueryWorkDetailPort{ + fun queryWorkDetailByWorkReportId(workReportId: UUID): List +} \ 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 fab05b4..a44aef8 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 @@ -1,9 +1,14 @@ package com.kodomo.juganbbojjak.domain.work_report.spi import com.kodomo.juganbbojjak.domain.work_report.model.WorkReport +import java.util.UUID -interface WorkReportPort : CommandWorkReport +interface WorkReportPort : CommandWorkReport, QueryWorkReport interface CommandWorkReport { fun saveWorkReport(workReport: WorkReport): WorkReport +} + +interface QueryWorkReport { + fun queryWorkReportByWeeklyWorkReportId(weeklyWorkReportId: UUID, userId: UUID?): WorkReport? } \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/usecase/QueryWorkReportDetailsUseCase.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/usecase/QueryWorkReportDetailsUseCase.kt new file mode 100644 index 0000000..b319a9d --- /dev/null +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/usecase/QueryWorkReportDetailsUseCase.kt @@ -0,0 +1,45 @@ +package com.kodomo.juganbbojjak.domain.work_report.usecase + +import com.kodomo.juganbbojjak.common.annotation.UseCase +import com.kodomo.juganbbojjak.common.spi.SecurityPort +import com.kodomo.juganbbojjak.domain.user.exception.UserNotFoundException +import com.kodomo.juganbbojjak.domain.user.model.Authority +import com.kodomo.juganbbojjak.domain.user.spi.QueryUserPort +import com.kodomo.juganbbojjak.domain.work_report.dto.reponse.QueryWorkReportDetailsResponse +import com.kodomo.juganbbojjak.domain.work_report.dto.reponse.WorkReportListResponse +import com.kodomo.juganbbojjak.domain.work_report.spi.WorkDetailPort +import com.kodomo.juganbbojjak.domain.work_report.spi.WorkReportPort +import java.util.UUID + +@UseCase +class QueryWorkReportDetailsUseCase( + private val workReportPort: WorkReportPort, + private val workDetailPort: WorkDetailPort, + private val securityPort: SecurityPort, + private val queryUserPort: QueryUserPort +) { + + fun execute(weeklyWorkReportId: UUID): QueryWorkReportDetailsResponse { + + val user = queryUserPort.queryUserById(securityPort.getCurrentUserId()) + ?: throw UserNotFoundException + + val workReport = when (user.authority) { + Authority.ADMIN -> workReportPort.queryWorkReportByWeeklyWorkReportId(weeklyWorkReportId, null) + Authority.USER -> workReportPort.queryWorkReportByWeeklyWorkReportId(weeklyWorkReportId, user.id) + } + + val workDetail = workDetailPort.queryWorkDetailByWorkReportId(workReport!!.id) + + return QueryWorkReportDetailsResponse( + title = workReport.title, + workReportList = workDetail.map { + WorkReportListResponse( + contentKey = it.title, + contentValue = it.content, + contentType = it.type + ) + } + ) + } +} \ 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 ca15c35..90ac454 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,15 +1,20 @@ package com.kodomo.juganbbojjak.domain.work_report.persistence 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 import com.kodomo.juganbbojjak.domain.work_report.persistence.mapper.WorkDetailMapper import com.kodomo.juganbbojjak.domain.work_report.persistence.repository.WorkDetailRepository import com.kodomo.juganbbojjak.domain.work_report.spi.WorkDetailPort import com.kodomo.juganbbojjak.global.annotation.Adapter +import com.querydsl.jpa.impl.JPAQueryFactory +import java.util.* @Adapter class WorkDetailPersistenceAdapter( private val workDetailRepository: WorkDetailRepository, - private val workDetailMapper: WorkDetailMapper + private val workDetailMapper: WorkDetailMapper, + private val queryFactory: JPAQueryFactory ) : WorkDetailPort { override fun saveAllWorkDetails(workDetails: List) { @@ -17,4 +22,14 @@ class WorkDetailPersistenceAdapter( workDetails.map { workDetailMapper.toEntity(it) } ) } + + override fun queryWorkDetailByWorkReportId(workReportId: UUID): List { + return queryFactory + .selectFrom(workDetailEntity) + .join(workReportEntity) + .on(workDetailEntity.workReportEntity.id.eq(workReportEntity.id)) + .where(workDetailEntity.workReportEntity.id.eq(workReportId)) + .fetch() + .map { workDetailMapper.toDomain(it) } + } } \ 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 d411bd3..385ffea 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,15 +1,20 @@ package com.kodomo.juganbbojjak.domain.work_report.persistence 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.spi.WorkReportPort import com.kodomo.juganbbojjak.global.annotation.Adapter +import com.querydsl.core.types.dsl.BooleanExpression +import com.querydsl.jpa.impl.JPAQueryFactory +import java.util.* @Adapter class WorkReportPersistenceAdapter( private val workReportRepository: WorkReportRepository, - private val workReportMapper: WorkReportMapper + private val workReportMapper: WorkReportMapper, + private val queryFactory: JPAQueryFactory ) : WorkReportPort { override fun saveWorkReport(workReport: WorkReport): WorkReport = @@ -19,4 +24,28 @@ class WorkReportPersistenceAdapter( ) ) + override fun queryWorkReportByWeeklyWorkReportId(weeklyWorkReportId: UUID, userId: UUID?): WorkReport? { + val workReportEntity = queryFactory + .selectFrom(workReportEntity) + .where( + workReportEntity.id.eq(weeklyWorkReportId), + eqUserId(userId) + ) + .fetchOne() + + return workReportEntity?.let { + WorkReport( + id = it.id, + title = it.title, + weeklyWorkReportId = weeklyWorkReportId, + userId = it.userEntity.id + ) + } + } + + private fun eqUserId(userId: UUID?): BooleanExpression? = + if (userId != null) + workReportEntity.userEntity.id.eq(userId) + else null + } \ 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 b40444e..8b70e2f 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,4 +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 fbfd1ad..9a7b996 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 @@ -1,9 +1,12 @@ package com.kodomo.juganbbojjak.domain.work_report.presentation +import com.kodomo.juganbbojjak.domain.work_report.dto.reponse.QueryWorkReportDetailsResponse import com.kodomo.juganbbojjak.domain.work_report.presentation.dto.CreateWorkReportWebRequest import com.kodomo.juganbbojjak.domain.work_report.usecase.CreateWorkReportUseCase +import com.kodomo.juganbbojjak.domain.work_report.usecase.QueryWorkReportDetailsUseCase 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.RequestBody @@ -15,7 +18,8 @@ import java.util.UUID @RequestMapping("/work_report") @RestController class WorkReportWebAdapter( - private val createWorkReportUseCase: CreateWorkReportUseCase + private val createWorkReportUseCase: CreateWorkReportUseCase, + private val queryWorkReportDetailsUseCase: QueryWorkReportDetailsUseCase ) { @ResponseStatus(HttpStatus.CREATED) @@ -26,4 +30,9 @@ class WorkReportWebAdapter( ) { createWorkReportUseCase.execute(weeklyWorkReportId, request.toDomainRequest()) } + + @GetMapping("/{weekly-work-report-id}") + fun queryWorkDetails(@PathVariable("weekly-work-report-id") weeklyWorkReportId: UUID): QueryWorkReportDetailsResponse = + queryWorkReportDetailsUseCase.execute(weeklyWorkReportId) + } \ No newline at end of file From 4ec994b4cb4c7cd954c440a72e3afa1b4ae39820 Mon Sep 17 00:00:00 2001 From: woonseok105 Date: Tue, 12 Dec 2023 23:30:02 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix=20::=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../work_report/usecase/QueryWorkReportDetailsUseCase.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/usecase/QueryWorkReportDetailsUseCase.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/usecase/QueryWorkReportDetailsUseCase.kt index b319a9d..8bd68bf 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/usecase/QueryWorkReportDetailsUseCase.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/usecase/QueryWorkReportDetailsUseCase.kt @@ -7,6 +7,7 @@ import com.kodomo.juganbbojjak.domain.user.model.Authority import com.kodomo.juganbbojjak.domain.user.spi.QueryUserPort import com.kodomo.juganbbojjak.domain.work_report.dto.reponse.QueryWorkReportDetailsResponse import com.kodomo.juganbbojjak.domain.work_report.dto.reponse.WorkReportListResponse +import com.kodomo.juganbbojjak.domain.work_report.exception.WorkReportNotFoundException import com.kodomo.juganbbojjak.domain.work_report.spi.WorkDetailPort import com.kodomo.juganbbojjak.domain.work_report.spi.WorkReportPort import java.util.UUID @@ -27,9 +28,9 @@ class QueryWorkReportDetailsUseCase( val workReport = when (user.authority) { Authority.ADMIN -> workReportPort.queryWorkReportByWeeklyWorkReportId(weeklyWorkReportId, null) Authority.USER -> workReportPort.queryWorkReportByWeeklyWorkReportId(weeklyWorkReportId, user.id) - } + } ?: throw WorkReportNotFoundException - val workDetail = workDetailPort.queryWorkDetailByWorkReportId(workReport!!.id) + val workDetail = workDetailPort.queryWorkDetailByWorkReportId(workReport.id) return QueryWorkReportDetailsResponse( title = workReport.title, From 429af0eae7d969f32d94fae18bfaaa03b048db80 Mon Sep 17 00:00:00 2001 From: woonseok105 Date: Tue, 12 Dec 2023 23:49:55 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat=20::=20=EA=B6=8C=ED=95=9C=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/kodomo/juganbbojjak/global/security/SecurityConfig.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/global/security/SecurityConfig.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/global/security/SecurityConfig.kt index 35ec4c3..d3ef1f2 100644 --- a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/global/security/SecurityConfig.kt +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/global/security/SecurityConfig.kt @@ -35,7 +35,8 @@ class SecurityConfig( .requestMatchers(HttpMethod.GET, "/event_schedules/{weekly-event-schedule-id}").hasAuthority(ADMIN.name) .requestMatchers(HttpMethod.POST, "/work_report/{weekly-work-report-id}").hasAuthority(USER.name) - + .requestMatchers(HttpMethod.GET, "/work_report/{weekly-work-report-id}").hasAnyAuthority(USER.name, ADMIN.name) + .anyRequest().permitAll() } .apply(FilterConfig(jwtTokenParser, objectMapper))