refactor: Exception Method 한 곳으로 이동
This commit is contained in:
@@ -22,7 +22,6 @@ public enum ErrorCode {
|
||||
EMAIL_NOT_FOUND(NOT_FOUND, "해당 이메일을 찾을 수 없습니다."),
|
||||
MOVIE_NOT_FOUND(NOT_FOUND, "해당 제목의 영화를 찾을 수 없습니다."),
|
||||
REFRESH_TOKEN_NOT_FOUND(NOT_FOUND, "리프레쉬 토큰을 찾을 수 없습니다."),
|
||||
PAYMENT_ID_NOT_FOUND(NOT_FOUND, "결제 내역을 찾을 수 없습니다."),
|
||||
|
||||
/* 409 CONFLICT : Resource 의 현재 상태와 충돌. 보통 중복된 데이터 존재 */
|
||||
DUPLICATE_EMAIL(CONFLICT, "이메일이 이미 존재합니다."),
|
||||
@@ -61,10 +60,6 @@ public enum ErrorCode {
|
||||
throw new TicketingException(REFRESH_TOKEN_NOT_FOUND);
|
||||
}
|
||||
|
||||
public static TicketingException throwPaymentIdNotFound() {
|
||||
throw new TicketingException(PAYMENT_ID_NOT_FOUND);
|
||||
}
|
||||
|
||||
/* 409 CONFLICT : Resource 의 현재 상태와 충돌. 보통 중복된 데이터 존재 */
|
||||
public static TicketingException throwDuplicateEmail() {
|
||||
throw new TicketingException(DUPLICATE_EMAIL);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.ticketing.server.movie.service;
|
||||
|
||||
import static com.ticketing.server.global.exception.ErrorCode.MOVIE_NOT_FOUND;
|
||||
|
||||
import com.ticketing.server.global.exception.TicketingException;
|
||||
import com.ticketing.server.global.exception.ErrorCode;
|
||||
import com.ticketing.server.movie.domain.Movie;
|
||||
import com.ticketing.server.movie.domain.MovieTime;
|
||||
import com.ticketing.server.movie.domain.repository.MovieRepository;
|
||||
@@ -22,28 +20,24 @@ import org.springframework.stereotype.Service;
|
||||
@Slf4j
|
||||
public class MovieTimeServiceImpl implements MovieTimeService {
|
||||
|
||||
private final MovieRepository movieRepository;
|
||||
private final MovieRepository movieRepository;
|
||||
|
||||
private final MovieTimeRepository movieTimeRepository;
|
||||
private final MovieTimeRepository movieTimeRepository;
|
||||
|
||||
@Override
|
||||
public List<MovieTimeDto> getMovieTimes(String title, LocalDate runningDate) {
|
||||
Movie movie = movieRepository.findByTitle(title)
|
||||
.orElseThrow(MovieTimeServiceImpl::throwMovieNotFound);
|
||||
@Override
|
||||
public List<MovieTimeDto> getMovieTimes(String title, LocalDate runningDate) {
|
||||
Movie movie = movieRepository.findByTitle(title)
|
||||
.orElseThrow(ErrorCode::throwMovieNotFound);
|
||||
|
||||
LocalDateTime startOfDay = runningDate.atStartOfDay().plusHours(6);
|
||||
LocalDateTime endOfDay = startOfDay.plusDays(1);
|
||||
LocalDateTime startOfDay = runningDate.atStartOfDay().plusHours(6);
|
||||
LocalDateTime endOfDay = startOfDay.plusDays(1);
|
||||
|
||||
List<MovieTime> movieTimes = movieTimeRepository.findValidMovieTimes(movie, startOfDay, endOfDay);
|
||||
List<MovieTime> movieTimes = movieTimeRepository.findValidMovieTimes(movie, startOfDay, endOfDay);
|
||||
|
||||
return movieTimes.stream()
|
||||
.map(MovieTimeDto::from)
|
||||
.collect(Collectors.toList());
|
||||
return movieTimes.stream()
|
||||
.map(MovieTimeDto::from)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
private static RuntimeException throwMovieNotFound() {
|
||||
throw new TicketingException(MOVIE_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package com.ticketing.server.user.domain;
|
||||
|
||||
import static com.ticketing.server.global.exception.ErrorCode.DELETED_EMAIL;
|
||||
import static com.ticketing.server.global.exception.ErrorCode.MISMATCH_PASSWORD;
|
||||
|
||||
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
||||
import com.ticketing.server.global.exception.TicketingException;
|
||||
import com.ticketing.server.global.exception.ErrorCode;
|
||||
import com.ticketing.server.global.validator.constraints.Phone;
|
||||
import com.ticketing.server.user.service.dto.ChangePasswordDTO;
|
||||
import com.ticketing.server.user.service.dto.DeleteUserDTO;
|
||||
@@ -62,7 +59,7 @@ public class User extends AbstractEntity {
|
||||
|
||||
public User delete(DeleteUserDTO deleteUser) {
|
||||
if (isDeleted) {
|
||||
throw new TicketingException(DELETED_EMAIL);
|
||||
throw ErrorCode.throwDeletedEmail();
|
||||
}
|
||||
|
||||
checkPassword(deleteUser);
|
||||
@@ -81,7 +78,7 @@ public class User extends AbstractEntity {
|
||||
|
||||
public void checkPassword(PasswordMatches passwordMatches) {
|
||||
if (!passwordMatches.passwordMatches(password)) {
|
||||
throw new TicketingException(MISMATCH_PASSWORD);
|
||||
throw ErrorCode.throwMismatchPassword();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package com.ticketing.server.user.service;
|
||||
|
||||
import static com.ticketing.server.global.exception.ErrorCode.REFRESH_TOKEN_NOT_FOUND;
|
||||
import static com.ticketing.server.global.exception.ErrorCode.TOKEN_TYPE;
|
||||
import static com.ticketing.server.global.exception.ErrorCode.UNAVAILABLE_REFRESH_TOKEN;
|
||||
|
||||
import com.ticketing.server.global.exception.TicketingException;
|
||||
import com.ticketing.server.global.exception.ErrorCode;
|
||||
import com.ticketing.server.global.redis.RefreshRedisRepository;
|
||||
import com.ticketing.server.global.redis.RefreshToken;
|
||||
import com.ticketing.server.global.security.jwt.JwtProperties;
|
||||
@@ -63,11 +59,11 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
|
||||
// Redis 에 토큰이 있는지 검증
|
||||
RefreshToken findTokenEntity = refreshRedisRepository.findByEmail(authentication.getName())
|
||||
.orElseThrow(() -> new TicketingException(REFRESH_TOKEN_NOT_FOUND));
|
||||
.orElseThrow(ErrorCode::throwRefreshTokenNotFound);
|
||||
|
||||
// redis 토큰과 input 토큰이 일치한지 확인
|
||||
if (!refreshToken.equals(findTokenEntity.getToken())) {
|
||||
throw new TicketingException(UNAVAILABLE_REFRESH_TOKEN);
|
||||
throw ErrorCode.throwUnavailableRefreshToken();
|
||||
}
|
||||
|
||||
// 토큰 발급
|
||||
@@ -94,7 +90,7 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
if (StringUtils.hasText(bearerToken) && jwtProperties.hasTokenStartsWith(bearerToken)) {
|
||||
return bearerToken.substring(7);
|
||||
}
|
||||
throw new TicketingException(TOKEN_TYPE);
|
||||
throw ErrorCode.throwTokenType();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.ticketing.server.user.service;
|
||||
|
||||
import static com.ticketing.server.global.exception.ErrorCode.EMAIL_NOT_FOUND;
|
||||
|
||||
import com.ticketing.server.global.exception.TicketingException;
|
||||
import com.ticketing.server.global.exception.ErrorCode;
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import com.ticketing.server.user.domain.repository.UserRepository;
|
||||
import java.util.Collections;
|
||||
@@ -23,7 +21,7 @@ public class CustomUserDetailsService implements UserDetailsService {
|
||||
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
|
||||
return userRepository.findByEmailAndIsDeletedFalse(email)
|
||||
.map(this::createUserDetails)
|
||||
.orElseThrow(() -> new TicketingException(EMAIL_NOT_FOUND));
|
||||
.orElseThrow(ErrorCode::throwEmailNotFound);
|
||||
}
|
||||
|
||||
private UserDetails createUserDetails(User user) {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.ticketing.server.user.service;
|
||||
|
||||
import static com.ticketing.server.global.exception.ErrorCode.DUPLICATE_EMAIL;
|
||||
import static com.ticketing.server.global.exception.ErrorCode.EMAIL_NOT_FOUND;
|
||||
|
||||
import com.ticketing.server.global.exception.TicketingException;
|
||||
import com.ticketing.server.global.exception.ErrorCode;
|
||||
import com.ticketing.server.user.api.PaymentClient;
|
||||
import com.ticketing.server.user.api.dto.request.SimplePaymentsRequest;
|
||||
import com.ticketing.server.user.api.dto.response.SimplePaymentsResponse;
|
||||
@@ -40,7 +37,7 @@ public class UserServiceImpl implements UserService {
|
||||
return userRepository.save(signUpDto.toUser());
|
||||
}
|
||||
|
||||
throw new TicketingException(DUPLICATE_EMAIL);
|
||||
throw ErrorCode.throwDuplicateEmail();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,7 +57,7 @@ public class UserServiceImpl implements UserService {
|
||||
@Override
|
||||
public User findByEmail(String email) {
|
||||
return userRepository.findByEmail(email)
|
||||
.orElseThrow(UserServiceImpl::throwEmailNotFound);
|
||||
.orElseThrow(ErrorCode::throwEmailNotFound);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,11 +70,7 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
private User findNotDeletedUserByEmail(String email) {
|
||||
return userRepository.findByEmailAndIsDeletedFalse(email)
|
||||
.orElseThrow(UserServiceImpl::throwEmailNotFound);
|
||||
}
|
||||
|
||||
private static RuntimeException throwEmailNotFound() {
|
||||
throw new TicketingException(EMAIL_NOT_FOUND);
|
||||
.orElseThrow(ErrorCode::throwEmailNotFound);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user