From 6a5990ff2811281e9a4917048c6da4aeffdba625 Mon Sep 17 00:00:00 2001 From: habin Date: Wed, 3 Jul 2024 09:51:44 +0900 Subject: [PATCH 1/2] fix(common) exception MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: CommonApplicationException StackTrace 제외 처리 --- .../exception/CommonApplicationException.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) 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 cf90e55..e6de5b0 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,53 @@ public class CommonApplicationException extends RuntimeException implements Supp private MessageCode messageCode; + 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 this; + } + @Override public CommonApplicationException get() { return this; From 46770e6e7f589eaf3c8e6125c16e5abc2517c6cc Mon Sep 17 00:00:00 2001 From: habin Date: Wed, 3 Jul 2024 10:21:20 +0900 Subject: [PATCH 2/2] fix(common) exception MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: CommonApplicationException 예외 캐싱 적용 --- .../account/adapter/input/rest/LogoutController.java | 2 +- .../input/security/JwtAuthenticationFilter.java | 2 +- .../persistence/jwt/JwtTokenPersistenceAdapter.java | 10 +++++----- .../service/CheckUsernameDuplicateService.java | 4 +--- .../application/service/CustomUserDetailsService.java | 4 +--- .../application/service/FindUsernameService.java | 4 +--- .../v1/account/application/service/LoginService.java | 6 ++---- .../account/application/service/RegisterService.java | 4 +--- .../service/SendForgotPasswordOtpService.java | 3 +-- .../application/service/UpdateNicknameService.java | 4 +--- .../service/email/CheckEmailDuplicateService.java | 4 +--- .../service/email/CheckEmailVerifiedService.java | 7 ++----- .../service/email/RegisterEmailService.java | 7 ++----- .../application/service/email/VerifyEmailService.java | 3 +-- .../handler/OAuth2AuthenticationSuccessHandler.java | 7 +++---- .../v1/common/aspect/DistributionLockAspect.java | 8 ++------ .../com/tune_fun/v1/common/aspect/RateLimitAspect.java | 3 +-- .../v1/common/config/PermissionPolicyEvaluator.java | 8 +++----- .../common/exception/CommonApplicationException.java | 8 +++++++- .../tune_fun/v1/common/rate/TokenBucketResolver.java | 2 +- .../interaction/application/service/FollowService.java | 7 ++----- .../application/service/LikeVotePaperService.java | 4 +--- .../application/service/UnFollowService.java | 7 ++----- .../output/persistence/OtpPersistenceAdapter.java | 7 +++---- .../v1/otp/adapter/output/persistence/OtpType.java | 4 +--- .../v1/otp/application/service/ResendOtpService.java | 3 +-- .../v1/otp/application/service/VerifyOtpService.java | 4 +--- .../application/service/DeleteVotePaperService.java | 7 ++----- .../vote/application/service/GetVotePaperService.java | 4 +--- .../application/service/RegisterVoteChoiceService.java | 8 ++++---- .../application/service/RegisterVotePaperService.java | 6 ++---- .../vote/application/service/RegisterVoteService.java | 4 +--- .../service/ScheduleVotePaperDeadlineService.java | 3 +-- .../service/UpdateVotePaperDeliveryDateService.java | 8 +++----- .../service/UpdateVotePaperVideoUrlService.java | 7 ++----- 35 files changed, 65 insertions(+), 118 deletions(-) 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 8709449..5e2df4e 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 d61c790..9c102ed 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 5e99373..91cdf7a 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 29002e0..cf325a5 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 dded418..d3bd92f 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 87179b2..11b053d 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 2940374..c44442b 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 e446474..4b0750c 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 be861f8..1e81383 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 4147916..95a1620 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 e6f5c92..1dfe74f 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 1449a5a..5bfe7c5 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 cba8050..f08a3e0 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 eba85cb..2561676 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 c61cb5c..9f0f466 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 40e17c8..880dbb8 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 d2c21c6..6aa6f23 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 30b0181..e851dc3 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 e6de5b0..12b1d8e 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 @@ -19,6 +19,12 @@ 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); @@ -63,7 +69,7 @@ public class CommonApplicationException extends RuntimeException implements Supp @Override public synchronized Throwable fillInStackTrace() { - return this; + return MessageCode.ERROR.equals(messageCode) ? super.fillInStackTrace() : this; } @Override 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 ff7835d..fb26943 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 c2f835d..f9853d1 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 78e3a1a..9a5e0fc 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 b4c5ae7..a61c30f 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 5a3c922..8f739cd 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 0a42f4f..8dee315 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 ead1620..cebf244 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 40832cf..6d41dcd 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 2f01783..eca18ca 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 fd39dfa..cb6e9e2 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 f975108..6d32e99 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 75b898c..02a99db 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 7211fd4..04a808f 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 2b6f6a3..ad228df 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 7073e99..4057b22 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 7671390..5556a3f 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());