From 0b43eb52b7ae58253f8c4614622f04d35c8ddb6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=B1=84?= <103401813+alsco39@users.noreply.github.com> Date: Wed, 17 Jan 2024 10:51:02 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=80=20::=20(#255)=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=20API=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#124)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ♻️ :: 메소드명 변경 및 타입이 있을 시 타입 수정으로 변경 * ♻️ :: 메소드명 변경 * ♻️ :: 사용하지 않는 메소드 제거 * ♻️ :: let함수로 변경 * ♻️ :: klint 해결 * ♻️ :: ktlint 해결 * ♻️ :: ktlint 해결 * ♻️ :: 줄바꿈 제거 * ♻️ :: ktlint 해결 --- .../domain/admin/api/AdminApi.kt | 7 +++--- .../domain/admin/usecase/AdminUseCase.kt | 23 +++++++++++-------- .../domain/selfstudydirector/Type.kt | 3 +-- .../common/error/ErrorResponse.kt | 1 - .../common/error/GlobalErrorCode.kt | 2 -- .../admin/presentation/AdminWebAdapter.kt | 14 +---------- .../persistence/entity/ApplicationEntity.kt | 2 +- 7 files changed, 20 insertions(+), 32 deletions(-) diff --git a/pick-application/src/main/kotlin/com/pickdsm/pickserverspring/domain/admin/api/AdminApi.kt b/pick-application/src/main/kotlin/com/pickdsm/pickserverspring/domain/admin/api/AdminApi.kt index 96fede19..e6208d25 100644 --- a/pick-application/src/main/kotlin/com/pickdsm/pickserverspring/domain/admin/api/AdminApi.kt +++ b/pick-application/src/main/kotlin/com/pickdsm/pickserverspring/domain/admin/api/AdminApi.kt @@ -18,7 +18,8 @@ interface AdminApi { fun getStudentStatusListByGradeAndClassNum(grade: Int?, classNum: Int?): QueryStudentListByGradeAndClassNum - fun saveType(date: LocalDate, type: DirectorType) - - fun updateType(date: LocalDate, type: DirectorType) + fun saveOrUpdateType( + date: LocalDate, + type: DirectorType, + ) } diff --git a/pick-application/src/main/kotlin/com/pickdsm/pickserverspring/domain/admin/usecase/AdminUseCase.kt b/pick-application/src/main/kotlin/com/pickdsm/pickserverspring/domain/admin/usecase/AdminUseCase.kt index c39daf74..07add80d 100644 --- a/pick-application/src/main/kotlin/com/pickdsm/pickserverspring/domain/admin/usecase/AdminUseCase.kt +++ b/pick-application/src/main/kotlin/com/pickdsm/pickserverspring/domain/admin/usecase/AdminUseCase.kt @@ -272,20 +272,23 @@ class AdminUseCase( status.studentId == userId && status.startPeriod <= statusPeriod && status.endPeriod >= statusPeriod }?.type ?: StatusType.ATTENDANCE - override fun saveType(date: LocalDate, type: DirectorType) { - commandTypeSpi.saveType( + override fun saveOrUpdateType( + date: LocalDate, + type: DirectorType, + ) { + val existType = queryTypeSpi.queryTypeByDate(date) + + existType?.let { + commandTypeSpi.saveType( + it.changeType( + type, + ), + ) + } ?: commandTypeSpi.saveType( Type( date = date, type = type, ), ) } - - override fun updateType(date: LocalDate, type: DirectorType) { - val currentType = queryTypeSpi.queryTypeByDate(date) - ?: throw TypeNotFoundException - commandTypeSpi.saveType( - currentType.changeType(date, type), - ) - } } diff --git a/pick-application/src/main/kotlin/com/pickdsm/pickserverspring/domain/selfstudydirector/Type.kt b/pick-application/src/main/kotlin/com/pickdsm/pickserverspring/domain/selfstudydirector/Type.kt index 8550ed11..120a0e31 100644 --- a/pick-application/src/main/kotlin/com/pickdsm/pickserverspring/domain/selfstudydirector/Type.kt +++ b/pick-application/src/main/kotlin/com/pickdsm/pickserverspring/domain/selfstudydirector/Type.kt @@ -13,9 +13,8 @@ data class Type( val type: DirectorType, ) { - fun changeType(date: LocalDate, type: DirectorType): Type { + fun changeType(type: DirectorType): Type { return copy( - date = date, type = type, ) } diff --git a/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/common/error/ErrorResponse.kt b/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/common/error/ErrorResponse.kt index d88d0e99..e9b31e9e 100644 --- a/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/common/error/ErrorResponse.kt +++ b/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/common/error/ErrorResponse.kt @@ -1,6 +1,5 @@ package com.pickdsm.pickserverspring.common.error -import com.pickdsm.pickserverspring.common.error.ErrorProperty import org.springframework.dao.DataIntegrityViolationException import org.springframework.validation.BindingResult import org.springframework.validation.FieldError diff --git a/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/common/error/GlobalErrorCode.kt b/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/common/error/GlobalErrorCode.kt index 3f417f7e..a4160903 100644 --- a/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/common/error/GlobalErrorCode.kt +++ b/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/common/error/GlobalErrorCode.kt @@ -1,7 +1,5 @@ package com.pickdsm.pickserverspring.common.error -import com.pickdsm.pickserverspring.common.error.ErrorProperty - enum class GlobalErrorCode( private val status: Int, private val message: String diff --git a/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/domain/admin/presentation/AdminWebAdapter.kt b/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/domain/admin/presentation/AdminWebAdapter.kt index f7f58456..c35d83fe 100644 --- a/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/domain/admin/presentation/AdminWebAdapter.kt +++ b/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/domain/admin/presentation/AdminWebAdapter.kt @@ -256,19 +256,7 @@ class AdminWebAdapter( @RequestParam type: DirectorType, ) { - adminApi.saveType(date, type) - } - - @ResponseStatus(HttpStatus.NO_CONTENT) - @PatchMapping("/type") - fun updateType( - @RequestParam - @DateTimeFormat(pattern = "yyyy-MM-dd") - date: LocalDate, - @RequestParam - type: DirectorType, - ) { - adminApi.updateType(date, type) + adminApi.saveOrUpdateType(date, type) } @PostMapping("/director") diff --git a/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/domain/application/persistence/entity/ApplicationEntity.kt b/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/domain/application/persistence/entity/ApplicationEntity.kt index 419a8fc4..c10323be 100644 --- a/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/domain/application/persistence/entity/ApplicationEntity.kt +++ b/pick-infrastructure/src/main/kotlin/com/pickdsm/pickserverspring/domain/application/persistence/entity/ApplicationEntity.kt @@ -28,4 +28,4 @@ class ApplicationEntity( @ColumnDefault("false") val isReturn: Boolean, - ) : BaseUUIDEntity(id) +) : BaseUUIDEntity(id)