diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/spi/EventSchedulePort.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/spi/EventSchedulePort.kt index 045bb4f..d745c17 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/spi/EventSchedulePort.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/spi/EventSchedulePort.kt @@ -11,6 +11,8 @@ interface EventSchedulePort : QueryEventSchedulePort, CommandEventSchedulePort { interface QueryEventSchedulePort { fun queryWeeklyEventScheduleById(weeklyEventScheduleId: UUID): WeeklyEventSchedule? fun queryEventSchedulesByWeeklyEventScheduleId(weeklyEventScheduleId: UUID, userId: UUID?): List + fun queryAllEventScheduleList(): List + fun queryLatestEventSchedule(): WeeklyEventSchedule? } interface CommandEventSchedulePort { diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/dto/response/QueryLatestWorkResponse.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/dto/response/QueryLatestWorkResponse.kt new file mode 100644 index 0000000..ef45680 --- /dev/null +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/dto/response/QueryLatestWorkResponse.kt @@ -0,0 +1,13 @@ +package com.kodomo.juganbbojjak.domain.user.dto.response + +import java.time.LocalDate +import java.util.UUID + +data class QueryLatestWorkResponse( + val workReportId: UUID, + val workReportStartDate: LocalDate, + val workReportEndDate: LocalDate, + val eventScheduleId: UUID, + val eventScheduleStartDate: LocalDate, + val eventScheduleEndDate: LocalDate +) \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/dto/response/QueryWeeklyListResponse.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/dto/response/QueryWeeklyListResponse.kt new file mode 100644 index 0000000..4309f2c --- /dev/null +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/dto/response/QueryWeeklyListResponse.kt @@ -0,0 +1,16 @@ +package com.kodomo.juganbbojjak.domain.user.dto.response + +import com.kodomo.juganbbojjak.domain.user.model.WeeklyListType +import java.time.LocalDate +import java.util.UUID + +data class QueryWeeklyListResponse ( + val weeklyList: List +) + +data class WeeklyList( + val id: UUID, + val startDate: LocalDate, + val endDate: LocalDate, + val type: WeeklyListType +) \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/model/WeeklyListType.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/model/WeeklyListType.kt new file mode 100644 index 0000000..d6077c5 --- /dev/null +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/model/WeeklyListType.kt @@ -0,0 +1,5 @@ +package com.kodomo.juganbbojjak.domain.user.model + +enum class WeeklyListType { + WORK_REPORT, EVENT_SCHEDULE +} \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/usecase/QueryLatestWorkUseCase.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/usecase/QueryLatestWorkUseCase.kt new file mode 100644 index 0000000..0db4227 --- /dev/null +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/usecase/QueryLatestWorkUseCase.kt @@ -0,0 +1,29 @@ +package com.kodomo.juganbbojjak.domain.user.usecase + +import com.kodomo.juganbbojjak.common.annotation.UseCase +import com.kodomo.juganbbojjak.domain.event_schedule.exception.WeeklyEventScheduleNotFoundException +import com.kodomo.juganbbojjak.domain.event_schedule.spi.QueryEventSchedulePort +import com.kodomo.juganbbojjak.domain.user.dto.response.QueryLatestWorkResponse +import com.kodomo.juganbbojjak.domain.work_report.spi.QueryWeeklyWorkReportPort + +@UseCase +class QueryLatestWorkUseCase( + private val queryWeeklyWorkReportPort: QueryWeeklyWorkReportPort, + private val queryEventSchedulePort: QueryEventSchedulePort +) { + + fun execute(): QueryLatestWorkResponse { + val weeklyWorkReport = queryWeeklyWorkReportPort.queryLatestWeeklyWorkReport() + val eventSchedule = queryEventSchedulePort.queryLatestEventSchedule() + ?: throw WeeklyEventScheduleNotFoundException + + return QueryLatestWorkResponse( + workReportId = weeklyWorkReport.id, + workReportStartDate = weeklyWorkReport.startDate, + workReportEndDate = weeklyWorkReport.endDate, + eventScheduleId = eventSchedule.id, + eventScheduleStartDate = eventSchedule.startDate, + eventScheduleEndDate = eventSchedule.endDate + ) + } +} \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/usecase/QueryWeeklyListUseCase.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/usecase/QueryWeeklyListUseCase.kt new file mode 100644 index 0000000..5e6be4b --- /dev/null +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/usecase/QueryWeeklyListUseCase.kt @@ -0,0 +1,43 @@ +package com.kodomo.juganbbojjak.domain.user.usecase + +import com.kodomo.juganbbojjak.common.annotation.UseCase +import com.kodomo.juganbbojjak.domain.event_schedule.spi.QueryEventSchedulePort +import com.kodomo.juganbbojjak.domain.user.dto.response.QueryWeeklyListResponse +import com.kodomo.juganbbojjak.domain.user.dto.response.WeeklyList +import com.kodomo.juganbbojjak.domain.user.model.WeeklyListType +import com.kodomo.juganbbojjak.domain.user.model.WeeklyListType.EVENT_SCHEDULE +import com.kodomo.juganbbojjak.domain.user.model.WeeklyListType.WORK_REPORT +import com.kodomo.juganbbojjak.domain.work_report.spi.QueryWeeklyWorkReportPort + +@UseCase +class QueryWeeklyListUseCase( + private val queryWeeklyWorkReportPort: QueryWeeklyWorkReportPort, + private val queryWeeklySchedulePort: QueryEventSchedulePort +) { + + fun execute(weeklyListType: WeeklyListType): QueryWeeklyListResponse = + + when (weeklyListType) { + WORK_REPORT -> QueryWeeklyListResponse( + queryWeeklyWorkReportPort.queryAllWeeklyWorkReportList().map { + WeeklyList( + id = it.id, + startDate = it.startDate, + endDate = it.endDate, + type = WORK_REPORT + ) + } + ) + + EVENT_SCHEDULE -> QueryWeeklyListResponse( + queryWeeklySchedulePort.queryAllEventScheduleList().map { + WeeklyList( + id = it.id, + startDate = it.startDate, + endDate = it.endDate, + type = EVENT_SCHEDULE + ) + } + ) + } +} \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/spi/WeeklyWorkReportPort.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/spi/WeeklyWorkReportPort.kt index 70f803c..609f1c6 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/spi/WeeklyWorkReportPort.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/spi/WeeklyWorkReportPort.kt @@ -11,4 +11,6 @@ interface CommandWeeklyWorkReportPort { interface QueryWeeklyWorkReportPort { fun queryWeeklyWorkReportById(weeklyWorkReportId: UUID): WeeklyWorkReport + fun queryAllWeeklyWorkReportList(): List + fun queryLatestWeeklyWorkReport(): WeeklyWorkReport } \ 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 a44aef8..ace58c2 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 @@ -3,12 +3,12 @@ package com.kodomo.juganbbojjak.domain.work_report.spi import com.kodomo.juganbbojjak.domain.work_report.model.WorkReport import java.util.UUID -interface WorkReportPort : CommandWorkReport, QueryWorkReport +interface WorkReportPort : CommandWorkReportPort, QueryWorkReportPort -interface CommandWorkReport { +interface CommandWorkReportPort { fun saveWorkReport(workReport: WorkReport): WorkReport } -interface QueryWorkReport { +interface QueryWorkReportPort { 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/CreateWorkReportUseCase.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/usecase/CreateWorkReportUseCase.kt index 45e1f8c..4c7105a 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/usecase/CreateWorkReportUseCase.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/usecase/CreateWorkReportUseCase.kt @@ -5,24 +5,22 @@ import com.kodomo.juganbbojjak.common.spi.SecurityPort import com.kodomo.juganbbojjak.domain.work_report.dto.request.CreateWorkReportRequest import com.kodomo.juganbbojjak.domain.work_report.model.WorkDetail import com.kodomo.juganbbojjak.domain.work_report.model.WorkReport -import com.kodomo.juganbbojjak.domain.work_report.spi.QueryWeeklyWorkReportPort -import com.kodomo.juganbbojjak.domain.work_report.spi.WorkDetailPort -import com.kodomo.juganbbojjak.domain.work_report.spi.WorkReportPort +import com.kodomo.juganbbojjak.domain.work_report.spi.* import java.util.UUID @UseCase class CreateWorkReportUseCase( private val securityPort: SecurityPort, private val weeklyWorkReportPort: QueryWeeklyWorkReportPort, - private val workReportPort: WorkReportPort, - private val workDetailPort: WorkDetailPort + private val commandWorkReportPort: CommandWorkReportPort, + private val commandWorkDetailPort: CommandWorkDetailPort ) { fun execute(weeklyWorkReportId: UUID, request: CreateWorkReportRequest) { val user = securityPort.getCurrentUserId() val weeklyWorkReport = weeklyWorkReportPort.queryWeeklyWorkReportById(weeklyWorkReportId) - val workReport = workReportPort.saveWorkReport( + val workReport = commandWorkReportPort.saveWorkReport( WorkReport( title = request.title, weeklyWorkReportId = weeklyWorkReport.id, @@ -30,7 +28,7 @@ class CreateWorkReportUseCase( ) ) - workDetailPort.saveAllWorkDetails( + commandWorkDetailPort.saveAllWorkDetails( request.workReportList.map { WorkDetail( title = it.contentKey, 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 8bd68bf..b0bbd89 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 @@ -8,14 +8,13 @@ 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 com.kodomo.juganbbojjak.domain.work_report.spi.* import java.util.UUID @UseCase class QueryWorkReportDetailsUseCase( - private val workReportPort: WorkReportPort, - private val workDetailPort: WorkDetailPort, + private val queryWorkReportPort: QueryWorkReportPort, + private val queryWorkDetailPort: QueryWorkDetailPort, private val securityPort: SecurityPort, private val queryUserPort: QueryUserPort ) { @@ -26,11 +25,11 @@ class QueryWorkReportDetailsUseCase( ?: throw UserNotFoundException val workReport = when (user.authority) { - Authority.ADMIN -> workReportPort.queryWorkReportByWeeklyWorkReportId(weeklyWorkReportId, null) - Authority.USER -> workReportPort.queryWorkReportByWeeklyWorkReportId(weeklyWorkReportId, user.id) + Authority.ADMIN -> queryWorkReportPort.queryWorkReportByWeeklyWorkReportId(weeklyWorkReportId, null) + Authority.USER -> queryWorkReportPort.queryWorkReportByWeeklyWorkReportId(weeklyWorkReportId, user.id) } ?: throw WorkReportNotFoundException - val workDetail = workDetailPort.queryWorkDetailByWorkReportId(workReport.id) + val workDetail = queryWorkDetailPort.queryWorkDetailByWorkReportId(workReport.id) return QueryWorkReportDetailsResponse( title = workReport.title, diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/EvenSchedulePersistenceAdapter.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/EvenSchedulePersistenceAdapter.kt index bed7e21..096ab93 100644 --- a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/EvenSchedulePersistenceAdapter.kt +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/EvenSchedulePersistenceAdapter.kt @@ -56,4 +56,18 @@ class EvenSchedulePersistenceAdapter( if (userId != null) eventScheduleEntity.userEntity.id.eq(userId) else null + override fun queryAllEventScheduleList(): List { + val weeklyEventScheduleEntity = weeklyEventScheduleJpaRepository.findAllByOrderByEndDateDesc() + + return weeklyEventScheduleEntity.map { + WeeklyEventSchedule( + id = it.id, + startDate = it.startDate, + endDate = it.endDate + ) + } + } + + override fun queryLatestEventSchedule(): WeeklyEventSchedule? = + weeklyEventScheduleMapper.toDomain(weeklyEventScheduleJpaRepository.findTopByOrderByEndDateDesc()) } \ No newline at end of file diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/repository/WeeklyEventScheduleJpaRepository.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/repository/WeeklyEventScheduleJpaRepository.kt index 8e90500..40dd9ff 100644 --- a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/repository/WeeklyEventScheduleJpaRepository.kt +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/repository/WeeklyEventScheduleJpaRepository.kt @@ -5,4 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository import java.util.UUID interface WeeklyEventScheduleJpaRepository : JpaRepository { + fun findAllByOrderByEndDateDesc(): List + fun findTopByOrderByEndDateDesc(): WeeklyEventScheduleEntity? } \ No newline at end of file diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/presentation/UserWebAdapter.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/presentation/UserWebAdapter.kt new file mode 100644 index 0000000..8869611 --- /dev/null +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/user/presentation/UserWebAdapter.kt @@ -0,0 +1,28 @@ +package com.kodomo.juganbbojjak.domain.user.presentation + +import com.kodomo.juganbbojjak.domain.user.dto.response.QueryLatestWorkResponse +import com.kodomo.juganbbojjak.domain.user.dto.response.QueryWeeklyListResponse +import com.kodomo.juganbbojjak.domain.user.model.WeeklyListType +import com.kodomo.juganbbojjak.domain.user.usecase.QueryLatestWorkUseCase +import com.kodomo.juganbbojjak.domain.user.usecase.QueryWeeklyListUseCase +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.bind.annotation.RestController + +@RequestMapping("/main") +@RestController +class UserWebAdapter( + private val queryWeeklyListUseCase: QueryWeeklyListUseCase, + private val queryLatestWorkUseCase: QueryLatestWorkUseCase +) { + + @GetMapping + fun queryWeeklyList(@RequestParam("weekly-list-type") weeklyListType: WeeklyListType): QueryWeeklyListResponse = + queryWeeklyListUseCase.execute(weeklyListType) + + @GetMapping("/latest_work") + fun queryLatestWork(): QueryLatestWorkResponse = + queryLatestWorkUseCase.execute() + +} \ No newline at end of file diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/WeeklyWorkReportPersistenceAdapter.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/WeeklyWorkReportPersistenceAdapter.kt index eee7f39..4826330 100644 --- a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/WeeklyWorkReportPersistenceAdapter.kt +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/WeeklyWorkReportPersistenceAdapter.kt @@ -21,4 +21,21 @@ class WeeklyWorkReportPersistenceAdapter( ?: throw WeeklyWorkReportNotFoundException ) + override fun queryAllWeeklyWorkReportList(): List { + val weeklyWorkReportEntity = weeklyWorkReportRepository.findAllByOrderByEndDateDesc() + + return weeklyWorkReportEntity.map { + WeeklyWorkReport( + id = it.id, + startDate = it.startDate, + endDate = it.endDate + ) + } + } + + override fun queryLatestWeeklyWorkReport(): WeeklyWorkReport = + weeklyWorkReportMapper.toDomain( + weeklyWorkReportRepository.findTopByOrderByEndDateDesc() + ?: throw WeeklyWorkReportNotFoundException + ) } \ No newline at end of file diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/repository/WeeklyWorkReportRepository.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/repository/WeeklyWorkReportRepository.kt index 77cbcfe..8c75911 100644 --- a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/repository/WeeklyWorkReportRepository.kt +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/work_report/persistence/repository/WeeklyWorkReportRepository.kt @@ -5,4 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository import java.util.UUID interface WeeklyWorkReportRepository : JpaRepository { + fun findAllByOrderByEndDateDesc(): List + fun findTopByOrderByEndDateDesc(): WeeklyWorkReportEntity? } \ No newline at end of file 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 238adbd..c41c3a2 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 @@ -37,6 +37,9 @@ class SecurityConfig( .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) + .requestMatchers(HttpMethod.GET, "/main").hasAnyAuthority(USER.name, ADMIN.name) + .requestMatchers(HttpMethod.GET, "/main/latest_work").hasAuthority(USER.name) + .anyRequest().permitAll() } .apply(FilterConfig(jwtTokenParser, objectMapper))