diff --git a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/applicationservice/GoalApplicationService.kt b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/applicationservice/GoalApplicationService.kt index a0e0f52..16923ce 100644 --- a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/applicationservice/GoalApplicationService.kt +++ b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/applicationservice/GoalApplicationService.kt @@ -38,6 +38,10 @@ class GoalApplicationService( exceptionCode = ExceptionCode.E409_CONFLICT, executionMessage = "다짐을 생성하는 중, 생성할 수 있는 다짐 갯수를 초과하였습니다." ) + if (goalService.existsByUserIdAndAnyResult(userId, Result.PROCEEDING)) throw BaseException.of( + exceptionCode = ExceptionCode.E409_CONFLICT, + executionMessage = "다짐을 생성하는 중, 이미 생성한 다짐이 있어 생성이 불가합니다." + ) val goal = goalService.create( userId = userId, content = content, diff --git a/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/goal/GoalRepository.kt b/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/goal/GoalRepository.kt index 90cd43c..1a97a17 100644 --- a/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/goal/GoalRepository.kt +++ b/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/goal/GoalRepository.kt @@ -12,4 +12,6 @@ interface GoalRepository : JpaRepository { fun findByIdAndUserEntity(id: Long, userEntity: UserEntity): GoalEntity? fun findAllByEndDateLessThanEqualAndResultIs(endDate: LocalDateTime, result: Result): List + + fun findAllByUserEntityAndResult(userEntity: UserEntity, result: Result): List } \ No newline at end of file diff --git a/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/goal/GoalService.kt b/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/goal/GoalService.kt index 9bd6f4c..33ff88c 100644 --- a/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/goal/GoalService.kt +++ b/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/goal/GoalService.kt @@ -42,6 +42,12 @@ class GoalService( ?: throw IllegalArgumentException("다짐을 조회하는 중, 잘못된 내용을 요청하셨습니다.") } + fun existsByUserIdAndAnyResult(userId: Long, result: Result): Boolean { + val userEntity = userRepository.findByIdOrNull(userId) + ?: throw IllegalArgumentException("cannot find user $userId") + return goalRepository.findAllByUserEntityAndResult(userEntity, result).isNotEmpty() + } + fun loadAllByUserId(userId: Long): List { return goalRepository.findAllByUserEntity( userRepository.findById(userId).get()