Skip to content

Commit

Permalink
Merge branch 'main' into feat/user-query-event-schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
geunoo authored Dec 12, 2023
2 parents 31569c8 + 297ea33 commit 2b6ac3a
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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<WorkReportListResponse>
)

data class WorkReportListResponse(
val contentKey: String,
val contentValue: String,
val contentType: WorkDetailType
)
Original file line number Diff line number Diff line change
@@ -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<WorkDetail>)
}

interface QueryWorkDetailPort{
fun queryWorkDetailByWorkReportId(workReportId: UUID): List<WorkDetail>
}
Original file line number Diff line number Diff line change
@@ -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?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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.exception.WorkReportNotFoundException
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)
} ?: throw WorkReportNotFoundException

val workDetail = workDetailPort.queryWorkDetailByWorkReportId(workReport.id)

return QueryWorkReportDetailsResponse(
title = workReport.title,
workReportList = workDetail.map {
WorkReportListResponse(
contentKey = it.title,
contentValue = it.content,
contentType = it.type
)
}
)
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
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<WorkDetail>) {
workDetailRepository.saveAll(
workDetails.map { workDetailMapper.toEntity(it) }
)
}

override fun queryWorkDetailByWorkReportId(workReportId: UUID): List<WorkDetail> {
return queryFactory
.selectFrom(workDetailEntity)
.join(workReportEntity)
.on(workDetailEntity.workReportEntity.id.eq(workReportEntity.id))
.where(workDetailEntity.workReportEntity.id.eq(workReportId))
.fetch()
.map { workDetailMapper.toDomain(it) }
}
}
Original file line number Diff line number Diff line change
@@ -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 =
Expand All @@ -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

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository
import java.util.UUID

interface WorkReportRepository : JpaRepository<WorkReportEntity, UUID> {
fun findByWeeklyWorkReportEntityId(weeklyWorkReportId: UUID): WorkReportEntity
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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)

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SecurityConfig(
.requestMatchers(HttpMethod.GET, "/event_schedules/{weekly-event-schedule-id}").hasAnyAuthority(ADMIN.name, USER.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()
}
Expand Down

0 comments on commit 2b6ac3a

Please sign in to comment.