diff --git a/src/main/java/com/tune_fun/v1/account/adapter/input/rest/LogoutController.java b/src/main/java/com/tune_fun/v1/account/adapter/input/rest/LogoutController.java index 87094492..5e2df4ec 100644 --- a/src/main/java/com/tune_fun/v1/account/adapter/input/rest/LogoutController.java +++ b/src/main/java/com/tune_fun/v1/account/adapter/input/rest/LogoutController.java @@ -33,7 +33,7 @@ public class LogoutController { public ResponseEntity> logout(final HttpServletRequest request, @Valid @RequestBody final AccountCommands.Device device, @CurrentUser final User user) { String authorizationValue = Optional.ofNullable(request.getHeader(AUTHORIZATION)) - .orElseThrow(() -> new CommonApplicationException(EXCEPTION_AUTHENTICATION_TOKEN_NOT_FOUND)); + .orElseThrow(CommonApplicationException.EXCEPTION_AUTHENTICATION_TOKEN_NOT_FOUND); String accessToken = StringUtil.removeBearerPrefix(authorizationValue); logoutUseCase.logout(accessToken, device, user); diff --git a/src/main/java/com/tune_fun/v1/account/adapter/input/security/JwtAuthenticationFilter.java b/src/main/java/com/tune_fun/v1/account/adapter/input/security/JwtAuthenticationFilter.java index d61c790d..9c102ed2 100644 --- a/src/main/java/com/tune_fun/v1/account/adapter/input/security/JwtAuthenticationFilter.java +++ b/src/main/java/com/tune_fun/v1/account/adapter/input/security/JwtAuthenticationFilter.java @@ -87,7 +87,7 @@ private String getAccessTokenFromRequest(final HttpServletRequest request) { String accessToken = Optional.ofNullable(request.getHeader(AUTHORIZATION)) .orElseThrow(() -> { log.info("Servlet Path is {}", request.getServletPath()); - return new CommonApplicationException(MessageCode.EXCEPTION_AUTHENTICATION_TOKEN_NOT_FOUND); + return CommonApplicationException.EXCEPTION_AUTHENTICATION_TOKEN_NOT_FOUND; }); return StringUtil.removeBearerPrefix(accessToken); diff --git a/src/main/java/com/tune_fun/v1/account/adapter/output/persistence/jwt/JwtTokenPersistenceAdapter.java b/src/main/java/com/tune_fun/v1/account/adapter/output/persistence/jwt/JwtTokenPersistenceAdapter.java index 5e993738..91cdf7af 100644 --- a/src/main/java/com/tune_fun/v1/account/adapter/output/persistence/jwt/JwtTokenPersistenceAdapter.java +++ b/src/main/java/com/tune_fun/v1/account/adapter/output/persistence/jwt/JwtTokenPersistenceAdapter.java @@ -3,9 +3,9 @@ import com.tune_fun.v1.account.application.port.output.jwt.*; import com.tune_fun.v1.account.domain.behavior.SaveJwtToken; import com.tune_fun.v1.common.exception.CommonApplicationException; -import com.tune_fun.v1.common.stereotype.PersistenceAdapter; import com.tune_fun.v1.common.property.JwtProperty; import com.tune_fun.v1.common.response.MessageCode; +import com.tune_fun.v1.common.stereotype.PersistenceAdapter; import com.tune_fun.v1.external.aws.kms.KmsProvider; import io.jsonwebtoken.Claims; import io.jsonwebtoken.ExpiredJwtException; @@ -82,7 +82,7 @@ public Boolean validate(String token) { return true; } catch (IllegalArgumentException e) { log.error("JWT claims string is empty: {}", e.getMessage()); - throw new CommonApplicationException(MessageCode.EXCEPTION_AUTHENTICATION_INVALID_TOKEN); + throw CommonApplicationException.EXCEPTION_AUTHENTICATION_INVALID_TOKEN; } } @@ -162,10 +162,10 @@ public String reissueAccessToken(String refreshTokenValue) { RefreshTokenRedisEntity refreshToken = redisTemplateRefresh.opsForValue().get(refreshTokenKey); if (refreshToken == null && refreshToken.getToken().equals(refreshTokenValue)) - throw new CommonApplicationException(MessageCode.EXCEPTION_AUTHENTICATION_INVALID_TOKEN); + throw CommonApplicationException.EXCEPTION_AUTHENTICATION_INVALID_TOKEN; if (isRefreshTokenExpired(refreshToken.getToken())) - throw new CommonApplicationException(MessageCode.EXCEPTION_EXPIRED_REFRESH_TOKEN); + throw CommonApplicationException.EXCEPTION_EXPIRED_REFRESH_TOKEN; SaveJwtToken behavior = new SaveJwtToken(username, getPayload(refreshTokenValue).get("role").toString()); return createAccessToken(behavior); @@ -212,7 +212,7 @@ private Claims getPayload(final String token) { try { return getJwtParser().parseSignedClaims(token).getPayload(); } catch (IllegalArgumentException e) { - throw new CommonApplicationException(MessageCode.EXCEPTION_AUTHENTICATION_INVALID_TOKEN); + throw CommonApplicationException.EXCEPTION_AUTHENTICATION_INVALID_TOKEN; } } diff --git a/src/main/java/com/tune_fun/v1/account/application/service/CheckUsernameDuplicateService.java b/src/main/java/com/tune_fun/v1/account/application/service/CheckUsernameDuplicateService.java index 29002e08..cf325a5b 100644 --- a/src/main/java/com/tune_fun/v1/account/application/service/CheckUsernameDuplicateService.java +++ b/src/main/java/com/tune_fun/v1/account/application/service/CheckUsernameDuplicateService.java @@ -8,8 +8,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.tune_fun.v1.common.response.MessageCode.USER_POLICY_USERNAME_REGISTERED; - @Service @UseCase @@ -23,7 +21,7 @@ public class CheckUsernameDuplicateService implements CheckUsernameDuplicateUseC public void checkUsernameDuplicate(final String username) { loadAccountPort.registeredAccountInfoByUsername(username) .ifPresent(account -> { - throw new CommonApplicationException(USER_POLICY_USERNAME_REGISTERED); + throw CommonApplicationException.USER_POLICY_USERNAME_REGISTERED; }); } } diff --git a/src/main/java/com/tune_fun/v1/account/application/service/CustomUserDetailsService.java b/src/main/java/com/tune_fun/v1/account/application/service/CustomUserDetailsService.java index dded4189..d3bd92f3 100644 --- a/src/main/java/com/tune_fun/v1/account/application/service/CustomUserDetailsService.java +++ b/src/main/java/com/tune_fun/v1/account/application/service/CustomUserDetailsService.java @@ -10,8 +10,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.tune_fun.v1.common.response.MessageCode.ACCOUNT_NOT_FOUND; - @Service @UseCase @@ -24,6 +22,6 @@ public class CustomUserDetailsService implements UserDetailsService { @Transactional(readOnly = true) public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { return loadAccountPort.loadCustomUserByUsername(username) - .orElseThrow(() -> new CommonApplicationException(ACCOUNT_NOT_FOUND)); + .orElseThrow(CommonApplicationException.ACCOUNT_NOT_FOUND); } } diff --git a/src/main/java/com/tune_fun/v1/account/application/service/FindUsernameService.java b/src/main/java/com/tune_fun/v1/account/application/service/FindUsernameService.java index 87179b20..11b053d2 100644 --- a/src/main/java/com/tune_fun/v1/account/application/service/FindUsernameService.java +++ b/src/main/java/com/tune_fun/v1/account/application/service/FindUsernameService.java @@ -14,8 +14,6 @@ import java.util.Optional; -import static com.tune_fun.v1.common.response.MessageCode.ACCOUNT_NOT_FOUND; - @Service @UseCase @@ -36,6 +34,6 @@ public void findUsername(final AccountQueries.Username query) throws Exception { return; } - throw new CommonApplicationException(ACCOUNT_NOT_FOUND); + throw CommonApplicationException.ACCOUNT_NOT_FOUND; } } diff --git a/src/main/java/com/tune_fun/v1/account/application/service/LoginService.java b/src/main/java/com/tune_fun/v1/account/application/service/LoginService.java index 29403747..c44442bf 100644 --- a/src/main/java/com/tune_fun/v1/account/application/service/LoginService.java +++ b/src/main/java/com/tune_fun/v1/account/application/service/LoginService.java @@ -20,8 +20,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.tune_fun.v1.common.response.MessageCode.ACCOUNT_NOT_FOUND; - @Service @UseCase @@ -50,10 +48,10 @@ private static LoginResult getLoginResult(RegisteredAccount registeredAccount, S @Transactional public LoginResult login(final AccountCommands.Login command) { RegisteredAccount registeredAccount = loadAccountPort.registeredAccountInfoByUsername(command.username()) - .orElseThrow(() -> new CommonApplicationException(ACCOUNT_NOT_FOUND)); + .orElseThrow(CommonApplicationException.ACCOUNT_NOT_FOUND); if (!passwordEncoder.matches(command.password(), registeredAccount.password())) - throw new CommonApplicationException(ACCOUNT_NOT_FOUND); + throw CommonApplicationException.ACCOUNT_NOT_FOUND; String authorities = String.join(Constants.COMMA, registeredAccount.roles()); diff --git a/src/main/java/com/tune_fun/v1/account/application/service/RegisterService.java b/src/main/java/com/tune_fun/v1/account/application/service/RegisterService.java index e4464743..4b0750c0 100644 --- a/src/main/java/com/tune_fun/v1/account/application/service/RegisterService.java +++ b/src/main/java/com/tune_fun/v1/account/application/service/RegisterService.java @@ -20,8 +20,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.tune_fun.v1.common.response.MessageCode.USER_POLICY_ACCOUNT_REGISTERED; - @Service @UseCase @@ -71,7 +69,7 @@ public RegisterResult register(final String registerType, final AccountCommands. @Transactional(readOnly = true) public void checkRegisteredAccount(AccountCommands.Register command) { loadAccountPort.currentAccountInfo(command.username()).ifPresent(accountInfo -> { - throw new CommonApplicationException(USER_POLICY_ACCOUNT_REGISTERED); + throw CommonApplicationException.USER_POLICY_ACCOUNT_REGISTERED; }); } } diff --git a/src/main/java/com/tune_fun/v1/account/application/service/SendForgotPasswordOtpService.java b/src/main/java/com/tune_fun/v1/account/application/service/SendForgotPasswordOtpService.java index be861f85..1e813832 100644 --- a/src/main/java/com/tune_fun/v1/account/application/service/SendForgotPasswordOtpService.java +++ b/src/main/java/com/tune_fun/v1/account/application/service/SendForgotPasswordOtpService.java @@ -16,7 +16,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.tune_fun.v1.common.response.MessageCode.ACCOUNT_NOT_FOUND; import static com.tune_fun.v1.otp.adapter.output.persistence.OtpType.FORGOT_PASSWORD; @@ -49,6 +48,6 @@ public void sendOtp(final AccountCommands.SendForgotPasswordOtp command) throws @Transactional(readOnly = true) public CurrentAccount getCurrentAccount(final AccountCommands.SendForgotPasswordOtp command) { return loadAccountPort.currentAccountInfo(command.username()) - .orElseThrow(() -> new CommonApplicationException(ACCOUNT_NOT_FOUND)); + .orElseThrow(CommonApplicationException.ACCOUNT_NOT_FOUND); } } diff --git a/src/main/java/com/tune_fun/v1/account/application/service/UpdateNicknameService.java b/src/main/java/com/tune_fun/v1/account/application/service/UpdateNicknameService.java index 4147916f..95a16202 100644 --- a/src/main/java/com/tune_fun/v1/account/application/service/UpdateNicknameService.java +++ b/src/main/java/com/tune_fun/v1/account/application/service/UpdateNicknameService.java @@ -11,8 +11,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.tune_fun.v1.common.response.MessageCode.USER_POLICY_NICKNAME_REGISTERED; - @Service @UseCase @RequiredArgsConstructor @@ -25,7 +23,7 @@ public class UpdateNicknameService implements UpdateNicknameUseCase { @Transactional public void updateNickname(final AccountCommands.UpdateNickname command, final User user) { if (loadAccountPort.registeredAccountInfoByNickname(command.newNickname()).isPresent()) - throw new CommonApplicationException(USER_POLICY_NICKNAME_REGISTERED); + throw CommonApplicationException.USER_POLICY_NICKNAME_REGISTERED; updateNicknamePort.updateNickname(user.getUsername(), command.newNickname()); } diff --git a/src/main/java/com/tune_fun/v1/account/application/service/email/CheckEmailDuplicateService.java b/src/main/java/com/tune_fun/v1/account/application/service/email/CheckEmailDuplicateService.java index e6f5c921..1dfe74f9 100644 --- a/src/main/java/com/tune_fun/v1/account/application/service/email/CheckEmailDuplicateService.java +++ b/src/main/java/com/tune_fun/v1/account/application/service/email/CheckEmailDuplicateService.java @@ -8,8 +8,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.tune_fun.v1.common.response.MessageCode.USER_POLICY_EMAIL_REGISTERED; - @Service @UseCase @@ -23,7 +21,7 @@ public class CheckEmailDuplicateService implements CheckEmailDuplicateUseCase { public void checkEmailDuplicate(final String email) { loadAccountPort.registeredAccountInfoByEmail(email) .ifPresent(account -> { - throw new CommonApplicationException(USER_POLICY_EMAIL_REGISTERED); + throw CommonApplicationException.USER_POLICY_EMAIL_REGISTERED; }); } } diff --git a/src/main/java/com/tune_fun/v1/account/application/service/email/CheckEmailVerifiedService.java b/src/main/java/com/tune_fun/v1/account/application/service/email/CheckEmailVerifiedService.java index 1449a5a3..5bfe7c54 100644 --- a/src/main/java/com/tune_fun/v1/account/application/service/email/CheckEmailVerifiedService.java +++ b/src/main/java/com/tune_fun/v1/account/application/service/email/CheckEmailVerifiedService.java @@ -10,9 +10,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.tune_fun.v1.common.response.MessageCode.ACCOUNT_NOT_FOUND; -import static com.tune_fun.v1.common.response.MessageCode.EXCEPTION_EMAIL_NOT_VERIFIED; - @Service @UseCase @@ -25,9 +22,9 @@ public class CheckEmailVerifiedService implements CheckEmailVerifiedUseCase { @Transactional public void checkEmailVerified(final User user) { CurrentAccount currentAccount = loadAccountPort.currentAccountInfo(user.getUsername()) - .orElseThrow(() -> new CommonApplicationException(ACCOUNT_NOT_FOUND)); + .orElseThrow(CommonApplicationException.ACCOUNT_NOT_FOUND); if (currentAccount.emailVerifiedAt() == null) - throw new CommonApplicationException(EXCEPTION_EMAIL_NOT_VERIFIED); + throw CommonApplicationException.EXCEPTION_EMAIL_NOT_VERIFIED; } } diff --git a/src/main/java/com/tune_fun/v1/account/application/service/email/RegisterEmailService.java b/src/main/java/com/tune_fun/v1/account/application/service/email/RegisterEmailService.java index cba8050a..f08a3e03 100644 --- a/src/main/java/com/tune_fun/v1/account/application/service/email/RegisterEmailService.java +++ b/src/main/java/com/tune_fun/v1/account/application/service/email/RegisterEmailService.java @@ -12,9 +12,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.tune_fun.v1.common.response.MessageCode.ACCOUNT_NOT_FOUND; -import static com.tune_fun.v1.common.response.MessageCode.USER_POLICY_CANNOT_REGISTER_EMAIL_TWICE; - @Service @UseCase @RequiredArgsConstructor @@ -28,10 +25,10 @@ public class RegisterEmailService implements RegisterEmailUseCase { @Override public void registerEmail(AccountCommands.SaveEmail command, User user) throws Exception { CurrentAccount currentAccount = loadAccountPort.currentAccountInfo(user.getUsername()) - .orElseThrow(() -> new CommonApplicationException(ACCOUNT_NOT_FOUND)); + .orElseThrow(CommonApplicationException.ACCOUNT_NOT_FOUND); if (currentAccount.email() != null) - throw new CommonApplicationException(USER_POLICY_CANNOT_REGISTER_EMAIL_TWICE); + throw CommonApplicationException.USER_POLICY_CANNOT_REGISTER_EMAIL_TWICE; saveEmailPort.saveEmail(command.email(), user.getUsername()); } diff --git a/src/main/java/com/tune_fun/v1/account/application/service/email/VerifyEmailService.java b/src/main/java/com/tune_fun/v1/account/application/service/email/VerifyEmailService.java index eba85cbd..25616769 100644 --- a/src/main/java/com/tune_fun/v1/account/application/service/email/VerifyEmailService.java +++ b/src/main/java/com/tune_fun/v1/account/application/service/email/VerifyEmailService.java @@ -16,7 +16,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.tune_fun.v1.common.response.MessageCode.ACCOUNT_NOT_FOUND; import static com.tune_fun.v1.otp.adapter.output.persistence.OtpType.VERIFY_EMAIL; @Service @@ -49,6 +48,6 @@ private static SaveOtp getSaveOtp(String username) { @Transactional(readOnly = true) public CurrentAccount getCurrentAccount(final String username) { return loadAccountPort.currentAccountInfo(username) - .orElseThrow(() -> new CommonApplicationException(ACCOUNT_NOT_FOUND)); + .orElseThrow(CommonApplicationException.ACCOUNT_NOT_FOUND); } } diff --git a/src/main/java/com/tune_fun/v1/account/application/service/oauth2/handler/OAuth2AuthenticationSuccessHandler.java b/src/main/java/com/tune_fun/v1/account/application/service/oauth2/handler/OAuth2AuthenticationSuccessHandler.java index c61cb5c6..9f0f466b 100644 --- a/src/main/java/com/tune_fun/v1/account/application/service/oauth2/handler/OAuth2AuthenticationSuccessHandler.java +++ b/src/main/java/com/tune_fun/v1/account/application/service/oauth2/handler/OAuth2AuthenticationSuccessHandler.java @@ -36,7 +36,6 @@ import static com.tune_fun.v1.account.adapter.output.persistence.oauth2.OAuth2AuthorizationRequestPersistenceAdapter.*; import static com.tune_fun.v1.account.domain.value.oauth2.OAuth2AuthorizationRequestMode.fromQueryParameter; import static com.tune_fun.v1.account.domain.value.oauth2.OAuth2Provider.APPLE; -import static com.tune_fun.v1.common.response.MessageCode.*; import static com.tune_fun.v1.common.util.CookieUtil.getCookie; import static com.tune_fun.v1.common.util.StringUtil.getFlattenAuthorities; import static org.springframework.web.util.UriComponentsBuilder.fromUriString; @@ -126,7 +125,7 @@ public String link(final OAuth2UserPrincipal principal, final String targetUrl, if (usernameOptional.isEmpty()) return AUTH_FAILED_URL_FUNCTION.apply(targetUrl); if (loadRegisteredOAuth2Account(principal).isPresent()) - throw new CommonApplicationException(USER_POLICY_ALREADY_LINKED_PROVIDER); + throw CommonApplicationException.USER_POLICY_ALREADY_LINKED_PROVIDER; String username = usernameOptional.get(); RegisteredAccount registeredAccount = loadRegisteredAccount(username); @@ -162,7 +161,7 @@ public String unlink(final OAuth2UserPrincipal principal, final String targetUrl String username = usernameOptional.get(); RegisteredAccount registeredAccount = loadRegisteredAccount(username); if (registeredAccount.isUniqueOAuth2Account()) - throw new CommonApplicationException(USER_POLICY_CANNOT_UNLINK_UNIQUE_PROVIDER); + throw CommonApplicationException.USER_POLICY_CANNOT_UNLINK_UNIQUE_PROVIDER; unlinkHttpRequest(provider, accessToken); disableOAuth2AccountPort.disableOAuth2Account(principal.userInfo().getEmail()); @@ -184,7 +183,7 @@ protected void clearAuthenticationAttributes(HttpServletRequest request, HttpSer @Transactional public RegisteredAccount loadRegisteredAccount(final String username) { return loadAccountPort.registeredAccountInfoByUsername(username) - .orElseThrow(() -> new CommonApplicationException(ACCOUNT_NOT_FOUND)); + .orElseThrow(CommonApplicationException.ACCOUNT_NOT_FOUND); } @Transactional diff --git a/src/main/java/com/tune_fun/v1/common/aspect/DistributionLockAspect.java b/src/main/java/com/tune_fun/v1/common/aspect/DistributionLockAspect.java index 40e17c8e..880dbb89 100644 --- a/src/main/java/com/tune_fun/v1/common/aspect/DistributionLockAspect.java +++ b/src/main/java/com/tune_fun/v1/common/aspect/DistributionLockAspect.java @@ -4,7 +4,6 @@ import com.tune_fun.v1.common.lock.DistributedTransactionMediator; import com.tune_fun.v1.common.lock.DistributionLock; import com.tune_fun.v1.common.lock.DistributionLockKeyGenerator; -import com.tune_fun.v1.common.response.MessageCode; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; @@ -15,9 +14,6 @@ import org.redisson.api.RedissonClient; import org.springframework.stereotype.Component; -import static com.tune_fun.v1.common.response.MessageCode.LOCK_ACQUISITION_FAILED_ERROR; -import static com.tune_fun.v1.common.response.MessageCode.LOCK_INTERRUPTED_ERROR; - @Slf4j @Aspect @Component @@ -34,13 +30,13 @@ public Object lock(ProceedingJoinPoint joinPoint, DistributionLock distributionL try { if (!lockInfo.reentrantLock().tryLock(distributionLock.waitTime(), distributionLock.leaseTime(), distributionLock.timeUnit())) - throw new CommonApplicationException(LOCK_ACQUISITION_FAILED_ERROR); + throw CommonApplicationException.LOCK_ACQUISITION_FAILED_ERROR; log.info("reentrantLock - {}", lockInfo.key()); return distributedTransactionMediator.proceed(joinPoint); } catch (InterruptedException e) { log.error(e.getMessage()); - throw new CommonApplicationException(LOCK_INTERRUPTED_ERROR); + throw CommonApplicationException.LOCK_INTERRUPTED_ERROR; } finally { log.info("unlock - {}", lockInfo.key()); lockInfo.reentrantLock().unlock(); diff --git a/src/main/java/com/tune_fun/v1/common/aspect/RateLimitAspect.java b/src/main/java/com/tune_fun/v1/common/aspect/RateLimitAspect.java index d2c21c6d..6aa6f23e 100644 --- a/src/main/java/com/tune_fun/v1/common/aspect/RateLimitAspect.java +++ b/src/main/java/com/tune_fun/v1/common/aspect/RateLimitAspect.java @@ -2,7 +2,6 @@ import com.tune_fun.v1.common.exception.CommonApplicationException; import com.tune_fun.v1.common.rate.TokenBucketResolver; -import com.tune_fun.v1.common.response.MessageCode; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; @@ -31,7 +30,7 @@ public Object rateLimit(ProceedingJoinPoint joinPoint) throws Throwable { if (tokenBucketResolver.checkBucketCounter(key)) return joinPoint.proceed(); - throw new CommonApplicationException(MessageCode.TOO_MANY_REQUESTS); + throw CommonApplicationException.TOO_MANY_REQUESTS; } } diff --git a/src/main/java/com/tune_fun/v1/common/config/PermissionPolicyEvaluator.java b/src/main/java/com/tune_fun/v1/common/config/PermissionPolicyEvaluator.java index 30b01810..e851dc30 100644 --- a/src/main/java/com/tune_fun/v1/common/config/PermissionPolicyEvaluator.java +++ b/src/main/java/com/tune_fun/v1/common/config/PermissionPolicyEvaluator.java @@ -13,8 +13,6 @@ import java.io.Serializable; -import static com.tune_fun.v1.common.response.MessageCode.*; - @Slf4j @Component @RequiredArgsConstructor @@ -40,16 +38,16 @@ public boolean hasPermission(Authentication authentication, Serializable targetI public boolean hasPermissionForVotePaper(User principal, Serializable targetId) { RegisteredVotePaper registeredVotePaper = loadVotePaperPort.loadRegisteredVotePaper(principal.getUsername()) - .orElseThrow(() -> new CommonApplicationException(VOTE_POLICY_ONLY_AUTHOR_CAN_UPDATE_DELIVERY_DATE)); + .orElseThrow(CommonApplicationException.VOTE_POLICY_ONLY_AUTHOR_CAN_UPDATE_DELIVERY_DATE); if (registeredVotePaper.id().equals(targetId)) return true; - throw new CommonApplicationException(VOTE_PAPER_NOT_FOUND); + throw CommonApplicationException.VOTE_PAPER_NOT_FOUND; } private boolean hasPermissionForVote(User principal, Serializable targetId) { if (loadVotePort.loadVoteByVoterAndVotePaperId(principal.getUsername(), (Long) targetId).isPresent()) - throw new CommonApplicationException(VOTE_POLICY_ONE_VOTE_PER_USER); + throw CommonApplicationException.VOTE_POLICY_ONE_VOTE_PER_USER; return true; } diff --git a/src/main/java/com/tune_fun/v1/common/exception/CommonApplicationException.java b/src/main/java/com/tune_fun/v1/common/exception/CommonApplicationException.java index cf90e55f..12b1d8e2 100644 --- a/src/main/java/com/tune_fun/v1/common/exception/CommonApplicationException.java +++ b/src/main/java/com/tune_fun/v1/common/exception/CommonApplicationException.java @@ -8,6 +8,9 @@ import java.util.function.Supplier; +/** + * @see Java의 예외 생성 비용 절감 방법 + */ @NoArgsConstructor @AllArgsConstructor @Data @@ -16,6 +19,59 @@ public class CommonApplicationException extends RuntimeException implements Supp private MessageCode messageCode; + public static final CommonApplicationException TOO_MANY_REQUESTS = new CommonApplicationException(MessageCode.TOO_MANY_REQUESTS); + public static final CommonApplicationException NOT_OWNER = new CommonApplicationException(MessageCode.NOT_OWNER); + public static final CommonApplicationException NOT_FOUND_DATA = new CommonApplicationException(MessageCode.NOT_FOUND_DATA); + public static final CommonApplicationException ERROR = new CommonApplicationException(MessageCode.ERROR); + public static final CommonApplicationException EXCEPTION_ILLEGAL_ARGUMENT = new CommonApplicationException(MessageCode.EXCEPTION_ILLEGAL_ARGUMENT); + + public static final CommonApplicationException ACCOUNT_NOT_FOUND = new CommonApplicationException(MessageCode.ACCOUNT_NOT_FOUND); + public static final CommonApplicationException USER_POLICY_ACCOUNT_REGISTERED = new CommonApplicationException(MessageCode.USER_POLICY_ACCOUNT_REGISTERED); + public static final CommonApplicationException USER_POLICY_NICKNAME_REGISTERED = new CommonApplicationException(MessageCode.USER_POLICY_NICKNAME_REGISTERED); + public static final CommonApplicationException USER_UNREGISTERED = new CommonApplicationException(MessageCode.USER_UNREGISTERED); + public static final CommonApplicationException USER_POLICY_AUTH = new CommonApplicationException(MessageCode.USER_POLICY_AUTH); + public static final CommonApplicationException USER_POLICY_USERNAME_REGISTERED = new CommonApplicationException(MessageCode.USER_POLICY_USERNAME_REGISTERED); + public static final CommonApplicationException USER_POLICY_EMAIL_REGISTERED = new CommonApplicationException(MessageCode.USER_POLICY_EMAIL_REGISTERED); + public static final CommonApplicationException USER_POLICY_CANNOT_UNLINK_UNIQUE_PROVIDER = new CommonApplicationException(MessageCode.USER_POLICY_CANNOT_UNLINK_UNIQUE_PROVIDER); + public static final CommonApplicationException USER_POLICY_ALREADY_LINKED_PROVIDER = new CommonApplicationException(MessageCode.USER_POLICY_ALREADY_LINKED_PROVIDER); + public static final CommonApplicationException USER_POLICY_CANNOT_REGISTER_EMAIL_TWICE = new CommonApplicationException(MessageCode.USER_POLICY_CANNOT_REGISTER_EMAIL_TWICE); + + public static final CommonApplicationException EXCEPTION_AUTHENTICATION_LOGIN_FAIL = new CommonApplicationException(MessageCode.EXCEPTION_AUTHENTICATION_LOGIN_FAIL); + public static final CommonApplicationException EXCEPTION_AUTHENTICATION_INVALID_TOKEN = new CommonApplicationException(MessageCode.EXCEPTION_AUTHENTICATION_INVALID_TOKEN); + public static final CommonApplicationException EXCEPTION_AUTHENTICATION_TOKEN_NOT_FOUND = new CommonApplicationException(MessageCode.EXCEPTION_AUTHENTICATION_TOKEN_NOT_FOUND); + public static final CommonApplicationException EXCEPTION_EXPIRED_TOKEN = new CommonApplicationException(MessageCode.EXCEPTION_EXPIRED_TOKEN); + public static final CommonApplicationException EXCEPTION_REFRESH_TOKEN_NOT_FOUND = new CommonApplicationException(MessageCode.EXCEPTION_REFRESH_TOKEN_NOT_FOUND); + public static final CommonApplicationException EXCEPTION_EXPIRED_REFRESH_TOKEN = new CommonApplicationException(MessageCode.EXCEPTION_EXPIRED_REFRESH_TOKEN); + public static final CommonApplicationException EXCEPTION_EMAIL_NOT_VERIFIED = new CommonApplicationException(MessageCode.EXCEPTION_EMAIL_NOT_VERIFIED); + + public static final CommonApplicationException EXCEPTION_OTP_NOT_FOUND = new CommonApplicationException(MessageCode.EXCEPTION_OTP_NOT_FOUND); + public static final CommonApplicationException EXCEPTION_OTP_EXPIRED = new CommonApplicationException(MessageCode.EXCEPTION_OTP_EXPIRED); + public static final CommonApplicationException EXCEPTION_OTP_NOT_MATCH = new CommonApplicationException(MessageCode.EXCEPTION_OTP_NOT_MATCH); + public static final CommonApplicationException EXCEPTION_OTP_TYPE_NOT_FOUND = new CommonApplicationException(MessageCode.SUCCESS_OTP_VERIFIED); + + public static final CommonApplicationException VOTE_POLICY_ONE_VOTE_PAPER_PER_USER = new CommonApplicationException(MessageCode.VOTE_POLICY_ONE_VOTE_PAPER_PER_USER); + public static final CommonApplicationException VOTE_POLICY_ONLY_AUTHOR_CAN_UPDATE_DELIVERY_DATE = new CommonApplicationException(MessageCode.VOTE_POLICY_ONLY_AUTHOR_CAN_UPDATE_DELIVERY_DATE); + public static final CommonApplicationException VOTE_PAPER_NOT_FOUND = new CommonApplicationException(MessageCode.VOTE_PAPER_NOT_FOUND); + public static final CommonApplicationException VOTE_POLICY_ONE_VOTE_PER_USER = new CommonApplicationException(MessageCode.VOTE_POLICY_ONE_VOTE_PER_USER); + public static final CommonApplicationException VOTE_POLICY_ONLY_AUTHOR_CAN_UPDATE_VIDEO_URL = new CommonApplicationException(MessageCode.VOTE_POLICY_ONLY_AUTHOR_CAN_UPDATE_VIDEO_URL); + public static final CommonApplicationException VOTE_POLICY_ONLY_AUTHOR_CAN_DELETE = new CommonApplicationException(MessageCode.VOTE_POLICY_ONLY_AUTHOR_CAN_DELETE); + public static final CommonApplicationException VOTE_POLICY_OFFERS_COUNT_SHOULD_BE_MORE_THAN_TWO = new CommonApplicationException(MessageCode.VOTE_POLICY_OFFERS_COUNT_SHOULD_BE_MORE_THAN_TWO); + public static final CommonApplicationException VOTE_POLICY_ONLY_REGISTER_CHOICE_ON_ALLOW_ADD_CHOICES_OPTION = new CommonApplicationException(MessageCode.VOTE_POLICY_ONLY_REGISTER_CHOICE_ON_ALLOW_ADD_CHOICES_OPTION); + public static final CommonApplicationException VOTE_POLICY_ONE_VOTE_CHOICE_PER_USER_ON_VOTE_PAPER = new CommonApplicationException(MessageCode.VOTE_POLICY_ONE_VOTE_CHOICE_PER_USER_ON_VOTE_PAPER); + public static final CommonApplicationException VOTE_POLICY_ALREADY_LIKED_VOTE_PAPER = new CommonApplicationException(MessageCode.VOTE_POLICY_ALREADY_LIKED_VOTE_PAPER); + + public static final CommonApplicationException ALREADY_FOLLOWED = new CommonApplicationException(MessageCode.ALREADY_FOLLOWED); + public static final CommonApplicationException NOT_FOLLOWED = new CommonApplicationException(MessageCode.NOT_FOLLOWED); + + public static final CommonApplicationException LOCK_ACQUISITION_FAILED_ERROR = new CommonApplicationException(MessageCode.LOCK_ACQUISITION_FAILED_ERROR); + public static final CommonApplicationException LOCK_INTERRUPTED_ERROR = new CommonApplicationException(MessageCode.LOCK_INTERRUPTED_ERROR); + + + @Override + public synchronized Throwable fillInStackTrace() { + return MessageCode.ERROR.equals(messageCode) ? super.fillInStackTrace() : this; + } + @Override public CommonApplicationException get() { return this; diff --git a/src/main/java/com/tune_fun/v1/common/rate/TokenBucketResolver.java b/src/main/java/com/tune_fun/v1/common/rate/TokenBucketResolver.java index ff7835de..fb269437 100644 --- a/src/main/java/com/tune_fun/v1/common/rate/TokenBucketResolver.java +++ b/src/main/java/com/tune_fun/v1/common/rate/TokenBucketResolver.java @@ -23,7 +23,7 @@ private Bucket bucket(final String key) { } public boolean checkBucketCounter(String key) { - if (!bucket(key).tryConsume(1)) throw new CommonApplicationException(TOO_MANY_REQUESTS); + if (!bucket(key).tryConsume(1)) throw CommonApplicationException.TOO_MANY_REQUESTS; return true; } diff --git a/src/main/java/com/tune_fun/v1/interaction/application/service/FollowService.java b/src/main/java/com/tune_fun/v1/interaction/application/service/FollowService.java index c2f835dd..f9853d17 100644 --- a/src/main/java/com/tune_fun/v1/interaction/application/service/FollowService.java +++ b/src/main/java/com/tune_fun/v1/interaction/application/service/FollowService.java @@ -16,9 +16,6 @@ import java.util.function.Consumer; -import static com.tune_fun.v1.common.response.MessageCode.ACCOUNT_NOT_FOUND; -import static com.tune_fun.v1.common.response.MessageCode.ALREADY_FOLLOWED; - @Service @UseCase @RequiredArgsConstructor @@ -29,14 +26,14 @@ public class FollowService implements FollowUserUseCase { private final SaveFollowPort saveFollowPort; private static final Consumer THROW_ALREADY_FOLLOWED = follow -> { - throw new CommonApplicationException(ALREADY_FOLLOWED); + throw CommonApplicationException.ALREADY_FOLLOWED; }; @Transactional @Override public void follow(final InteractionCommands.Follow command, final User user) { CurrentAccount currentAccount = loadAccountPort.currentAccountInfo(user.getUsername()) - .orElseThrow(new CommonApplicationException(ACCOUNT_NOT_FOUND)); + .orElseThrow(CommonApplicationException.ACCOUNT_NOT_FOUND); Long followerAccountId = currentAccount.id(); loadFollowPort.loadFollow(command.targetAccountId(), followerAccountId) diff --git a/src/main/java/com/tune_fun/v1/interaction/application/service/LikeVotePaperService.java b/src/main/java/com/tune_fun/v1/interaction/application/service/LikeVotePaperService.java index 78e3a1a2..9a5e0fc9 100644 --- a/src/main/java/com/tune_fun/v1/interaction/application/service/LikeVotePaperService.java +++ b/src/main/java/com/tune_fun/v1/interaction/application/service/LikeVotePaperService.java @@ -11,8 +11,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.tune_fun.v1.common.response.MessageCode.VOTE_POLICY_ALREADY_LIKED_VOTE_PAPER; - @Service @UseCase @RequiredArgsConstructor @@ -27,7 +25,7 @@ public class LikeVotePaperService implements LikeVotePaperUseCase { @Override public void likeVotePaper(final Long votePaperId, final User user) { if (isVotePaperLikePresent(votePaperId, user)) - throw new CommonApplicationException(VOTE_POLICY_ALREADY_LIKED_VOTE_PAPER); + throw CommonApplicationException.VOTE_POLICY_ALREADY_LIKED_VOTE_PAPER; saveLikePort.saveVotePaperLike(votePaperId, user.getUsername()); saveVotePaperLikeCountPort.incrementVotePaperLikeCount(votePaperId); diff --git a/src/main/java/com/tune_fun/v1/interaction/application/service/UnFollowService.java b/src/main/java/com/tune_fun/v1/interaction/application/service/UnFollowService.java index b4c5ae77..a61c30f0 100644 --- a/src/main/java/com/tune_fun/v1/interaction/application/service/UnFollowService.java +++ b/src/main/java/com/tune_fun/v1/interaction/application/service/UnFollowService.java @@ -13,9 +13,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.tune_fun.v1.common.response.MessageCode.ACCOUNT_NOT_FOUND; -import static com.tune_fun.v1.common.response.MessageCode.NOT_FOLLOWED; - @Service @UseCase @RequiredArgsConstructor @@ -29,14 +26,14 @@ public class UnFollowService implements UnFollowUserUseCase { @Override public void unfollow(final InteractionCommands.UnFollow command, final User user) { CurrentAccount currentAccount = loadAccountPort.currentAccountInfo(user.getUsername()) - .orElseThrow(new CommonApplicationException(ACCOUNT_NOT_FOUND)); + .orElseThrow(CommonApplicationException.ACCOUNT_NOT_FOUND); Long followerAccountId = currentAccount.id(); loadFollowPort.loadFollow(command.targetAccountId(), followerAccountId) .ifPresentOrElse( follow -> deleteFollowPort.deleteFollow(follow.followeeId(), follow.followerId()), () -> { - throw new CommonApplicationException(NOT_FOLLOWED); + throw CommonApplicationException.NOT_FOLLOWED; } ); } diff --git a/src/main/java/com/tune_fun/v1/otp/adapter/output/persistence/OtpPersistenceAdapter.java b/src/main/java/com/tune_fun/v1/otp/adapter/output/persistence/OtpPersistenceAdapter.java index 5a3c9223..8f739cd3 100644 --- a/src/main/java/com/tune_fun/v1/otp/adapter/output/persistence/OtpPersistenceAdapter.java +++ b/src/main/java/com/tune_fun/v1/otp/adapter/output/persistence/OtpPersistenceAdapter.java @@ -24,7 +24,6 @@ import java.util.Date; import java.util.Objects; -import static com.tune_fun.v1.common.response.MessageCode.*; import static com.tune_fun.v1.otp.adapter.output.persistence.OtpType.fromLabel; import static java.lang.String.format; @@ -73,13 +72,13 @@ public void verifyOtp(final VerifyOtp verifyOtp) throws Exception { ValueOperations ops = redisTemplate.opsForValue(); OtpRedisEntity otpRedisEntity = ops.get(otpKey); - if (otpRedisEntity == null) throw new CommonApplicationException(EXCEPTION_OTP_NOT_FOUND); + if (otpRedisEntity == null) throw CommonApplicationException.EXCEPTION_OTP_NOT_FOUND; if (checkRedisExpiration(ops, otpKey)) - throw new CommonApplicationException(EXCEPTION_OTP_EXPIRED); + throw CommonApplicationException.EXCEPTION_OTP_EXPIRED; if (!checkMatchValue(verifyOtp.otp(), otpRedisEntity)) - throw new CommonApplicationException(EXCEPTION_OTP_NOT_MATCH); + throw CommonApplicationException.EXCEPTION_OTP_NOT_MATCH; expire(otpKey); } diff --git a/src/main/java/com/tune_fun/v1/otp/adapter/output/persistence/OtpType.java b/src/main/java/com/tune_fun/v1/otp/adapter/output/persistence/OtpType.java index 0a42f4ff..8dee315d 100644 --- a/src/main/java/com/tune_fun/v1/otp/adapter/output/persistence/OtpType.java +++ b/src/main/java/com/tune_fun/v1/otp/adapter/output/persistence/OtpType.java @@ -4,8 +4,6 @@ import lombok.AllArgsConstructor; import lombok.Getter; -import static com.tune_fun.v1.common.response.MessageCode.EXCEPTION_OTP_TYPE_NOT_FOUND; - @Getter @AllArgsConstructor public enum OtpType { @@ -20,7 +18,7 @@ public enum OtpType { public static OtpType fromLabel(String label) { for (OtpType type : OtpType.values()) if (type.getLabel().equals(label)) return type; - throw new CommonApplicationException(EXCEPTION_OTP_TYPE_NOT_FOUND); + throw CommonApplicationException.EXCEPTION_OTP_TYPE_NOT_FOUND; } } diff --git a/src/main/java/com/tune_fun/v1/otp/application/service/ResendOtpService.java b/src/main/java/com/tune_fun/v1/otp/application/service/ResendOtpService.java index ead1620a..cebf244f 100644 --- a/src/main/java/com/tune_fun/v1/otp/application/service/ResendOtpService.java +++ b/src/main/java/com/tune_fun/v1/otp/application/service/ResendOtpService.java @@ -4,7 +4,6 @@ import com.tune_fun.v1.account.domain.value.CurrentAccount; import com.tune_fun.v1.common.exception.CommonApplicationException; import com.tune_fun.v1.common.stereotype.UseCase; -import com.tune_fun.v1.common.response.MessageCode; import com.tune_fun.v1.otp.application.port.input.command.OtpCommands; import com.tune_fun.v1.otp.application.port.input.usecase.ResendOtpUseCase; import com.tune_fun.v1.otp.application.port.output.DeleteOtpPort; @@ -32,7 +31,7 @@ public class ResendOtpService implements ResendOtpUseCase { @Override public void resend(final OtpCommands.Resend command) throws Exception { Optional currentAccount = loadAccountPort.currentAccountInfo(command.username()); - if (currentAccount.isEmpty()) throw new CommonApplicationException(MessageCode.ACCOUNT_NOT_FOUND); + if (currentAccount.isEmpty()) throw CommonApplicationException.ACCOUNT_NOT_FOUND; CurrentAccount account = currentAccount.get(); diff --git a/src/main/java/com/tune_fun/v1/otp/application/service/VerifyOtpService.java b/src/main/java/com/tune_fun/v1/otp/application/service/VerifyOtpService.java index 40832cfb..6d41dcdb 100644 --- a/src/main/java/com/tune_fun/v1/otp/application/service/VerifyOtpService.java +++ b/src/main/java/com/tune_fun/v1/otp/application/service/VerifyOtpService.java @@ -19,8 +19,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.tune_fun.v1.common.response.MessageCode.ACCOUNT_NOT_FOUND; - @Service @UseCase @@ -65,6 +63,6 @@ public VerifyResult verify(final OtpQueries.Verify query) throws Exception { @Transactional(readOnly = true) public CurrentAccount getCurrentAccount(OtpQueries.Verify query) { return loadAccountPort.currentAccountInfo(query.username()) - .orElseThrow(() -> new CommonApplicationException(ACCOUNT_NOT_FOUND)); + .orElseThrow(CommonApplicationException.ACCOUNT_NOT_FOUND); } } diff --git a/src/main/java/com/tune_fun/v1/vote/application/service/DeleteVotePaperService.java b/src/main/java/com/tune_fun/v1/vote/application/service/DeleteVotePaperService.java index 2f017835..eca18cac 100644 --- a/src/main/java/com/tune_fun/v1/vote/application/service/DeleteVotePaperService.java +++ b/src/main/java/com/tune_fun/v1/vote/application/service/DeleteVotePaperService.java @@ -2,7 +2,6 @@ import com.tune_fun.v1.common.exception.CommonApplicationException; import com.tune_fun.v1.common.stereotype.UseCase; -import com.tune_fun.v1.common.response.MessageCode; import com.tune_fun.v1.vote.application.port.input.usecase.DeleteVotePaperUseCase; import com.tune_fun.v1.vote.application.port.output.DeleteVotePaperPort; import com.tune_fun.v1.vote.application.port.output.LoadVotePaperPort; @@ -12,8 +11,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.tune_fun.v1.common.response.MessageCode.VOTE_POLICY_ONLY_AUTHOR_CAN_DELETE; - @Service @UseCase @RequiredArgsConstructor @@ -26,10 +23,10 @@ public class DeleteVotePaperService implements DeleteVotePaperUseCase { @Override public void delete(final Long votePaperId, final User user) { RegisteredVotePaper registeredVotePaper = loadVotePaperPort.loadRegisteredVotePaper(votePaperId) - .orElseThrow(() -> new CommonApplicationException(MessageCode.VOTE_PAPER_NOT_FOUND)); + .orElseThrow(CommonApplicationException.VOTE_PAPER_NOT_FOUND); if (!registeredVotePaper.isAuthor(user.getUsername())) - throw new CommonApplicationException(VOTE_POLICY_ONLY_AUTHOR_CAN_DELETE); + throw CommonApplicationException.VOTE_POLICY_ONLY_AUTHOR_CAN_DELETE; deleteVotePaperPort.disableVotePaper(votePaperId); } diff --git a/src/main/java/com/tune_fun/v1/vote/application/service/GetVotePaperService.java b/src/main/java/com/tune_fun/v1/vote/application/service/GetVotePaperService.java index fd39dfa4..cb6e9e23 100644 --- a/src/main/java/com/tune_fun/v1/vote/application/service/GetVotePaperService.java +++ b/src/main/java/com/tune_fun/v1/vote/application/service/GetVotePaperService.java @@ -17,8 +17,6 @@ import java.util.List; import java.util.Optional; -import static com.tune_fun.v1.common.response.MessageCode.VOTE_PAPER_NOT_FOUND; - @Service @UseCase @RequiredArgsConstructor @@ -33,7 +31,7 @@ public class GetVotePaperService implements GetVotePaperUseCase { @Override public FullVotePaper getVotePaper(final Long votePaperId, final User user) { RegisteredVotePaper registeredVotePaper = loadVotePaperPort.loadRegisteredVotePaper(votePaperId) - .orElseThrow(() -> new CommonApplicationException(VOTE_PAPER_NOT_FOUND)); + .orElseThrow(CommonApplicationException.VOTE_PAPER_NOT_FOUND); List registeredVoteChoices = loadVoteChoicePort.loadRegisteredVoteChoice(votePaperId); Optional registeredVote = loadVotePort.loadVoteByVoterAndVotePaperId(user.getUsername(), votePaperId); diff --git a/src/main/java/com/tune_fun/v1/vote/application/service/RegisterVoteChoiceService.java b/src/main/java/com/tune_fun/v1/vote/application/service/RegisterVoteChoiceService.java index f9751083..6d32e992 100644 --- a/src/main/java/com/tune_fun/v1/vote/application/service/RegisterVoteChoiceService.java +++ b/src/main/java/com/tune_fun/v1/vote/application/service/RegisterVoteChoiceService.java @@ -16,7 +16,7 @@ import java.util.Set; -import static com.tune_fun.v1.common.response.MessageCode.*; +import static com.tune_fun.v1.common.response.MessageCode.VOTE_PAPER_NOT_FOUND; import static com.tune_fun.v1.vote.domain.value.VotePaperOption.DENY_ADD_CHOICES; import static java.util.Collections.singleton; @@ -36,7 +36,7 @@ public class RegisterVoteChoiceService implements RegisterVoteChoiceUseCase { @Override public void registerVoteChoice(final Long votePaperId, final VotePaperCommands.Offer offer, final User user) { RegisteredVotePaper registeredVotePaper = loadVotePaperPort.loadRegisteredVotePaper(votePaperId) - .orElseThrow(() -> new CommonApplicationException(VOTE_PAPER_NOT_FOUND)); + .orElseThrow(CommonApplicationException.VOTE_PAPER_NOT_FOUND); validateVotePaperOption(registeredVotePaper); validateRegisteredVotePaper(votePaperId, user); @@ -47,12 +47,12 @@ public void registerVoteChoice(final Long votePaperId, final VotePaperCommands.O private static void validateVotePaperOption(RegisteredVotePaper registeredVotePaper) { if (DENY_ADD_CHOICES.equals(registeredVotePaper.option())) - throw new CommonApplicationException(VOTE_POLICY_ONLY_REGISTER_CHOICE_ON_ALLOW_ADD_CHOICES_OPTION); + throw CommonApplicationException.VOTE_POLICY_ONLY_REGISTER_CHOICE_ON_ALLOW_ADD_CHOICES_OPTION; } public void validateRegisteredVotePaper(Long votePaperId, User user) { if (loadVoteChoicePort.loadVoteChoiceByUsername(votePaperId, user.getUsername()).isPresent()) - throw new CommonApplicationException(VOTE_POLICY_ONE_VOTE_CHOICE_PER_USER_ON_VOTE_PAPER); + throw CommonApplicationException.VOTE_POLICY_ONE_VOTE_CHOICE_PER_USER_ON_VOTE_PAPER; } } diff --git a/src/main/java/com/tune_fun/v1/vote/application/service/RegisterVotePaperService.java b/src/main/java/com/tune_fun/v1/vote/application/service/RegisterVotePaperService.java index 75b898c2..02a99db5 100644 --- a/src/main/java/com/tune_fun/v1/vote/application/service/RegisterVotePaperService.java +++ b/src/main/java/com/tune_fun/v1/vote/application/service/RegisterVotePaperService.java @@ -21,8 +21,6 @@ import java.util.Set; -import static com.tune_fun.v1.common.response.MessageCode.VOTE_POLICY_OFFERS_COUNT_SHOULD_BE_MORE_THAN_TWO; -import static com.tune_fun.v1.common.response.MessageCode.VOTE_POLICY_ONE_VOTE_PAPER_PER_USER; import static com.tune_fun.v1.vote.domain.value.VotePaperOption.DENY_ADD_CHOICES; @Slf4j @@ -67,12 +65,12 @@ public void register(final VotePaperCommands.Register command, final User user) private static void validateOffersCount(final VotePaperCommands.Register command) { if (DENY_ADD_CHOICES.equals(command.option()) && command.offers().size() < 2) - throw new CommonApplicationException(VOTE_POLICY_OFFERS_COUNT_SHOULD_BE_MORE_THAN_TWO); + throw CommonApplicationException.VOTE_POLICY_OFFERS_COUNT_SHOULD_BE_MORE_THAN_TWO; } public void validateRegistrableVotePaperCount(final User user) { if (loadVotePaperPort.loadRegisteredVotePaper(user.getUsername()).isPresent()) - throw new CommonApplicationException(VOTE_POLICY_ONE_VOTE_PAPER_PER_USER); + throw CommonApplicationException.VOTE_POLICY_ONE_VOTE_PAPER_PER_USER; } @Transactional diff --git a/src/main/java/com/tune_fun/v1/vote/application/service/RegisterVoteService.java b/src/main/java/com/tune_fun/v1/vote/application/service/RegisterVoteService.java index 7211fd4d..04a808fc 100644 --- a/src/main/java/com/tune_fun/v1/vote/application/service/RegisterVoteService.java +++ b/src/main/java/com/tune_fun/v1/vote/application/service/RegisterVoteService.java @@ -9,8 +9,6 @@ import org.springframework.security.core.userdetails.User; import org.springframework.stereotype.Service; -import static com.tune_fun.v1.common.response.MessageCode.VOTE_POLICY_ONE_VOTE_PER_USER; - @Service @UseCase @@ -23,7 +21,7 @@ public class RegisterVoteService implements RegisterVoteUseCase { @Override public void register(final Long votePaperId, final Long voteChoiceId, final User user) { if (loadVotePort.loadVoteByVoterAndVotePaperId(user.getUsername(), votePaperId).isPresent()) - throw new CommonApplicationException(VOTE_POLICY_ONE_VOTE_PER_USER); + throw CommonApplicationException.VOTE_POLICY_ONE_VOTE_PER_USER; saveVotePort.saveVote(voteChoiceId, user.getUsername()); } diff --git a/src/main/java/com/tune_fun/v1/vote/application/service/ScheduleVotePaperDeadlineService.java b/src/main/java/com/tune_fun/v1/vote/application/service/ScheduleVotePaperDeadlineService.java index 2b6f6a30..ad228df6 100644 --- a/src/main/java/com/tune_fun/v1/vote/application/service/ScheduleVotePaperDeadlineService.java +++ b/src/main/java/com/tune_fun/v1/vote/application/service/ScheduleVotePaperDeadlineService.java @@ -5,7 +5,6 @@ import com.tune_fun.v1.account.domain.value.NotificationApprovedDevice; import com.tune_fun.v1.common.exception.CommonApplicationException; import com.tune_fun.v1.common.stereotype.UseCase; -import com.tune_fun.v1.common.response.MessageCode; import com.tune_fun.v1.vote.application.port.input.usecase.ScheduleVotePaperDeadlineUseCase; import com.tune_fun.v1.vote.application.port.output.SendVoteNotificationPort; import com.tune_fun.v1.vote.domain.behavior.SendVotePaperEndNotification; @@ -46,7 +45,7 @@ public void scheduleVotePaperDeadlineAction(VotePaperDeadlineEvent event) { try { sendVotePaperEndNotification(event); } catch (FirebaseMessagingException e) { - throw new CommonApplicationException(MessageCode.ERROR); + throw CommonApplicationException.ERROR; } }, deadlineInstant); diff --git a/src/main/java/com/tune_fun/v1/vote/application/service/UpdateVotePaperDeliveryDateService.java b/src/main/java/com/tune_fun/v1/vote/application/service/UpdateVotePaperDeliveryDateService.java index 7073e991..4057b220 100644 --- a/src/main/java/com/tune_fun/v1/vote/application/service/UpdateVotePaperDeliveryDateService.java +++ b/src/main/java/com/tune_fun/v1/vote/application/service/UpdateVotePaperDeliveryDateService.java @@ -14,8 +14,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.tune_fun.v1.common.response.MessageCode.VOTE_PAPER_NOT_FOUND; -import static com.tune_fun.v1.common.response.MessageCode.VOTE_POLICY_ONLY_AUTHOR_CAN_UPDATE_DELIVERY_DATE; import static java.time.LocalDateTime.now; @Service @@ -32,13 +30,13 @@ public class UpdateVotePaperDeliveryDateService implements UpdateVotePaperDelive @Override public void updateDeliveryDate(final Long votePaperId, final VotePaperCommands.UpdateDeliveryDate command, final User user) { RegisteredVotePaper registeredVotePaper = loadVotePaperPort.loadRegisteredVotePaper(votePaperId) - .orElseThrow(() -> new CommonApplicationException(VOTE_PAPER_NOT_FOUND)); + .orElseThrow(CommonApplicationException.VOTE_PAPER_NOT_FOUND); if (!registeredVotePaper.isAuthor(user.getUsername())) - throw new CommonApplicationException(VOTE_POLICY_ONLY_AUTHOR_CAN_UPDATE_DELIVERY_DATE); + throw CommonApplicationException.VOTE_POLICY_ONLY_AUTHOR_CAN_UPDATE_DELIVERY_DATE; if (!registeredVotePaper.isValidDeliveryAt(now(), command.deliveryAt())) - throw new CommonApplicationException(VOTE_POLICY_ONLY_AUTHOR_CAN_UPDATE_DELIVERY_DATE); + throw CommonApplicationException.VOTE_POLICY_ONLY_AUTHOR_CAN_UPDATE_DELIVERY_DATE; RegisteredVotePaper updatedVotePaper = updateDeliveryAtPort.updateDeliveryAt(votePaperId, command.deliveryAt()); diff --git a/src/main/java/com/tune_fun/v1/vote/application/service/UpdateVotePaperVideoUrlService.java b/src/main/java/com/tune_fun/v1/vote/application/service/UpdateVotePaperVideoUrlService.java index 76713909..5556a3f1 100644 --- a/src/main/java/com/tune_fun/v1/vote/application/service/UpdateVotePaperVideoUrlService.java +++ b/src/main/java/com/tune_fun/v1/vote/application/service/UpdateVotePaperVideoUrlService.java @@ -13,9 +13,6 @@ import org.springframework.security.core.userdetails.User; import org.springframework.stereotype.Service; -import static com.tune_fun.v1.common.response.MessageCode.VOTE_PAPER_NOT_FOUND; -import static com.tune_fun.v1.common.response.MessageCode.VOTE_POLICY_ONLY_AUTHOR_CAN_UPDATE_VIDEO_URL; - @Service @UseCase @RequiredArgsConstructor @@ -30,10 +27,10 @@ public class UpdateVotePaperVideoUrlService implements UpdateVotePaperVideoUrlUs @Override public void updateVideoUrl(final Long votePaperId, final VotePaperCommands.UpdateVideoUrl command, final User user) { RegisteredVotePaper registeredVotePaper = loadVotePaperPort.loadRegisteredVotePaper(votePaperId) - .orElseThrow(() -> new CommonApplicationException(VOTE_PAPER_NOT_FOUND)); + .orElseThrow(CommonApplicationException.VOTE_PAPER_NOT_FOUND); if (!registeredVotePaper.isAuthor(user.getUsername())) - throw new CommonApplicationException(VOTE_POLICY_ONLY_AUTHOR_CAN_UPDATE_VIDEO_URL); + throw CommonApplicationException.VOTE_POLICY_ONLY_AUTHOR_CAN_UPDATE_VIDEO_URL; RegisteredVotePaper updatedVotePaper = updateVideoUrlPort.updateVideoUrl(votePaperId, command.videoUrl());