Skip to content

Commit

Permalink
refactor :: exception
Browse files Browse the repository at this point in the history
  • Loading branch information
jyk1029 committed Jan 24, 2024
1 parent 2947880 commit dccb88f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit dccb88f

Please sign in to comment.