diff --git a/src/main/kotlin/com/example/boheom/domain/feed/exception/ImpossibleApplicationException.kt b/src/main/kotlin/com/example/boheom/domain/feed/exception/ImpossibleApplicationException.kt new file mode 100644 index 0000000..1acb09f --- /dev/null +++ b/src/main/kotlin/com/example/boheom/domain/feed/exception/ImpossibleApplicationException.kt @@ -0,0 +1,6 @@ +package com.example.boheom.domain.feed.exception + +import com.example.boheom.global.error.exception.BoheomException +import com.example.boheom.global.error.exception.ErrorCode.IMPOSSIBLE_APPLICATION + +object ImpossibleApplicationException: BoheomException(IMPOSSIBLE_APPLICATION) \ No newline at end of file diff --git a/src/main/kotlin/com/example/boheom/domain/feed/service/FeedApplyService.kt b/src/main/kotlin/com/example/boheom/domain/feed/service/FeedApplyService.kt index b14c90e..a3c7068 100644 --- a/src/main/kotlin/com/example/boheom/domain/feed/service/FeedApplyService.kt +++ b/src/main/kotlin/com/example/boheom/domain/feed/service/FeedApplyService.kt @@ -1,10 +1,13 @@ package com.example.boheom.domain.feed.service import com.example.boheom.domain.feed.domain.Apply +import com.example.boheom.domain.feed.domain.Feed import com.example.boheom.domain.feed.domain.repository.ApplyRepository import com.example.boheom.domain.feed.exception.AlreadyApplyException +import com.example.boheom.domain.feed.exception.ImpossibleApplicationException import com.example.boheom.domain.feed.exception.NotAllowSelfApplicationException import com.example.boheom.domain.feed.facade.FeedFacade +import com.example.boheom.domain.user.domain.User import com.example.boheom.domain.user.facade.UserFacade import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -20,12 +23,20 @@ class FeedApplyService( fun execute(feedId: UUID) { val user = userFacade.getCurrentUser() val feed = feedFacade.getByFeedId(feedId) + validateApply(feed, user) + applyRepository.save(Apply(user, feed)) + } + fun validateApply(feed: Feed, user: User) { + val applyCount = applyRepository.countByFeed(feed) + if (user.equals(feed.user)) { throw NotAllowSelfApplicationException } if (applyRepository.existsByUserAndFeed(user, feed)) { throw AlreadyApplyException } - applyRepository.save(Apply(user, feed)) + if (feed.recruitment.equals(applyCount)) { + throw ImpossibleApplicationException + } } } \ No newline at end of file diff --git a/src/main/kotlin/com/example/boheom/global/error/exception/ErrorCode.kt b/src/main/kotlin/com/example/boheom/global/error/exception/ErrorCode.kt index d387045..10d9265 100644 --- a/src/main/kotlin/com/example/boheom/global/error/exception/ErrorCode.kt +++ b/src/main/kotlin/com/example/boheom/global/error/exception/ErrorCode.kt @@ -9,6 +9,7 @@ enum class ErrorCode( INCORRECT_USER(400, "Incorrect User"), NOT_ALLOW_SELF_APPLICATION(400, "Not Allow Self Application"), BAD_FILE_EXTENSION(400, "Bad File Extension"), + IMPOSSIBLE_APPLICATION(400, "Impossible Application"), TOKEN_INVALID(401, "Token Invalid"), TOKEN_EXPIRED(401, "Token Expired"),