Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat :: (#22) 주간 업무 보고 수정 api #27

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.kodomo.juganbbojjak.domain.work_report.dto.request

import java.util.UUID

data class UpdateWorkReportRequest(
val workReportId: UUID,
val title: String,
val workReportDetails: List<UpdateWorkReportDetailsRequest>
)

data class UpdateWorkReportDetailsRequest(
val workDetailId: UUID,
val contentKey: String,
val contentValue: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.kodomo.juganbbojjak.domain.work_report.exception

import com.kodomo.juganbbojjak.common.error.JuGanBbojjakException
import com.kodomo.juganbbojjak.domain.work_report.exception.error.WorkReportErrorCode

object WorkDetailNotFoundException : JuGanBbojjakException(
WorkReportErrorCode.WORK_DETAIL_NOT_FOUND
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ enum class WorkReportErrorCode(
) : ErrorProperty {

WEEKLY_WORK_REPORT_NOT_FOUND(404, "Weekly Work Report Not Found"),
WORK_REPORT_NOT_FOUND(404, "Work Report Not Found")
WORK_REPORT_NOT_FOUND(404, "Work Report Not Found"),
WORK_DETAIL_NOT_FOUND(404, "Work Detail Not Found")
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.kodomo.juganbbojjak.domain.work_report.model

import com.kodomo.juganbbojjak.common.annotation.Aggregate
import com.kodomo.juganbbojjak.domain.work_report.dto.request.UpdateWorkReportDetailsRequest
import java.util.UUID

@Aggregate
class WorkDetail(
data class WorkDetail(

val id: UUID = UUID.randomUUID(),

Expand All @@ -15,4 +16,14 @@ class WorkDetail(
val type: WorkDetailType,

val workReportId: UUID
)
) {

fun updateWorkDetail(updateWorkReportDetails: UpdateWorkReportDetailsRequest): WorkDetail =
WorkDetail(
id = id,
title = updateWorkReportDetails.contentKey,
content = updateWorkReportDetails.contentValue,
workReportId = workReportId,
type = type
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.kodomo.juganbbojjak.common.annotation.Aggregate
import java.util.UUID

@Aggregate
class WorkReport (
data class WorkReport(

val id: UUID = UUID.randomUUID(),

Expand All @@ -13,4 +13,9 @@ class WorkReport (
val weeklyWorkReportId: UUID,

val userId: UUID
)
) {

fun updateWorkReport(title: String) = this.copy(
title = title
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ interface WorkDetailPort : CommandWorkDetailPort, QueryWorkDetailPort

interface CommandWorkDetailPort{
fun saveAllWorkDetails(workDetails: List<WorkDetail>)
fun saveWorkDetail(workDetail: WorkDetail)
}

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

interface QueryWorkReportPort {

fun queryWorkReportById(workReportId: UUID): WorkReport
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.kodomo.juganbbojjak.domain.work_report.usecase

import com.kodomo.juganbbojjak.common.annotation.UseCase
import com.kodomo.juganbbojjak.domain.work_report.dto.request.UpdateWorkReportRequest
import com.kodomo.juganbbojjak.domain.work_report.spi.CommandWorkDetailPort
import com.kodomo.juganbbojjak.domain.work_report.spi.CommandWorkReportPort
import com.kodomo.juganbbojjak.domain.work_report.spi.QueryWorkDetailPort
import com.kodomo.juganbbojjak.domain.work_report.spi.QueryWorkReportPort

@UseCase
class UpdateWorkReportUseCase(
private val queryWorkReportPort: QueryWorkReportPort,
private val commandWorkReportPort: CommandWorkReportPort,
private val queryWorkDetailPort: QueryWorkDetailPort,
private val commandWorkDetailPort: CommandWorkDetailPort
) {

fun execute(request: UpdateWorkReportRequest) {
val workReportEntity = queryWorkReportPort.queryWorkReportById(request.workReportId)

commandWorkReportPort.saveWorkReport(workReportEntity.updateWorkReport(request.title))

request.workReportDetails.forEach { workReportDetails ->
val workDetailList =
queryWorkDetailPort.queryWorkDetailById(workReportDetails.workDetailId)

commandWorkDetailPort.saveWorkDetail(
workDetailList.updateWorkDetail(workReportDetails)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kodomo.juganbbojjak.domain.work_report.persistence

import com.kodomo.juganbbojjak.domain.work_report.exception.WorkDetailNotFoundException
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
Expand All @@ -9,11 +10,11 @@ import com.kodomo.juganbbojjak.domain.work_report.persistence.vo.QQueryWorkRepor
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 org.springframework.data.repository.findByIdOrNull
import java.util.*

@Adapter
Expand Down Expand Up @@ -57,5 +58,17 @@ class WorkDetailPersistenceAdapter(
workReportEntity.userEntity.id.eq(userId)
else null

override fun queryWorkDetailById(workDetailIdList: UUID): WorkDetail {
return workDetailMapper.toDomain(
workDetailRepository.findByIdOrNull(workDetailIdList)
?: throw WorkDetailNotFoundException
)

}

override fun saveWorkDetail(workDetail: WorkDetail) {
workDetailRepository.save(
workDetailMapper.toEntity(workDetail)
)
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package com.kodomo.juganbbojjak.domain.work_report.persistence

import com.kodomo.juganbbojjak.domain.work_report.exception.WorkReportNotFoundException
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 org.springframework.data.repository.findByIdOrNull
import java.util.*
import kotlin.collections.List

@Adapter
class WorkReportPersistenceAdapter(
private val workReportRepository: WorkReportRepository,
private val workReportMapper: WorkReportMapper,
private val queryFactory: JPAQueryFactory
) : WorkReportPort {

override fun saveWorkReport(workReport: WorkReport): WorkReport =
Expand All @@ -27,4 +22,10 @@ class WorkReportPersistenceAdapter(
)
)

override fun queryWorkReportById(workReportId: UUID): WorkReport =
workReportMapper.toDomain(
workReportRepository.findByIdOrNull(workReportId)
?: throw WorkReportNotFoundException
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +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
Expand Up @@ -2,13 +2,16 @@ package com.kodomo.juganbbojjak.domain.work_report.presentation

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.presentation.dto.UpdateWorkReportWebRequest
import com.kodomo.juganbbojjak.domain.work_report.usecase.CreateWorkReportUseCase
import com.kodomo.juganbbojjak.domain.work_report.usecase.QueryWorkReportDetailsUseCase
import com.kodomo.juganbbojjak.domain.work_report.usecase.UpdateWorkReportUseCase
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.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseStatus
Expand All @@ -19,7 +22,8 @@ import java.util.UUID
@RestController
class WorkReportWebAdapter(
private val createWorkReportUseCase: CreateWorkReportUseCase,
private val queryWorkReportDetailsUseCase: QueryWorkReportDetailsUseCase
private val queryWorkReportDetailsUseCase: QueryWorkReportDetailsUseCase,
private val updateWorkReportUseCase: UpdateWorkReportUseCase
) {

@ResponseStatus(HttpStatus.CREATED)
Expand All @@ -35,4 +39,10 @@ class WorkReportWebAdapter(
fun queryWorkDetails(@PathVariable("weekly-work-report-id") weeklyWorkReportId: UUID): QueryWorkReportDetailsResponse =
queryWorkReportDetailsUseCase.execute(weeklyWorkReportId)

@ResponseStatus(HttpStatus.NO_CONTENT)
@PutMapping
fun updateWorkReport(@RequestBody request: UpdateWorkReportWebRequest) {
updateWorkReportUseCase.execute(request.toDomainRequest())
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.kodomo.juganbbojjak.domain.work_report.presentation.dto

import com.kodomo.juganbbojjak.domain.work_report.dto.request.UpdateWorkReportDetailsRequest
import com.kodomo.juganbbojjak.domain.work_report.dto.request.UpdateWorkReportRequest
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull
import java.util.*

data class UpdateWorkReportWebRequest(

@NotBlank
val workReportId: UUID,

@NotBlank
val title: String,

val workReportDetails: List<@NotNull UpdateWorkReportDetailsWebRequest>
) {
fun toDomainRequest() = UpdateWorkReportRequest(
workReportId = workReportId,
title = title,
workReportDetails = workReportDetails.map {
UpdateWorkReportDetailsRequest(
workDetailId = it.workDetailId,
contentKey = it.contentKey,
contentValue = it.contentValue
)
}
)
}

data class UpdateWorkReportDetailsWebRequest(

@NotBlank
val workDetailId: UUID,

@NotBlank
val contentKey: String,

@NotBlank
val contentValue: String
)
Loading