Skip to content

Commit

Permalink
feat :: (#20) 메인페이지 조회 api
Browse files Browse the repository at this point in the history
feat :: (#20) 메인페이지 조회 api
  • Loading branch information
Woonseok105 authored Dec 13, 2023
2 parents c8155ff + 161b3c8 commit 298aaea
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ interface EventSchedulePort : QueryEventSchedulePort, CommandEventSchedulePort {
interface QueryEventSchedulePort {
fun queryWeeklyEventScheduleById(weeklyEventScheduleId: UUID): WeeklyEventSchedule?
fun queryEventSchedulesByWeeklyEventScheduleId(weeklyEventScheduleId: UUID, userId: UUID?): List<EventSchedule>
fun queryAllEventScheduleList(): List<WeeklyEventSchedule>
fun queryLatestEventSchedule(): WeeklyEventSchedule?
}

interface CommandEventSchedulePort {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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<WeeklyList>
)

data class WeeklyList(
val id: UUID,
val startDate: LocalDate,
val endDate: LocalDate,
val type: WeeklyListType
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.kodomo.juganbbojjak.domain.user.model

enum class WeeklyListType {
WORK_REPORT, EVENT_SCHEDULE
}
Original file line number Diff line number Diff line change
@@ -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
)
}
}
Original file line number Diff line number Diff line change
@@ -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
)
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ interface CommandWeeklyWorkReportPort {

interface QueryWeeklyWorkReportPort {
fun queryWeeklyWorkReportById(weeklyWorkReportId: UUID): WeeklyWorkReport
fun queryAllWeeklyWorkReportList(): List<WeeklyWorkReport>
fun queryLatestWeeklyWorkReport(): WeeklyWorkReport
}
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,30 @@ 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,
userId = user
)
)

workDetailPort.saveAllWorkDetails(
commandWorkDetailPort.saveAllWorkDetails(
request.workReportList.map {
WorkDetail(
title = it.contentKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,18 @@ class EvenSchedulePersistenceAdapter(
if (userId != null)
eventScheduleEntity.userEntity.id.eq(userId)
else null
override fun queryAllEventScheduleList(): List<WeeklyEventSchedule> {
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())
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository
import java.util.UUID

interface WeeklyEventScheduleJpaRepository : JpaRepository<WeeklyEventScheduleEntity, UUID> {
fun findAllByOrderByEndDateDesc(): List<WeeklyEventScheduleEntity>
fun findTopByOrderByEndDateDesc(): WeeklyEventScheduleEntity?
}
Original file line number Diff line number Diff line change
@@ -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()

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,21 @@ class WeeklyWorkReportPersistenceAdapter(
?: throw WeeklyWorkReportNotFoundException
)

override fun queryAllWeeklyWorkReportList(): List<WeeklyWorkReport> {
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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository
import java.util.UUID

interface WeeklyWorkReportRepository : JpaRepository<WeeklyWorkReportEntity, UUID> {
fun findAllByOrderByEndDateDesc(): List<WeeklyWorkReportEntity>
fun findTopByOrderByEndDateDesc(): WeeklyWorkReportEntity?
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 298aaea

Please sign in to comment.