Skip to content

Commit

Permalink
fix :: 코드 수정
Browse files Browse the repository at this point in the history
fix :: 코드 수정
  • Loading branch information
Woonseok105 authored Dec 14, 2023
2 parents 8b17680 + d99fd2a commit 512542b
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ package com.kodomo.juganbbojjak.domain.work_report.dto.request
import com.kodomo.juganbbojjak.domain.work_report.model.WorkDetailType

data class CreateWorkReportRequest(
val title: String,
val workReportList: List<WorkReportList>
)

data class WorkReportList(
val title: String,
val workReportDetails: List<WorkReportDetails>
)

data class WorkReportDetails(
val contentKey: String,
val contentValue: String,
val contentType: WorkDetailType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.kodomo.juganbbojjak.domain.work_report.dto.reponse
package com.kodomo.juganbbojjak.domain.work_report.dto.response

import com.kodomo.juganbbojjak.domain.work_report.model.WorkDetailType
import java.util.UUID

data class QueryWorkReportDetailsResponse(
val title: String,
val workReportList: List<WorkReportListResponse>
)

data class WorkReportListResponse(
val workReportId: UUID,
val title: String,
val workReportDetails: List<WorkReportDetailsResponse>
)
data class WorkReportDetailsResponse(
val workDetailId: UUID,
val contentKey: String,
val contentValue: String,
val contentType: WorkDetailType
)
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kodomo.juganbbojjak.domain.work_report.spi

import com.kodomo.juganbbojjak.domain.work_report.model.WorkDetail
import com.kodomo.juganbbojjak.domain.work_report.spi.vo.WorkReportDetailsVO
import java.util.UUID

interface WorkDetailPort : CommandWorkDetailPort, QueryWorkDetailPort
Expand All @@ -10,5 +11,5 @@ interface CommandWorkDetailPort{
}

interface QueryWorkDetailPort{
fun queryWorkDetailByWorkReportId(workReportId: UUID): List<WorkDetail>
fun queryWorkDetailByWeeklyWorkReportId(weeklyWorkReportId: UUID, userId: UUID?): List<WorkReportDetailsVO>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ interface CommandWorkReportPort {
}

interface QueryWorkReportPort {
fun queryWorkReportByWeeklyWorkReportId(weeklyWorkReportId: UUID, userId: UUID?): WorkReport?

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.kodomo.juganbbojjak.domain.work_report.spi.vo

import com.kodomo.juganbbojjak.domain.work_report.model.WorkDetail
import java.util.*

open class WorkReportDetailsVO (
val workReportId: UUID,
val title: String,
val workDetailsList: List<WorkDetail>
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@ class CreateWorkReportUseCase(
val user = securityPort.getCurrentUserId()
val weeklyWorkReport = weeklyWorkReportPort.queryWeeklyWorkReportById(weeklyWorkReportId)

val workReport = commandWorkReportPort.saveWorkReport(
WorkReport(
title = request.title,
weeklyWorkReportId = weeklyWorkReport.id,
userId = user
request.workReportList.forEach { workReportList ->
val workReport = commandWorkReportPort.saveWorkReport(
WorkReport(
title = workReportList.title,
weeklyWorkReportId = weeklyWorkReport.id,
userId = user
)
)
)

commandWorkDetailPort.saveAllWorkDetails(
request.workReportList.map {
val workDetails = workReportList.workReportDetails.map { detail ->
WorkDetail(
title = it.contentKey,
content = it.contentValue,
type = it.contentType,
title = detail.contentKey,
content = detail.contentValue,
type = detail.contentType,
workReportId = workReport.id
)
}
)
commandWorkDetailPort.saveAllWorkDetails(workDetails)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ 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.dto.response.QueryWorkReportDetailsResponse
import com.kodomo.juganbbojjak.domain.work_report.dto.response.WorkReportDetailsResponse
import com.kodomo.juganbbojjak.domain.work_report.dto.response.WorkReportListResponse
import com.kodomo.juganbbojjak.domain.work_report.spi.*
import java.util.UUID

@UseCase
class QueryWorkReportDetailsUseCase(
private val queryWorkReportPort: QueryWorkReportPort,
private val queryWorkDetailPort: QueryWorkDetailPort,
private val securityPort: SecurityPort,
private val queryUserPort: QueryUserPort
Expand All @@ -24,20 +23,24 @@ class QueryWorkReportDetailsUseCase(
val user = queryUserPort.queryUserById(securityPort.getCurrentUserId())
?: throw UserNotFoundException

val workReport = when (user.authority) {
Authority.ADMIN -> queryWorkReportPort.queryWorkReportByWeeklyWorkReportId(weeklyWorkReportId, null)
Authority.USER -> queryWorkReportPort.queryWorkReportByWeeklyWorkReportId(weeklyWorkReportId, user.id)
} ?: throw WorkReportNotFoundException

val workDetail = queryWorkDetailPort.queryWorkDetailByWorkReportId(workReport.id)
val workReportList = when (user.authority) {
Authority.ADMIN -> queryWorkDetailPort.queryWorkDetailByWeeklyWorkReportId(weeklyWorkReportId, null)
Authority.USER -> queryWorkDetailPort.queryWorkDetailByWeeklyWorkReportId(weeklyWorkReportId, user.id)
}

return QueryWorkReportDetailsResponse(
title = workReport.title,
workReportList = workDetail.map {
workReportList = workReportList.map { workReport ->
WorkReportListResponse(
contentKey = it.title,
contentValue = it.content,
contentType = it.type
workReportId = workReport.workReportId,
title = workReport.title,
workReportDetails = workReport.workDetailsList.map { workDetail ->
WorkReportDetailsResponse(
workDetailId = workDetail.id,
contentKey = workDetail.title,
contentValue = workDetail.content,
contentType = workDetail.type
)
}
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ import com.kodomo.juganbbojjak.domain.work_report.persistence.entity.QWorkDetail
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.persistence.vo.QQueryWorkReportDetailsVO
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 java.util.*

Expand All @@ -23,13 +29,33 @@ class WorkDetailPersistenceAdapter(
)
}

override fun queryWorkDetailByWorkReportId(workReportId: UUID): List<WorkDetail> {
return queryFactory
.selectFrom(workDetailEntity)
.join(workReportEntity)
override fun queryWorkDetailByWeeklyWorkReportId(
weeklyWorkReportId: UUID,
userId: UUID?
): List<WorkReportDetailsVO> =
queryFactory
.selectFrom(workReportEntity)
.leftJoin(workDetailEntity)
.on(workDetailEntity.workReportEntity.id.eq(workReportEntity.id))
.where(workDetailEntity.workReportEntity.id.eq(workReportId))
.fetch()
.map { workDetailMapper.toDomain(it) }
}
.where(
workReportEntity.weeklyWorkReportEntity.id.eq(weeklyWorkReportId),
eqUserId(userId)
)
.transform(
groupBy(workReportEntity.id)
.list(
QQueryWorkReportDetailsVO(
workReportEntity.id,
workReportEntity.title,
list(workDetailEntity)
)
)
)

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 @@ -4,11 +4,14 @@ 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 java.util.*
import kotlin.collections.List

@Adapter
class WorkReportPersistenceAdapter(
Expand All @@ -24,28 +27,4 @@ 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
@@ -0,0 +1,25 @@
package com.kodomo.juganbbojjak.domain.work_report.persistence.vo

import com.kodomo.juganbbojjak.domain.work_report.model.WorkDetail
import com.kodomo.juganbbojjak.domain.work_report.persistence.entity.WorkDetailEntity
import com.kodomo.juganbbojjak.domain.work_report.spi.vo.WorkReportDetailsVO
import com.querydsl.core.annotations.QueryProjection
import java.util.*

class QueryWorkReportDetailsVO @QueryProjection constructor(
workReportId: UUID,
title: String,
workDetailsList: List<WorkDetailEntity>
) : WorkReportDetailsVO(
workReportId = workReportId,
title = title,
workDetailsList = workDetailsList.map {
WorkDetail(
id = it.id,
title = it.title,
content = it.content,
type = it.type,
workReportId = it.workReportEntity.id
)
}
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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.dto.response.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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
package com.kodomo.juganbbojjak.domain.work_report.presentation.dto

import com.kodomo.juganbbojjak.domain.work_report.dto.request.CreateWorkReportRequest
import com.kodomo.juganbbojjak.domain.work_report.dto.request.WorkReportDetails
import com.kodomo.juganbbojjak.domain.work_report.dto.request.WorkReportList
import com.kodomo.juganbbojjak.domain.work_report.model.WorkDetailType
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull

data class CreateWorkReportWebRequest(

@field:NotBlank
val title: String,

val workReportList: List<@NotNull WorkReportListWebRequest>
) {
fun toDomainRequest() = CreateWorkReportRequest(
title = title,
workReportList = workReportList.map {
WorkReportList(
contentKey = it.contentKey,
contentValue = it.contentValue,
contentType = it.contentType
title = it.title,
workReportDetails = it.workReportDetails.map { detail ->
WorkReportDetails(
contentKey = detail.contentKey,
contentValue = detail.contentValue,
contentType = detail.contentType
)
}
)
}
)
}

data class WorkReportListWebRequest(

@field:NotBlank
val title: String,

val workReportDetails: List<@NotNull WorkReportDetailsWebRequest>
)

data class WorkReportDetailsWebRequest(
@field:NotBlank
val contentKey: String,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kodomo.juganbbojjak.global.querydsl

import com.querydsl.jpa.JPQLTemplates
import com.querydsl.jpa.impl.JPAQueryFactory
import jakarta.persistence.EntityManager
import org.springframework.context.annotation.Bean
Expand All @@ -11,5 +12,5 @@ class QuerydslConfig(
) {

@Bean
fun queryFactory() = JPAQueryFactory(entityManager)
fun queryFactory() = JPAQueryFactory(JPQLTemplates.DEFAULT, entityManager)
}

0 comments on commit 512542b

Please sign in to comment.