From 8ed21ce744711e16486f5675968f1232bc0d4ad4 Mon Sep 17 00:00:00 2001 From: CYY1007 Date: Fri, 6 Oct 2023 01:53:08 +0900 Subject: [PATCH 1/5] =?UTF-8?q?:recycle:=20Refactor=20:=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=ED=95=B8=EB=93=A4=EB=9F=AC=20=EB=8C=80=EA=B7=9C?= =?UTF-8?q?=EB=AA=A8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradlew.bat | 4 +- .../FeignClientExceptionErrorDecoder.java | 11 +- .../server/apiPayload/code/BaseCode.java | 8 + .../code/CommonStatus.java} | 57 +++--- .../server/apiPayload/code/Reason.java | 21 +++ .../apiPayload/exception/ExceptionAdvice.java | 163 ++++++++++++++++++ .../exception/base/GeneralException.java | 21 +++ .../handler/AuthNumberException.java | 10 ++ .../handler/CustomFeignClientException.java | 13 ++ .../handler/JwtAuthenticationException.java | 12 ++ .../exception/handler/MemberException.java | 12 ++ .../exception/handler/RecipeException.java | 11 ++ .../handler/RefreshTokenExceptionHandler.java | 11 ++ .../exception/handler/RootException.java | 11 ++ .../apiPayload/reponse/ResponseDto.java | 45 +++++ .../server/auth/filter/JwtRequestFilter.java | 8 +- .../auth/handler/JwtAccessDeniedHandler.java | 6 +- .../handler/JwtAuthenticationEntryPoint.java | 6 +- .../JwtAuthenticationExceptionHandler.java | 10 +- .../Resolver/AuthMemberArgumentResolver.java | 6 +- .../server/auth/provider/TokenProvider.java | 22 +-- .../zipdabang/server/base/ResponseDto.java | 80 ++++----- .../base/exception/ExceptionHandler.java | 147 ++++++++-------- .../base/exception/GeneralException.java | 100 +++++------ .../handler/AuthNumberException.java | 10 -- .../handler/CustomFeignClientException.java | 12 -- .../handler/JwtAuthenticationException.java | 11 -- .../exception/handler/MemberException.java | 10 -- .../exception/handler/RecipeException.java | 10 -- .../handler/RefreshTokenExceptionHandler.java | 10 -- .../base/exception/handler/RootException.java | 10 -- .../server/converter/MemberConverter.java | 6 +- .../server/converter/RecipeConverter.java | 14 +- .../server/converter/SmsConverter.java | 6 +- .../converter/common/BaseConverter.java | 8 +- .../redis/service/RedisServiceImpl.java | 16 +- .../serviceImpl/MemberServiceImpl.java | 33 ++-- .../serviceImpl/RecipeServiceImpl.java | 61 ++++--- .../service/serviceImpl/RootServiceImpl.java | 14 +- .../server/sms/dto/SmsResponseDto.java | 5 +- .../service/serviceImpl/SmsServiceImpl.java | 32 ++-- .../validation/annotation/ExistNickname.java | 18 ++ .../validator/CheckDeregisterValidator.java | 5 +- .../validator/CheckPageValidator.java | 5 +- .../validator/CheckTempMemberValidator.java | 4 +- .../ExistMemberRequestBodyValidator.java | 5 +- .../validator/ExistNicknameValidator.java | 36 ++++ .../validator/ExistNotificationValidator.java | 4 +- .../ExistRecipeCategoryValidator.java | 4 +- .../web/controller/MarketController.java | 2 +- .../web/controller/MemberRestController.java | 16 +- .../web/controller/RecipeRestController.java | 62 +++---- .../server/web/controller/RootController.java | 8 +- .../web/dto/requestDto/MemberRequestDto.java | 3 +- .../web/dto/requestDto/RecipeRequestDto.java | 3 +- src/main/resources/application.yml | 8 +- 56 files changed, 768 insertions(+), 478 deletions(-) create mode 100644 src/main/java/zipdabang/server/apiPayload/code/BaseCode.java rename src/main/java/zipdabang/server/{base/Code.java => apiPayload/code/CommonStatus.java} (81%) create mode 100644 src/main/java/zipdabang/server/apiPayload/code/Reason.java create mode 100644 src/main/java/zipdabang/server/apiPayload/exception/ExceptionAdvice.java create mode 100644 src/main/java/zipdabang/server/apiPayload/exception/base/GeneralException.java create mode 100644 src/main/java/zipdabang/server/apiPayload/exception/handler/AuthNumberException.java create mode 100644 src/main/java/zipdabang/server/apiPayload/exception/handler/CustomFeignClientException.java create mode 100644 src/main/java/zipdabang/server/apiPayload/exception/handler/JwtAuthenticationException.java create mode 100644 src/main/java/zipdabang/server/apiPayload/exception/handler/MemberException.java create mode 100644 src/main/java/zipdabang/server/apiPayload/exception/handler/RecipeException.java create mode 100644 src/main/java/zipdabang/server/apiPayload/exception/handler/RefreshTokenExceptionHandler.java create mode 100644 src/main/java/zipdabang/server/apiPayload/exception/handler/RootException.java create mode 100644 src/main/java/zipdabang/server/apiPayload/reponse/ResponseDto.java delete mode 100644 src/main/java/zipdabang/server/base/exception/handler/AuthNumberException.java delete mode 100644 src/main/java/zipdabang/server/base/exception/handler/CustomFeignClientException.java delete mode 100644 src/main/java/zipdabang/server/base/exception/handler/JwtAuthenticationException.java delete mode 100644 src/main/java/zipdabang/server/base/exception/handler/MemberException.java delete mode 100644 src/main/java/zipdabang/server/base/exception/handler/RecipeException.java delete mode 100644 src/main/java/zipdabang/server/base/exception/handler/RefreshTokenExceptionHandler.java delete mode 100644 src/main/java/zipdabang/server/base/exception/handler/RootException.java create mode 100644 src/main/java/zipdabang/server/validation/annotation/ExistNickname.java create mode 100644 src/main/java/zipdabang/server/validation/validator/ExistNicknameValidator.java diff --git a/gradlew.bat b/gradlew.bat index 93e3f59..7fb9fdd 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -79,8 +79,8 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar if %ERRORLEVEL% equ 0 goto mainEnd :fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return commonStatus instead of +rem the _cmd.exe /c_ return commonStatus! set EXIT_CODE=%ERRORLEVEL% if %EXIT_CODE% equ 0 set EXIT_CODE=1 if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% diff --git a/src/main/java/zipdabang/server/FeignClient/exception/FeignClientExceptionErrorDecoder.java b/src/main/java/zipdabang/server/FeignClient/exception/FeignClientExceptionErrorDecoder.java index e0fb9e0..b00e6f2 100644 --- a/src/main/java/zipdabang/server/FeignClient/exception/FeignClientExceptionErrorDecoder.java +++ b/src/main/java/zipdabang/server/FeignClient/exception/FeignClientExceptionErrorDecoder.java @@ -4,12 +4,9 @@ import feign.codec.ErrorDecoder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.handler.CustomFeignClientException; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; +import zipdabang.server.apiPayload.code.CommonStatus; +import zipdabang.server.apiPayload.exception.handler.CustomFeignClientException; public class FeignClientExceptionErrorDecoder implements ErrorDecoder { @@ -19,10 +16,10 @@ public class FeignClientExceptionErrorDecoder implements ErrorDecoder { public Exception decode(String methodKey, Response response) { if (response.status() >= 400 && response.status() <= 499) { logger.error("{}번 에러 발생 : {}", response.status(), response.reason()); - return new CustomFeignClientException(Code.FEIGN_CLIENT_ERROR_400); + return new CustomFeignClientException(CommonStatus.FEIGN_CLIENT_ERROR_400); } else { logger.error("500번대 에러 발생 : {}", response.reason()); - return new CustomFeignClientException(Code.FEIGN_CLIENT_ERROR_500); + return new CustomFeignClientException(CommonStatus.FEIGN_CLIENT_ERROR_500); } } } diff --git a/src/main/java/zipdabang/server/apiPayload/code/BaseCode.java b/src/main/java/zipdabang/server/apiPayload/code/BaseCode.java new file mode 100644 index 0000000..4ca40d6 --- /dev/null +++ b/src/main/java/zipdabang/server/apiPayload/code/BaseCode.java @@ -0,0 +1,8 @@ +package zipdabang.server.apiPayload.code; + +public interface BaseCode { + + public Reason getReason(); + + public Reason getReasonHttpStatus(); +} diff --git a/src/main/java/zipdabang/server/base/Code.java b/src/main/java/zipdabang/server/apiPayload/code/CommonStatus.java similarity index 81% rename from src/main/java/zipdabang/server/base/Code.java rename to src/main/java/zipdabang/server/apiPayload/code/CommonStatus.java index f1a201a..1ce29b8 100644 --- a/src/main/java/zipdabang/server/base/Code.java +++ b/src/main/java/zipdabang/server/apiPayload/code/CommonStatus.java @@ -1,17 +1,13 @@ -package zipdabang.server.base; +package zipdabang.server.apiPayload.code; + +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; -import zipdabang.server.base.exception.GeneralException; - -import java.util.Arrays; -import java.util.Optional; -import java.util.function.Predicate; @Getter -@RequiredArgsConstructor -public enum Code { +@AllArgsConstructor +public enum CommonStatus implements BaseCode { OK(HttpStatus.OK,2000, "Ok"), OAUTH_LOGIN(HttpStatus.OK,2050, "로그인 입니다."), @@ -131,39 +127,28 @@ public enum Code { //INTERNAL_SERVER_ERROR FEIGN_CLIENT_ERROR_500(HttpStatus.OK, 5001, "Inter server Error in feign client"); - - private final HttpStatus httpStatus; private final Integer code; private final String message; - public String getMessage(Throwable e) { - return this.getMessage(this.getMessage() + " - " + e.getMessage()); - // 결과 예시 - "Validation error - Reason why it isn't valid" + @Override + public Reason getReason() { + return Reason.builder() + .message(message) + .code(code) + .isSuccess((code >= 2000 && code < 3000) ? true : false) + .build(); } - public String getMessage(String message) { - return Optional.ofNullable(message) - .filter(Predicate.not(String::isBlank)) - .orElse(this.getMessage()); + @Override + public Reason getReasonHttpStatus() { + return Reason.builder() + .message(message) + .code(code) + .isSuccess((code >= 2000 && code < 3000) ? true : false) + .httpStatus(httpStatus) + .build() + ; } - public static Code valueOf(HttpStatus httpStatus) { - if (httpStatus == null) { - throw new GeneralException("HttpStatus is null."); - } - - return Arrays.stream(values()) - .filter(errorCode -> errorCode.getHttpStatus() == httpStatus) - .findFirst() - .orElseGet(() -> { - if (httpStatus.is4xxClientError()) { - return Code.BAD_REQUEST; - } else if (httpStatus.is5xxServerError()) { - return Code.INTERNAL_ERROR; - } else { - return Code.OK; - } - }); - } } diff --git a/src/main/java/zipdabang/server/apiPayload/code/Reason.java b/src/main/java/zipdabang/server/apiPayload/code/Reason.java new file mode 100644 index 0000000..8266db0 --- /dev/null +++ b/src/main/java/zipdabang/server/apiPayload/code/Reason.java @@ -0,0 +1,21 @@ +package zipdabang.server.apiPayload.code; + +import lombok.Builder; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +import java.util.HashMap; + +@Getter +@Builder +public class Reason { + + private HttpStatus httpStatus; + + private final boolean isSuccess; + private final Integer code; + private final String message; + private final HashMapresult; + + public boolean getIsSuccess(){return isSuccess;} +} diff --git a/src/main/java/zipdabang/server/apiPayload/exception/ExceptionAdvice.java b/src/main/java/zipdabang/server/apiPayload/exception/ExceptionAdvice.java new file mode 100644 index 0000000..7feecf8 --- /dev/null +++ b/src/main/java/zipdabang/server/apiPayload/exception/ExceptionAdvice.java @@ -0,0 +1,163 @@ +package zipdabang.server.apiPayload.exception; + +import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.core.userdetails.User; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.context.request.ServletWebRequest; +import org.springframework.web.context.request.WebRequest; +import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; +import zipdabang.server.apiPayload.code.CommonStatus; +import zipdabang.server.apiPayload.code.Reason; +import zipdabang.server.apiPayload.exception.base.GeneralException; +import zipdabang.server.apiPayload.reponse.ResponseDto; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +@Slf4j +@RestControllerAdvice(annotations = {RestController.class}) +public class ExceptionAdvice extends ResponseEntityExceptionHandler { + + + @org.springframework.web.bind.annotation.ExceptionHandler + public ResponseEntity validation(ConstraintViolationException e, WebRequest request) { + String errorMessage = e.getConstraintViolations().stream() + .map(constraintViolation -> constraintViolation.getMessage()) + .findFirst() + .orElseThrow(() -> new RuntimeException("ConstraintViolationException 추출 도중 에러 발생")); + + return handleExceptionInternalConstraint(e, CommonStatus.valueOf(errorMessage),HttpHeaders.EMPTY,request); + } + + @NotNull + @Override + public ResponseEntity handleMethodArgumentNotValid( + MethodArgumentNotValidException e, HttpHeaders headers, HttpStatus status, WebRequest request) { + + Map errors = new LinkedHashMap<>(); + + e.getBindingResult().getFieldErrors().stream() + .forEach(fieldError -> { + String fieldName = fieldError.getField(); + String errorMessage = Optional.ofNullable(fieldError.getDefaultMessage()).orElse(""); + errors.merge(fieldName, errorMessage, (existingErrorMessage, newErrorMessage) -> existingErrorMessage + ", " + newErrorMessage); + }); + + return handleExceptionInternalArgs(e,HttpHeaders.EMPTY,CommonStatus.valueOf("BAD_REQUEST"),request,errors); + } + + @org.springframework.web.bind.annotation.ExceptionHandler + public ResponseEntity exception(Exception e, WebRequest request) { + e.printStackTrace(); + + return handleExceptionInternalFalse(e, CommonStatus.INTERNAL_ERROR, HttpHeaders.EMPTY, CommonStatus.INTERNAL_ERROR.getHttpStatus(),request, e.getMessage()); + } + + @ExceptionHandler(value = GeneralException.class) + public ResponseEntity onThrowException(GeneralException generalException, + @AuthenticationPrincipal User user, HttpServletRequest request) { + getExceptionStackTrace(generalException, user, request); + Reason errorReasonHttpStatus = generalException.getErrorReasonHttpStatus(); + return handleExceptionInternal(generalException,errorReasonHttpStatus,null,request); + } + +// protected ResponseEntity handleExceptionInternal(Exception ex, Reason reason, +// HttpHeaders headers, HttpServletRequest request) { +// return handleExceptionInternal(ex, reason, headers, request); +// } + + +// private ResponseEntity handleExceptionInternal(Exception e, Reason errorReason, +// WebRequest request) { +// return handleExceptionInternal(e, errorReason, HttpHeaders.EMPTY, request); +// } + +// private ResponseEntity handleExceptionInternal(Exception e, CommonStatus commonStatus, +// WebRequest request) { +// return handleExceptionInternal(e, Reason, HttpHeaders.EMPTY, request); +// } + + private ResponseEntity handleExceptionInternal(Exception e, Reason reason, + HttpHeaders headers, HttpServletRequest request) { + + ResponseDto body = ResponseDto.onFailure(reason.getCode(),reason.getMessage(),null); +// e.printStackTrace(); + + WebRequest webRequest = new ServletWebRequest(request); + return super.handleExceptionInternal( + e, + body, + headers, + reason.getHttpStatus(), + webRequest + ); + } + + private ResponseEntity handleExceptionInternalFalse(Exception e, CommonStatus errorCommonStatus, + HttpHeaders headers, HttpStatus status, WebRequest request, String errorPoint) { + ResponseDto body = ResponseDto.onFailure(errorCommonStatus.getCode(),errorCommonStatus.getMessage(),errorPoint); + return super.handleExceptionInternal( + e, + body, + headers, + status, + request + ); + } + + private ResponseEntity handleExceptionInternalArgs(Exception e, HttpHeaders headers, CommonStatus errorCommonStatus, + WebRequest request, Map errorArgs) { + ResponseDto body = ResponseDto.onFailure(errorCommonStatus.getCode(),errorCommonStatus.getMessage(),errorArgs); + return super.handleExceptionInternal( + e, + body, + headers, + errorCommonStatus.getHttpStatus(), + request + ); + } + + private ResponseEntity handleExceptionInternalConstraint(Exception e, CommonStatus errorCommonStatus, + HttpHeaders headers, WebRequest request) { + ResponseDto body = ResponseDto.onFailure(errorCommonStatus.getCode(), errorCommonStatus.getMessage(), null); + return super.handleExceptionInternal( + e, + body, + headers, + errorCommonStatus.getHttpStatus(), + request + ); + } + + private void getExceptionStackTrace(Exception e, @AuthenticationPrincipal User user, + HttpServletRequest request) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + pw.append("\n==========================!!!ERROR TRACE!!!==========================\n"); + pw.append("uri: " + request.getRequestURI() + " " + request.getMethod() + "\n"); + if (user != null) { + pw.append("uid: " + user.getUsername() + "\n"); + } + pw.append(e.getMessage()); + pw.append("\n====================================================================="); + log.error(sw.toString()); + } +} diff --git a/src/main/java/zipdabang/server/apiPayload/exception/base/GeneralException.java b/src/main/java/zipdabang/server/apiPayload/exception/base/GeneralException.java new file mode 100644 index 0000000..049cddb --- /dev/null +++ b/src/main/java/zipdabang/server/apiPayload/exception/base/GeneralException.java @@ -0,0 +1,21 @@ +package zipdabang.server.apiPayload.exception.base; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import zipdabang.server.apiPayload.code.BaseCode; +import zipdabang.server.apiPayload.code.Reason; + +@Getter +@AllArgsConstructor +public class GeneralException extends RuntimeException { + + private BaseCode code; + + public Reason getErrorReason() { + return this.code.getReason(); + } + + public Reason getErrorReasonHttpStatus(){ + return this.code.getReasonHttpStatus(); + } +} diff --git a/src/main/java/zipdabang/server/apiPayload/exception/handler/AuthNumberException.java b/src/main/java/zipdabang/server/apiPayload/exception/handler/AuthNumberException.java new file mode 100644 index 0000000..977acb7 --- /dev/null +++ b/src/main/java/zipdabang/server/apiPayload/exception/handler/AuthNumberException.java @@ -0,0 +1,10 @@ +package zipdabang.server.apiPayload.exception.handler; + +import zipdabang.server.apiPayload.code.BaseCode; +import zipdabang.server.apiPayload.exception.base.GeneralException; + +public class AuthNumberException extends GeneralException { + public AuthNumberException(BaseCode errorCode) { + super(errorCode); + } +} diff --git a/src/main/java/zipdabang/server/apiPayload/exception/handler/CustomFeignClientException.java b/src/main/java/zipdabang/server/apiPayload/exception/handler/CustomFeignClientException.java new file mode 100644 index 0000000..dc763a6 --- /dev/null +++ b/src/main/java/zipdabang/server/apiPayload/exception/handler/CustomFeignClientException.java @@ -0,0 +1,13 @@ +package zipdabang.server.apiPayload.exception.handler; + +import zipdabang.server.apiPayload.code.BaseCode; +import zipdabang.server.apiPayload.code.CommonStatus; +import zipdabang.server.apiPayload.exception.base.GeneralException; + + +public class CustomFeignClientException extends GeneralException { + + public CustomFeignClientException(BaseCode errorCode){ + super(errorCode); + } +} diff --git a/src/main/java/zipdabang/server/apiPayload/exception/handler/JwtAuthenticationException.java b/src/main/java/zipdabang/server/apiPayload/exception/handler/JwtAuthenticationException.java new file mode 100644 index 0000000..3b889c2 --- /dev/null +++ b/src/main/java/zipdabang/server/apiPayload/exception/handler/JwtAuthenticationException.java @@ -0,0 +1,12 @@ +package zipdabang.server.apiPayload.exception.handler; + +import org.springframework.security.core.AuthenticationException; +import zipdabang.server.apiPayload.code.BaseCode; +import zipdabang.server.apiPayload.code.CommonStatus; + +public class JwtAuthenticationException extends AuthenticationException { + + public JwtAuthenticationException(CommonStatus code){ + super(code.name()); + } +} diff --git a/src/main/java/zipdabang/server/apiPayload/exception/handler/MemberException.java b/src/main/java/zipdabang/server/apiPayload/exception/handler/MemberException.java new file mode 100644 index 0000000..a29f449 --- /dev/null +++ b/src/main/java/zipdabang/server/apiPayload/exception/handler/MemberException.java @@ -0,0 +1,12 @@ +package zipdabang.server.apiPayload.exception.handler; + + +import zipdabang.server.apiPayload.code.BaseCode; +import zipdabang.server.apiPayload.code.CommonStatus; +import zipdabang.server.apiPayload.exception.base.GeneralException; + +public class MemberException extends GeneralException { + public MemberException(BaseCode errorCommonStatus) { + super(errorCommonStatus); + } +} diff --git a/src/main/java/zipdabang/server/apiPayload/exception/handler/RecipeException.java b/src/main/java/zipdabang/server/apiPayload/exception/handler/RecipeException.java new file mode 100644 index 0000000..8e131d6 --- /dev/null +++ b/src/main/java/zipdabang/server/apiPayload/exception/handler/RecipeException.java @@ -0,0 +1,11 @@ +package zipdabang.server.apiPayload.exception.handler; + +import zipdabang.server.apiPayload.code.BaseCode; +import zipdabang.server.apiPayload.exception.base.GeneralException; + + +public class RecipeException extends GeneralException { + public RecipeException(BaseCode errorCommonStatus) { + super(errorCommonStatus); + } +} diff --git a/src/main/java/zipdabang/server/apiPayload/exception/handler/RefreshTokenExceptionHandler.java b/src/main/java/zipdabang/server/apiPayload/exception/handler/RefreshTokenExceptionHandler.java new file mode 100644 index 0000000..5828e4c --- /dev/null +++ b/src/main/java/zipdabang/server/apiPayload/exception/handler/RefreshTokenExceptionHandler.java @@ -0,0 +1,11 @@ +package zipdabang.server.apiPayload.exception.handler; + + +import zipdabang.server.apiPayload.code.BaseCode; +import zipdabang.server.apiPayload.exception.base.GeneralException; + +public class RefreshTokenExceptionHandler extends GeneralException { + public RefreshTokenExceptionHandler(BaseCode errorCommonStatus) { + super(errorCommonStatus); + } +} diff --git a/src/main/java/zipdabang/server/apiPayload/exception/handler/RootException.java b/src/main/java/zipdabang/server/apiPayload/exception/handler/RootException.java new file mode 100644 index 0000000..a2ad912 --- /dev/null +++ b/src/main/java/zipdabang/server/apiPayload/exception/handler/RootException.java @@ -0,0 +1,11 @@ +package zipdabang.server.apiPayload.exception.handler; + + +import zipdabang.server.apiPayload.code.BaseCode; +import zipdabang.server.apiPayload.exception.base.GeneralException; + +public class RootException extends GeneralException { + public RootException(BaseCode errorCommonStatus) { + super(errorCommonStatus); + } +} diff --git a/src/main/java/zipdabang/server/apiPayload/reponse/ResponseDto.java b/src/main/java/zipdabang/server/apiPayload/reponse/ResponseDto.java new file mode 100644 index 0000000..7fc6e00 --- /dev/null +++ b/src/main/java/zipdabang/server/apiPayload/reponse/ResponseDto.java @@ -0,0 +1,45 @@ +package zipdabang.server.apiPayload.reponse; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Getter; +import zipdabang.server.apiPayload.code.BaseCode; +import zipdabang.server.apiPayload.code.CommonStatus; + + +@Getter +@AllArgsConstructor +@JsonPropertyOrder({"isSuccess", "code", "message", "result"}) +@Schema(description = "기본 응답") +public class ResponseDto { + + @Schema(description = "성공 유무", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") + @JsonProperty("isSuccess") + private final Boolean isSuccess; + @Schema(description = "응답 코드", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000") + private final Integer code; + @Schema(description = "응답 메시지", requiredMode = Schema.RequiredMode.REQUIRED, example = "요청에 성공하였습니다.") + private final String message; + @Schema(description = "응답 결과", requiredMode = Schema.RequiredMode.REQUIRED, example = "응답 결과") + @JsonInclude(JsonInclude.Include.NON_NULL) + private T result; + + + // 성공한 경우 응답 생성 + + public static ResponseDto of(T result){ + return new ResponseDto<>(true, 2000 , CommonStatus.OK.getMessage(), result); + } + + public static ResponseDto of(BaseCode code,T result){ + return new ResponseDto<>(true, 2000 , code.getReasonHttpStatus().getMessage(), result); + } + + // 실패한 경우 응답 생성 + public static ResponseDto onFailure(Integer code, String message, T data){ + return new ResponseDto<>(true, code, message, data); + } +} diff --git a/src/main/java/zipdabang/server/auth/filter/JwtRequestFilter.java b/src/main/java/zipdabang/server/auth/filter/JwtRequestFilter.java index 62cf04c..3ed922e 100644 --- a/src/main/java/zipdabang/server/auth/filter/JwtRequestFilter.java +++ b/src/main/java/zipdabang/server/auth/filter/JwtRequestFilter.java @@ -6,9 +6,9 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.util.StringUtils; import org.springframework.web.filter.OncePerRequestFilter; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.auth.provider.TokenProvider; -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.handler.JwtAuthenticationException; +import zipdabang.server.apiPayload.exception.handler.JwtAuthenticationException; import zipdabang.server.redis.service.RedisService; import javax.servlet.FilterChain; @@ -35,12 +35,12 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse // jwt는 정상적인 형태이나, 로그아웃 한 토큰인가? if(!redisService.validateLoginToken(jwt)) { logger.error("이미 로그아웃 된 토큰 발견"); - throw new JwtAuthenticationException(Code.JWT_FORBIDDEN); + throw new JwtAuthenticationException(CommonStatus.JWT_FORBIDDEN); } Authentication authentication = tokenProvider.getAuthentication(jwt); SecurityContextHolder.getContext().setAuthentication(authentication); }else{ - throw new JwtAuthenticationException(Code.JWT_TOKEN_NOT_FOUND); + throw new JwtAuthenticationException(CommonStatus.JWT_TOKEN_NOT_FOUND); } filterChain.doFilter(httpServletRequest, response); } diff --git a/src/main/java/zipdabang/server/auth/handler/JwtAccessDeniedHandler.java b/src/main/java/zipdabang/server/auth/handler/JwtAccessDeniedHandler.java index 88d9776..0b22238 100644 --- a/src/main/java/zipdabang/server/auth/handler/JwtAccessDeniedHandler.java +++ b/src/main/java/zipdabang/server/auth/handler/JwtAccessDeniedHandler.java @@ -5,7 +5,7 @@ import org.springframework.security.access.AccessDeniedException; import org.springframework.security.web.access.AccessDeniedHandler; import org.springframework.stereotype.Component; -import zipdabang.server.base.Code; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.base.exception.common.ApiErrorResult; import javax.servlet.ServletException; @@ -27,8 +27,8 @@ public void handle(HttpServletRequest request, HttpServletResponse response, Acc ApiErrorResult apiErrorResult = ApiErrorResult.builder() .isSuccess(false) - .code(Code.FORBIDDEN.getCode()) - .message(Code.FORBIDDEN.getMessage()) + .code(CommonStatus.FORBIDDEN.getCode()) + .message(CommonStatus.FORBIDDEN.getMessage()) .result(null) .build(); try{ diff --git a/src/main/java/zipdabang/server/auth/handler/JwtAuthenticationEntryPoint.java b/src/main/java/zipdabang/server/auth/handler/JwtAuthenticationEntryPoint.java index 7607bca..d6db957 100644 --- a/src/main/java/zipdabang/server/auth/handler/JwtAuthenticationEntryPoint.java +++ b/src/main/java/zipdabang/server/auth/handler/JwtAuthenticationEntryPoint.java @@ -5,7 +5,7 @@ import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.stereotype.Component; -import zipdabang.server.base.Code; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.base.exception.common.ApiErrorResult; import javax.servlet.ServletException; @@ -27,8 +27,8 @@ public void commence(HttpServletRequest request, HttpServletResponse response, A PrintWriter writer = response.getWriter(); ApiErrorResult apiErrorResult = ApiErrorResult.builder() .isSuccess(false) - .code(Code.UNAUTHORIZED.getCode()) - .message(Code.UNAUTHORIZED.getMessage()) + .code(CommonStatus.UNAUTHORIZED.getCode()) + .message(CommonStatus.UNAUTHORIZED.getMessage()) .result(null) .build(); try { diff --git a/src/main/java/zipdabang/server/auth/handler/JwtAuthenticationExceptionHandler.java b/src/main/java/zipdabang/server/auth/handler/JwtAuthenticationExceptionHandler.java index 4d33d5e..e9e9ed2 100644 --- a/src/main/java/zipdabang/server/auth/handler/JwtAuthenticationExceptionHandler.java +++ b/src/main/java/zipdabang/server/auth/handler/JwtAuthenticationExceptionHandler.java @@ -2,9 +2,9 @@ import org.springframework.http.HttpStatus; import org.springframework.web.filter.OncePerRequestFilter; -import zipdabang.server.base.Code; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.base.exception.common.ApiErrorResult; -import zipdabang.server.base.exception.handler.JwtAuthenticationException; +import zipdabang.server.apiPayload.exception.handler.JwtAuthenticationException; import javax.servlet.FilterChain; import javax.servlet.ServletException; @@ -25,12 +25,12 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse PrintWriter writer = response.getWriter(); String errorCodeName = authException.getMessage(); - Code code = Code.valueOf(errorCodeName); + CommonStatus commonStatus = CommonStatus.valueOf(errorCodeName); ApiErrorResult apiErrorResult = ApiErrorResult.builder() .isSuccess(false) - .code(code.getCode()) - .message(code.getMessage()) + .code(commonStatus.getCode()) + .message(commonStatus.getMessage()) .result(null) .build(); diff --git a/src/main/java/zipdabang/server/auth/handler/annotation/Resolver/AuthMemberArgumentResolver.java b/src/main/java/zipdabang/server/auth/handler/annotation/Resolver/AuthMemberArgumentResolver.java index cbec739..5dbeb59 100644 --- a/src/main/java/zipdabang/server/auth/handler/annotation/Resolver/AuthMemberArgumentResolver.java +++ b/src/main/java/zipdabang/server/auth/handler/annotation/Resolver/AuthMemberArgumentResolver.java @@ -10,9 +10,9 @@ import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.ModelAndViewContainer; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.auth.handler.annotation.AuthMember; -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.handler.MemberException; +import zipdabang.server.apiPayload.exception.handler.MemberException; import zipdabang.server.converter.MemberConverter; import zipdabang.server.domain.member.Member; @@ -38,7 +38,7 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m principal = authentication.getPrincipal(); } if (principal == null || principal.getClass() == String.class) { - throw new MemberException(Code.MEMBER_NOT_FOUND); + throw new MemberException(CommonStatus.MEMBER_NOT_FOUND); } UsernamePasswordAuthenticationToken authenticationToken = (UsernamePasswordAuthenticationToken) authentication; diff --git a/src/main/java/zipdabang/server/auth/provider/TokenProvider.java b/src/main/java/zipdabang/server/auth/provider/TokenProvider.java index e282e02..63a9c62 100644 --- a/src/main/java/zipdabang/server/auth/provider/TokenProvider.java +++ b/src/main/java/zipdabang/server/auth/provider/TokenProvider.java @@ -13,8 +13,8 @@ import org.springframework.security.core.userdetails.User; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.handler.JwtAuthenticationException; +import zipdabang.server.apiPayload.code.CommonStatus; +import zipdabang.server.apiPayload.exception.handler.JwtAuthenticationException; import javax.servlet.http.HttpServletRequest; import java.security.Key; @@ -115,14 +115,14 @@ public boolean validateToken(String token, TokenType type) throws JwtAuthenticat Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(token); return true; }catch (io.jsonwebtoken.security.SecurityException | MalformedJwtException e){ - throw new JwtAuthenticationException(Code.JWT_BAD_REQUEST); + throw new JwtAuthenticationException(CommonStatus.JWT_BAD_REQUEST); }catch (ExpiredJwtException e){ - if (type == TokenType.ACCESS) throw new JwtAuthenticationException(Code.JWT_ACCESS_TOKEN_EXPIRED); - else throw new JwtAuthenticationException(Code.JWT_REFRESH_TOKEN_EXPIRED); + if (type == TokenType.ACCESS) throw new JwtAuthenticationException(CommonStatus.JWT_ACCESS_TOKEN_EXPIRED); + else throw new JwtAuthenticationException(CommonStatus.JWT_REFRESH_TOKEN_EXPIRED); }catch (UnsupportedJwtException e){ - throw new JwtAuthenticationException(Code.JWT_UNSUPPORTED_TOKEN); + throw new JwtAuthenticationException(CommonStatus.JWT_UNSUPPORTED_TOKEN); }catch (IllegalArgumentException e){ - throw new JwtAuthenticationException(Code.JWT_BAD_REQUEST); + throw new JwtAuthenticationException(CommonStatus.JWT_BAD_REQUEST); } } @@ -131,17 +131,17 @@ public Long validateAndReturnSubject(String token) throws JwtAuthenticationExcep Claims body = Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(token).getBody(); return Long.valueOf(body.getSubject()); }catch (io.jsonwebtoken.security.SecurityException | MalformedJwtException e){ -// throw new JwtAuthenticationException(Code.JWT_BAD_REQUEST); +// throw new JwtAuthenticationException(CommonStatus.JWT_BAD_REQUEST); return -1L; }catch(ExpiredJwtException e){ -// throw new JwtAuthenticationException(Code.JWT_ACCESS_TOKEN_EXPIRED); +// throw new JwtAuthenticationException(CommonStatus.JWT_ACCESS_TOKEN_EXPIRED); return -2L; } catch (UnsupportedJwtException e){ -// throw new JwtAuthenticationException(Code.JWT_UNSUPPORTED_TOKEN); +// throw new JwtAuthenticationException(CommonStatus.JWT_UNSUPPORTED_TOKEN); return -3L; }catch (IllegalArgumentException e){ -// throw new JwtAuthenticationException(Code.JWT_BAD_REQUEST); +// throw new JwtAuthenticationException(CommonStatus.JWT_BAD_REQUEST); return -4L; } } diff --git a/src/main/java/zipdabang/server/base/ResponseDto.java b/src/main/java/zipdabang/server/base/ResponseDto.java index 7694a72..59bd8a4 100644 --- a/src/main/java/zipdabang/server/base/ResponseDto.java +++ b/src/main/java/zipdabang/server/base/ResponseDto.java @@ -1,39 +1,41 @@ -package zipdabang.server.base; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.ToString; - -@Getter -@ToString -@RequiredArgsConstructor -public class ResponseDto { - private final Boolean isSuccess; - private final Integer code; - private final String message; - private final T result; - - public static ResponseDto of(Boolean isSuccess, Code code, T result) { - return new ResponseDto<>(isSuccess, code.getCode(), code.getMessage(), result); - } - - public static ResponseDto of(Code code, T result){ - return new ResponseDto<>(true, code.getCode(), code.getMessage(), result); - } - - public static ResponseDto of(T result){ - return new ResponseDto<>(true, Code.OK.getCode(), Code.OK.getMessage(), result); - } - - public static ResponseDto of(Boolean isSuccess, Code errorCode, Exception e, T result) { - return new ResponseDto<>(isSuccess, errorCode.getCode(), errorCode.getMessage(e), result); - } - - public static ResponseDto of(Boolean isSuccess, Code errorCode, String message, T result) { - return new ResponseDto<>(isSuccess, errorCode.getCode(), errorCode.getMessage(message), result); - } - - public static ResponseDto empty(){ - return new ResponseDto<>(true, Code.OK.getCode(), Code.OK.getMessage(), null); - } -} +//package zipdabang.server.base; +// +//import lombok.Getter; +//import lombok.RequiredArgsConstructor; +//import lombok.ToString; +//import zipdabang.server.apiPayload.code.CommonStatus; +// +//@Getter +//@ToString +//@RequiredArgsConstructor +//public class ResponseDto { +// private final Boolean isSuccess; +// private final Integer code; +// private final String message; +// private final T result; +// +// public static ResponseDto of(Boolean isSuccess, CommonStatus commonStatus, T result) { +// return new ResponseDto<>(isSuccess, commonStatus.getCode(), commonStatus.getMessage(), result); +// } +// +// public static ResponseDto of(CommonStatus commonStatus, T result){ +// return new ResponseDto<>(true, commonStatus.getCode(), commonStatus.getMessage(), result); +// } +// +// public static ResponseDto of(T result){ +// return new ResponseDto<>(true, CommonStatus.OK.getCode(), CommonStatus.OK.getMessage(), result); +// } +// +// public static ResponseDto of(Boolean isSuccess, CommonStatus errorCommonStatus, Exception e, T result) { +// return new ResponseDto<>(isSuccess, errorCommonStatus.getCode(), errorCommonStatus.getMessage(e), result); +// } +// +// public static ResponseDto of(Boolean isSuccess, CommonStatus errorCommonStatus, String message, T result) { +// return new ResponseDto<>(isSuccess, errorCommonStatus.getCode(), errorCommonStatus.getMessage(message), result); +// } +// +// public static ResponseDto empty(){ +// return new ResponseDto<>(true, CommonStatus.OK.getCode(), CommonStatus.OK.getMessage(), null); +// } +//} +//a \ No newline at end of file diff --git a/src/main/java/zipdabang/server/base/exception/ExceptionHandler.java b/src/main/java/zipdabang/server/base/exception/ExceptionHandler.java index f30077f..1bffb66 100644 --- a/src/main/java/zipdabang/server/base/exception/ExceptionHandler.java +++ b/src/main/java/zipdabang/server/base/exception/ExceptionHandler.java @@ -1,74 +1,73 @@ -package zipdabang.server.base.exception; - -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.bind.annotation.RestControllerAdvice; -import org.springframework.web.context.request.WebRequest; -import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; -import zipdabang.server.base.Code; -import zipdabang.server.base.ResponseDto; - -import javax.validation.ConstraintViolationException; - -@RestControllerAdvice(annotations = {RestController.class}) -public class ExceptionHandler extends ResponseEntityExceptionHandler { - - - @org.springframework.web.bind.annotation.ExceptionHandler - public ResponseEntity validation(ConstraintViolationException e, WebRequest request) { - if(e.getConstraintViolations().size() >= 1) - return handleExceptionInternal(e, Code.valueOf(e.getMessage().split(":")[1].substring(1)), request); - return handleExceptionInternal(e, Code.UNAUTHORIZED, request); - } - - @org.springframework.web.bind.annotation.ExceptionHandler - public ResponseEntity general(GeneralException e, WebRequest request) { - return handleExceptionInternal(e, e.getErrorCode(), request); - } - - @org.springframework.web.bind.annotation.ExceptionHandler - public ResponseEntity exception(Exception e, WebRequest request) { - e.printStackTrace(); - return handleExceptionInternalFalse(e, Code.INTERNAL_ERROR, HttpHeaders.EMPTY, Code.INTERNAL_ERROR.getHttpStatus(),request); - } - - @Override - protected ResponseEntity handleExceptionInternal(Exception ex, Object body, - HttpHeaders headers, HttpStatus status, WebRequest request) { - return handleExceptionInternal(ex, Code.valueOf(status), headers, status, request); - } - - - private ResponseEntity handleExceptionInternal(Exception e, Code errorCode, - WebRequest request) { - return handleExceptionInternal(e, errorCode, HttpHeaders.EMPTY, errorCode.getHttpStatus(), - request); - } - - private ResponseEntity handleExceptionInternal(Exception e, Code errorCode, - HttpHeaders headers, HttpStatus status, WebRequest request) { - ResponseDto body = ResponseDto.of(true,errorCode, null); - e.printStackTrace(); - return super.handleExceptionInternal( - e, - body, - headers, - status, - request - ); - } - - private ResponseEntity handleExceptionInternalFalse(Exception e, Code errorCode, - HttpHeaders headers, HttpStatus status, WebRequest request) { - ResponseDto body = ResponseDto.of(false,errorCode, null); - return super.handleExceptionInternal( - e, - body, - headers, - status, - request - ); - } -} +//package zipdabang.server.base.exception; +// +//import org.springframework.http.HttpHeaders; +//import org.springframework.http.HttpStatus; +//import org.springframework.http.ResponseEntity; +//import org.springframework.web.bind.annotation.RestController; +//import org.springframework.web.bind.annotation.RestControllerAdvice; +//import org.springframework.web.context.request.WebRequest; +//import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; +//import zipdabang.server.apiPayload.code.CommonStatus; +// +//import javax.validation.ConstraintViolationException; +// +//@RestControllerAdvice(annotations = {RestController.class}) +//public class ExceptionHandler extends ResponseEntityExceptionHandler { +// +// +// @org.springframework.web.bind.annotation.ExceptionHandler +// public ResponseEntity validation(ConstraintViolationException e, WebRequest request) { +// if(e.getConstraintViolations().size() >= 1) +// return handleExceptionInternal(e, CommonStatus.valueOf(e.getMessage().split(":")[1].substring(1)), request); +// return handleExceptionInternal(e, CommonStatus.UNAUTHORIZED, request); +// } +// +// @org.springframework.web.bind.annotation.ExceptionHandler +// public ResponseEntity general(GeneralException e, WebRequest request) { +// return handleExceptionInternal(e, e.getErrorCommonStatus(), request); +// } +// +// @org.springframework.web.bind.annotation.ExceptionHandler +// public ResponseEntity exception(Exception e, WebRequest request) { +// e.printStackTrace(); +// return handleExceptionInternalFalse(e, CommonStatus.INTERNAL_ERROR, HttpHeaders.EMPTY, CommonStatus.INTERNAL_ERROR.getHttpStatus(),request); +// } +// +// @Override +// protected ResponseEntity handleExceptionInternal(Exception ex, Object body, +// HttpHeaders headers, HttpStatus status, WebRequest request) { +// return handleExceptionInternal(ex, CommonStatus.valueOf(status), headers, status, request); +// } +// +// +// private ResponseEntity handleExceptionInternal(Exception e, CommonStatus errorCommonStatus, +// WebRequest request) { +// return handleExceptionInternal(e, errorCommonStatus, HttpHeaders.EMPTY, errorCommonStatus.getHttpStatus(), +// request); +// } +// +// private ResponseEntity handleExceptionInternal(Exception e, CommonStatus errorCommonStatus, +// HttpHeaders headers, HttpStatus status, WebRequest request) { +// ResponseDto body = ResponseDto.of(true, errorCommonStatus, null); +// e.printStackTrace(); +// return super.handleExceptionInternal( +// e, +// body, +// headers, +// status, +// request +// ); +// } +// +// private ResponseEntity handleExceptionInternalFalse(Exception e, CommonStatus errorCommonStatus, +// HttpHeaders headers, HttpStatus status, WebRequest request) { +// ResponseDto body = ResponseDto.of(false, errorCommonStatus, null); +// return super.handleExceptionInternal( +// e, +// body, +// headers, +// status, +// request +// ); +// } +//} diff --git a/src/main/java/zipdabang/server/base/exception/GeneralException.java b/src/main/java/zipdabang/server/base/exception/GeneralException.java index ba4d88b..857d284 100644 --- a/src/main/java/zipdabang/server/base/exception/GeneralException.java +++ b/src/main/java/zipdabang/server/base/exception/GeneralException.java @@ -1,50 +1,50 @@ -package zipdabang.server.base.exception; - -import lombok.Getter; -import zipdabang.server.base.Code; - -@Getter -public class GeneralException extends RuntimeException{ - - private final Code errorCode; - - public GeneralException() { - super(Code.INTERNAL_ERROR.getMessage()); - this.errorCode = Code.INTERNAL_ERROR; - } - - public GeneralException(String message) { - super(Code.INTERNAL_ERROR.getMessage(message)); - this.errorCode = Code.INTERNAL_ERROR; - } - - public GeneralException(String message, Throwable cause) { - super(Code.INTERNAL_ERROR.getMessage(message), cause); - this.errorCode = Code.INTERNAL_ERROR; - } - - public GeneralException(Throwable cause) { - super(Code.INTERNAL_ERROR.getMessage(cause)); - this.errorCode = Code.INTERNAL_ERROR; - } - - public GeneralException(Code errorCode) { - super(errorCode.getMessage()); - this.errorCode = errorCode; - } - - public GeneralException(Code errorCode, String message) { - super(errorCode.getMessage(message)); - this.errorCode = errorCode; - } - - public GeneralException(Code errorCode, String message, Throwable cause) { - super(errorCode.getMessage(message), cause); - this.errorCode = errorCode; - } - - public GeneralException(Code errorCode, Throwable cause) { - super(errorCode.getMessage(cause), cause); - this.errorCode = errorCode; - } -} +//package zipdabang.server.base.exception; +// +//import lombok.Getter; +//import zipdabang.server.apiPayload.code.CommonStatus; +// +//@Getter +//public class GeneralException extends RuntimeException{ +// +// private final CommonStatus errorCommonStatus; +// +// public GeneralException() { +// super(CommonStatus.INTERNAL_ERROR.getMessage()); +// this.errorCommonStatus = CommonStatus.INTERNAL_ERROR; +// } +// +// public GeneralException(String message) { +// super(CommonStatus.INTERNAL_ERROR.getMessage(message)); +// this.errorCommonStatus = CommonStatus.INTERNAL_ERROR; +// } +// +// public GeneralException(String message, Throwable cause) { +// super(CommonStatus.INTERNAL_ERROR.getMessage(message), cause); +// this.errorCommonStatus = CommonStatus.INTERNAL_ERROR; +// } +// +// public GeneralException(Throwable cause) { +// super(CommonStatus.INTERNAL_ERROR.getMessage(cause)); +// this.errorCommonStatus = CommonStatus.INTERNAL_ERROR; +// } +// +// public GeneralException(CommonStatus errorCommonStatus) { +// super(errorCommonStatus.getMessage()); +// this.errorCommonStatus = errorCommonStatus; +// } +// +// public GeneralException(CommonStatus errorCommonStatus, String message) { +// super(errorCommonStatus.getMessage(message)); +// this.errorCommonStatus = errorCommonStatus; +// } +// +// public GeneralException(CommonStatus errorCommonStatus, String message, Throwable cause) { +// super(errorCommonStatus.getMessage(message), cause); +// this.errorCommonStatus = errorCommonStatus; +// } +// +// public GeneralException(CommonStatus errorCommonStatus, Throwable cause) { +// super(errorCommonStatus.getMessage(cause), cause); +// this.errorCommonStatus = errorCommonStatus; +// } +//} diff --git a/src/main/java/zipdabang/server/base/exception/handler/AuthNumberException.java b/src/main/java/zipdabang/server/base/exception/handler/AuthNumberException.java deleted file mode 100644 index 7d60867..0000000 --- a/src/main/java/zipdabang/server/base/exception/handler/AuthNumberException.java +++ /dev/null @@ -1,10 +0,0 @@ -package zipdabang.server.base.exception.handler; - -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.GeneralException; - -public class AuthNumberException extends GeneralException { - public AuthNumberException(Code errorCode){ - super(errorCode); - } -} diff --git a/src/main/java/zipdabang/server/base/exception/handler/CustomFeignClientException.java b/src/main/java/zipdabang/server/base/exception/handler/CustomFeignClientException.java deleted file mode 100644 index d908185..0000000 --- a/src/main/java/zipdabang/server/base/exception/handler/CustomFeignClientException.java +++ /dev/null @@ -1,12 +0,0 @@ -package zipdabang.server.base.exception.handler; - -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.GeneralException; - - -public class CustomFeignClientException extends GeneralException { - - public CustomFeignClientException(Code errorCode){ - super(errorCode); - } -} diff --git a/src/main/java/zipdabang/server/base/exception/handler/JwtAuthenticationException.java b/src/main/java/zipdabang/server/base/exception/handler/JwtAuthenticationException.java deleted file mode 100644 index e1923d4..0000000 --- a/src/main/java/zipdabang/server/base/exception/handler/JwtAuthenticationException.java +++ /dev/null @@ -1,11 +0,0 @@ -package zipdabang.server.base.exception.handler; - -import org.springframework.security.core.AuthenticationException; -import zipdabang.server.base.Code; - -public class JwtAuthenticationException extends AuthenticationException { - - public JwtAuthenticationException(Code code){ - super(code.name()); - } -} diff --git a/src/main/java/zipdabang/server/base/exception/handler/MemberException.java b/src/main/java/zipdabang/server/base/exception/handler/MemberException.java deleted file mode 100644 index 9e0db59..0000000 --- a/src/main/java/zipdabang/server/base/exception/handler/MemberException.java +++ /dev/null @@ -1,10 +0,0 @@ -package zipdabang.server.base.exception.handler; - -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.GeneralException; - -public class MemberException extends GeneralException { - public MemberException(Code errorCode) { - super(errorCode); - } -} diff --git a/src/main/java/zipdabang/server/base/exception/handler/RecipeException.java b/src/main/java/zipdabang/server/base/exception/handler/RecipeException.java deleted file mode 100644 index b7077dd..0000000 --- a/src/main/java/zipdabang/server/base/exception/handler/RecipeException.java +++ /dev/null @@ -1,10 +0,0 @@ -package zipdabang.server.base.exception.handler; - -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.GeneralException; - -public class RecipeException extends GeneralException { - public RecipeException(Code errorCode) { - super(errorCode); - } -} diff --git a/src/main/java/zipdabang/server/base/exception/handler/RefreshTokenExceptionHandler.java b/src/main/java/zipdabang/server/base/exception/handler/RefreshTokenExceptionHandler.java deleted file mode 100644 index 02fcecf..0000000 --- a/src/main/java/zipdabang/server/base/exception/handler/RefreshTokenExceptionHandler.java +++ /dev/null @@ -1,10 +0,0 @@ -package zipdabang.server.base.exception.handler; - -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.GeneralException; - -public class RefreshTokenExceptionHandler extends GeneralException { - public RefreshTokenExceptionHandler(Code errorCode) { - super(errorCode); - } -} diff --git a/src/main/java/zipdabang/server/base/exception/handler/RootException.java b/src/main/java/zipdabang/server/base/exception/handler/RootException.java deleted file mode 100644 index 8866cb9..0000000 --- a/src/main/java/zipdabang/server/base/exception/handler/RootException.java +++ /dev/null @@ -1,10 +0,0 @@ -package zipdabang.server.base.exception.handler; - -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.GeneralException; - -public class RootException extends GeneralException { - public RootException(Code errorCode) { - super(errorCode); - } -} diff --git a/src/main/java/zipdabang/server/converter/MemberConverter.java b/src/main/java/zipdabang/server/converter/MemberConverter.java index 65fe47d..538f793 100644 --- a/src/main/java/zipdabang/server/converter/MemberConverter.java +++ b/src/main/java/zipdabang/server/converter/MemberConverter.java @@ -5,9 +5,9 @@ import org.springframework.data.domain.Page; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.aws.s3.AmazonS3Manager; -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.handler.MemberException; +import zipdabang.server.apiPayload.exception.handler.MemberException; import zipdabang.server.domain.Category; import zipdabang.server.domain.enums.GenderType; import zipdabang.server.domain.enums.SocialType; @@ -158,7 +158,7 @@ public static MemberResponseDto.MemberInfoResponseDto toMemberInfoDto(Member mem } public static Member toMember(Long memberId) { - return staticMemberRepository.findById(memberId).orElseThrow(() -> new MemberException(Code.MEMBER_NOT_FOUND)); + return staticMemberRepository.findById(memberId).orElseThrow(() -> new MemberException(CommonStatus.MEMBER_NOT_FOUND)); } public static Member toMemberTemp(Long memberId) { diff --git a/src/main/java/zipdabang/server/converter/RecipeConverter.java b/src/main/java/zipdabang/server/converter/RecipeConverter.java index f04d1d9..628e764 100644 --- a/src/main/java/zipdabang/server/converter/RecipeConverter.java +++ b/src/main/java/zipdabang/server/converter/RecipeConverter.java @@ -2,14 +2,13 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.cloud.client.loadbalancer.RetryableStatusCodeException; import org.springframework.data.domain.Page; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; //import zipdabang.server.aws.s3.AmazonS3Manager; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.aws.s3.AmazonS3Manager; -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.handler.RecipeException; +import zipdabang.server.apiPayload.exception.handler.RecipeException; import zipdabang.server.domain.Report; import zipdabang.server.domain.etc.Uuid; import zipdabang.server.domain.member.Member; @@ -21,7 +20,6 @@ import javax.annotation.PostConstruct; import java.io.IOException; -import java.rmi.RemoteException; import java.util.List; import java.util.Optional; import java.util.concurrent.atomic.AtomicLong; @@ -29,8 +27,6 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import static org.apache.logging.log4j.ThreadContext.isEmpty; - @Slf4j @Component @RequiredArgsConstructor @@ -163,7 +159,7 @@ public static List toStep(RecipeRequestDto.CreateRecipeDto request, Recipe return request.getSteps().stream() .map(step-> { if (step.getDescription() == null) - throw new RecipeException(Code.NULL_RECIPE_ERROR); + throw new RecipeException(CommonStatus.NULL_RECIPE_ERROR); try { return toStepDto(step, recipe, stepImages); } catch (IOException e) { @@ -290,7 +286,7 @@ public static Recipe toRecipe(RecipeRequestDto.CreateRecipeDto request, Multipar if(thumbnail != null) imageUrl = uploadThumbnail(thumbnail); else - throw new RecipeException(Code.NULL_RECIPE_ERROR); + throw new RecipeException(CommonStatus.NULL_RECIPE_ERROR); recipe.setThumbnail(imageUrl); return recipe; @@ -353,7 +349,7 @@ private static Step toStepDto(RecipeRequestDto.StepDto step, Recipe recipe, List if(stepImages != null) imageUrl = uploadStepImage(stepImage); else - throw new RecipeException(Code.NULL_RECIPE_ERROR); + throw new RecipeException(CommonStatus.NULL_RECIPE_ERROR); createdStep.setImage(imageUrl); return createdStep; diff --git a/src/main/java/zipdabang/server/converter/SmsConverter.java b/src/main/java/zipdabang/server/converter/SmsConverter.java index 4764fbb..43204cc 100644 --- a/src/main/java/zipdabang/server/converter/SmsConverter.java +++ b/src/main/java/zipdabang/server/converter/SmsConverter.java @@ -2,16 +2,16 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; -import zipdabang.server.base.Code; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.sms.dto.SmsResponseDto; @Component @RequiredArgsConstructor public class SmsConverter { - public static SmsResponseDto.AuthNumResultDto toAuthNumResultDto(Code responseCode) { + public static SmsResponseDto.AuthNumResultDto toAuthNumResultDto(CommonStatus responseCommonStatus) { return SmsResponseDto.AuthNumResultDto.builder() - .responseCode(responseCode) + .responseCommonStatus(responseCommonStatus) .build(); } } diff --git a/src/main/java/zipdabang/server/converter/common/BaseConverter.java b/src/main/java/zipdabang/server/converter/common/BaseConverter.java index b28f0fc..3e3d32f 100644 --- a/src/main/java/zipdabang/server/converter/common/BaseConverter.java +++ b/src/main/java/zipdabang/server/converter/common/BaseConverter.java @@ -2,17 +2,17 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; -import zipdabang.server.base.Code; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.web.dto.common.BaseDto; @Component @RequiredArgsConstructor public class BaseConverter { - public static BaseDto.BaseResponseDto toBaseDto(Code responseCode, Object result) { + public static BaseDto.BaseResponseDto toBaseDto(CommonStatus responseCommonStatus, Object result) { return BaseDto.BaseResponseDto.builder() - .code(responseCode.getCode()) - .message(responseCode.getMessage()) + .code(responseCommonStatus.getCode()) + .message(responseCommonStatus.getMessage()) .build(); } } diff --git a/src/main/java/zipdabang/server/redis/service/RedisServiceImpl.java b/src/main/java/zipdabang/server/redis/service/RedisServiceImpl.java index bfbf7d2..b8dad03 100644 --- a/src/main/java/zipdabang/server/redis/service/RedisServiceImpl.java +++ b/src/main/java/zipdabang/server/redis/service/RedisServiceImpl.java @@ -5,10 +5,10 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.auth.provider.TokenProvider; -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.handler.MemberException; -import zipdabang.server.base.exception.handler.RefreshTokenExceptionHandler; +import zipdabang.server.apiPayload.exception.handler.MemberException; +import zipdabang.server.apiPayload.exception.handler.RefreshTokenExceptionHandler; import zipdabang.server.domain.member.Member; import zipdabang.server.redis.domain.LoginStatus; import zipdabang.server.redis.domain.RefreshToken; @@ -40,7 +40,7 @@ public class RedisServiceImpl implements RedisService { @Override @Transactional public RefreshToken generateRefreshToken(String email) { - Member member = memberRepository.findByEmail(email).orElseThrow(() -> new MemberException(Code.MEMBER_NOT_FOUND)); + Member member = memberRepository.findByEmail(email).orElseThrow(() -> new MemberException(CommonStatus.MEMBER_NOT_FOUND)); String token = UUID.randomUUID().toString(); Long memberId = member.getMemberId(); @@ -62,17 +62,17 @@ public RefreshToken generateRefreshToken(String email) { @Transactional public RefreshToken reGenerateRefreshToken(MemberRequestDto.IssueTokenDto request) { if(request.getRefreshToken() == null) - throw new MemberException(Code.REFRESH_TOKEN_NOT_FOUND); - RefreshToken findRefreshToken = refreshTokenRepository.findById(request.getRefreshToken()).orElseThrow(() -> new RefreshTokenExceptionHandler(Code.JWT_REFRESH_TOKEN_EXPIRED)); + throw new MemberException(CommonStatus.REFRESH_TOKEN_NOT_FOUND); + RefreshToken findRefreshToken = refreshTokenRepository.findById(request.getRefreshToken()).orElseThrow(() -> new RefreshTokenExceptionHandler(CommonStatus.JWT_REFRESH_TOKEN_EXPIRED)); LocalDateTime expireTime = findRefreshToken.getExpireTime(); LocalDateTime current = LocalDateTime.now(); LocalDateTime expireDeadLine = current.plusSeconds(20); - Member member = memberRepository.findById(findRefreshToken.getMemberId()).orElseThrow(() -> new MemberException(Code.MEMBER_NOT_FOUND)); + Member member = memberRepository.findById(findRefreshToken.getMemberId()).orElseThrow(() -> new MemberException(CommonStatus.MEMBER_NOT_FOUND)); if(current.isAfter(expireTime)) { logger.error("이미 만료된 리프레시 토큰 발견"); - throw new RefreshTokenExceptionHandler(Code.JWT_REFRESH_TOKEN_EXPIRED); + throw new RefreshTokenExceptionHandler(CommonStatus.JWT_REFRESH_TOKEN_EXPIRED); } // 새로 발급할 accessToken보다 refreshToken이 먼저 만료 될 경우인가? diff --git a/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java b/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java index 33c73de..bd8612f 100644 --- a/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java +++ b/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java @@ -9,12 +9,11 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.auth.provider.TokenProvider; import zipdabang.server.aws.s3.AmazonS3Manager; -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.handler.AuthNumberException; -import zipdabang.server.base.exception.handler.MemberException; -import zipdabang.server.base.exception.handler.RecipeException; +import zipdabang.server.apiPayload.exception.handler.AuthNumberException; +import zipdabang.server.apiPayload.exception.handler.MemberException; import zipdabang.server.converter.MemberConverter; import zipdabang.server.domain.Category; import zipdabang.server.domain.enums.DeregisterType; @@ -130,7 +129,7 @@ public Optional findMemberById(Long id) { @Override public void existByPhoneNumber(String phoneNum) { if (memberRepository.existsByPhoneNum(phoneNum)) { - throw new AuthNumberException(Code.PHONE_NUMBER_EXIST); + throw new AuthNumberException(CommonStatus.PHONE_NUMBER_EXIST); } } @@ -200,7 +199,7 @@ public void logout(String accessToken, Member member) { @Override public String regenerateAccessToken(RefreshToken refreshToken) { - Member member = memberRepository.findById(refreshToken.getMemberId()).orElseThrow(() -> new MemberException(Code.MEMBER_NOT_FOUND)); + Member member = memberRepository.findById(refreshToken.getMemberId()).orElseThrow(() -> new MemberException(CommonStatus.MEMBER_NOT_FOUND)); return redisService.saveLoginStatus(member.getMemberId(), tokenProvider.createAccessToken(member.getMemberId(), member.getSocialType().toString(),member.getEmail(),Arrays.asList(new SimpleGrantedAuthority("USER")))); } @@ -233,7 +232,7 @@ public Page findInquery(Member member, Integer page) { page -= 1; Page inqueries = inqueryRepository.findByMember(member, PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "createdAt"))); if(inqueries.getTotalPages() <= page) - throw new MemberException(Code.OVER_PAGE_INDEX_ERROR); + throw new MemberException(CommonStatus.OVER_PAGE_INDEX_ERROR); return inqueries; } @@ -246,7 +245,7 @@ public OAuthJoin.OAuthJoinDto joinInfoComplete(MemberRequestDto.MemberInfoDto re request.getPreferBeverages().stream() .map(prefer -> { - Category category = categoryRepository.findById(prefer).orElseThrow(() -> new MemberException(Code.NO_CATEGORY_EXIST)); + Category category = categoryRepository.findById(prefer).orElseThrow(() -> new MemberException(CommonStatus.NO_CATEGORY_EXIST)); MemberPreferCategory memberPreferCategory = MemberConverter.toMemberPreferCategory(joinUser, category); return preferCategoryRepository.save(memberPreferCategory); } @@ -329,11 +328,11 @@ public void saveDeregisterReasons(Long deregisterId, List deregi @Transactional public void blockMember(Member owner, Long blockedId) { if (owner.getMemberId() == blockedId) { - throw new MemberException(Code.BLOCK_SELF); + throw new MemberException(CommonStatus.BLOCK_SELF); } - Member blocked = memberRepository.findById(blockedId).orElseThrow(() -> new MemberException(Code.MEMBER_NOT_FOUND)); + Member blocked = memberRepository.findById(blockedId).orElseThrow(() -> new MemberException(CommonStatus.MEMBER_NOT_FOUND)); if (blockedMemberRepository.existsByOwnerAndBlocked(owner, blocked)) { - throw new MemberException(Code.ALREADY_BLOCKED_MEMBER); + throw new MemberException(CommonStatus.ALREADY_BLOCKED_MEMBER); } blockedMemberRepository.save( BlockedMember.builder() @@ -345,7 +344,7 @@ public void blockMember(Member owner, Long blockedId) { @Override @Transactional public void unblockMember(Member owner, Long blockedId) { - Member blocked = memberRepository.findById(blockedId).orElseThrow(() -> new MemberException(Code.MEMBER_NOT_FOUND)); + Member blocked = memberRepository.findById(blockedId).orElseThrow(() -> new MemberException(CommonStatus.MEMBER_NOT_FOUND)); blockedMemberRepository.deleteByOwnerAndBlocked(owner, blocked); } @@ -355,10 +354,10 @@ public Page findBlockedMember(Integer page, Member member) { Page blockedMembers = blockedMemberRepository.findBlockedByOwner(member, PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "createdAt"))); if (blockedMembers.getContent().isEmpty()) { - throw new MemberException(Code.BLOCKED_MEMBER_NOT_FOUND); + throw new MemberException(CommonStatus.BLOCKED_MEMBER_NOT_FOUND); } if(blockedMembers.getTotalPages() <= page) - throw new MemberException(Code.OVER_PAGE_INDEX_ERROR); + throw new MemberException(CommonStatus.OVER_PAGE_INDEX_ERROR); return blockedMembers; @@ -368,7 +367,7 @@ public Page findBlockedMember(Integer page, Member member) { @Transactional public Follow toggleFollow(Long targetId, Member member) { if(targetId.equals(member.getMemberId())) - throw new MemberException(Code.SELF_FOLLOW_FORBIDDEN); + throw new MemberException(CommonStatus.SELF_FOLLOW_FORBIDDEN); Member target = memberRepository.findById(targetId).get(); Optional checkFollow = followRepository.findByFollowerAndFollowee(member, target); @@ -395,7 +394,7 @@ public Page findFollowing(Member member, Integer page) { Page followingMember = followRepository.findAllByFollower(member, PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "createdAt"))); if(followingMember.getTotalPages() <= page) - throw new MemberException(Code.OVER_PAGE_INDEX_ERROR); + throw new MemberException(CommonStatus.OVER_PAGE_INDEX_ERROR); return followingMember; } @@ -406,7 +405,7 @@ public Page findFollower(Member member, Integer page) { Page followerMember = followRepository.findAllByFollowee(member, PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "createdAt"))); if(followerMember.getTotalPages() <= page) - throw new MemberException(Code.OVER_PAGE_INDEX_ERROR); + throw new MemberException(CommonStatus.OVER_PAGE_INDEX_ERROR); return followerMember; } diff --git a/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java b/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java index 8ea214a..5b2efa0 100644 --- a/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java +++ b/src/main/java/zipdabang/server/service/serviceImpl/RecipeServiceImpl.java @@ -11,9 +11,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.aws.s3.AmazonS3Manager; -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.handler.RecipeException; +import zipdabang.server.apiPayload.exception.handler.RecipeException; import zipdabang.server.converter.RecipeConverter; import zipdabang.server.domain.Report; import zipdabang.server.domain.member.BlockedMember; @@ -135,7 +135,7 @@ public TempRecipe tempUpdate(Long tempId, RecipeRequestDto.TempRecipeDto request log.info("service: ", request.toString()); - TempRecipe tempRecipe = tempRecipeRepository.findById(tempId).orElseThrow(() -> new RecipeException(Code.NO_TEMP_RECIPE_EXIST)); + TempRecipe tempRecipe = tempRecipeRepository.findById(tempId).orElseThrow(() -> new RecipeException(CommonStatus.NO_TEMP_RECIPE_EXIST)); //recipe String thumbnailUrl = null; @@ -192,11 +192,11 @@ public TempRecipe tempUpdate(Long tempId, RecipeRequestDto.TempRecipeDto request @Override public Recipe getRecipe(Long recipeId, Member member) { - Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(()->new RecipeException(Code.NO_RECIPE_EXIST)); + Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(()->new RecipeException(CommonStatus.NO_RECIPE_EXIST)); Optional blockedInfos= blockedMemberRepository.findByOwnerAndBlocked(member, findRecipe.getMember()); if(blockedInfos.isPresent()){ - throw new RecipeException(Code.BLOCKED_USER_RECIPE); + throw new RecipeException(CommonStatus.BLOCKED_USER_RECIPE); } else { findRecipe.updateView(); @@ -229,7 +229,7 @@ public Page searchRecipe(Long categoryId, String keyword, Integer pageIn List recipeCategory = recipeCategoryRepository.findAllById(categoryId); if(recipeCategory.isEmpty()) - throw new RecipeException(Code.RECIPE_NOT_FOUND); + throw new RecipeException(CommonStatus.RECIPE_NOT_FOUND); QRecipe qRecipe = recipe; QRecipeCategoryMapping qRecipeCategoryMapping = recipeCategoryMapping; @@ -285,7 +285,7 @@ else if (writtenby.equals("common")) else if (writtenby.equals("all")) return null; else - throw new RecipeException(Code.WRITTEN_BY_TYPE_ERROR); + throw new RecipeException(CommonStatus.WRITTEN_BY_TYPE_ERROR); } private BooleanExpression blockedMemberNotInForRecipe(Member member) { @@ -305,10 +305,10 @@ private List getBlockedMember(Member member) { @Override @Transactional(readOnly = false) public Recipe updateLikeOnRecipe(Long recipeId, Member member) { - Recipe recipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(Code.NO_RECIPE_EXIST)); + Recipe recipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(CommonStatus.NO_RECIPE_EXIST)); if(recipe.getMember() == member) - throw new RecipeException(Code.RECIPE_OWNER); + throw new RecipeException(CommonStatus.RECIPE_OWNER); Optional likesExist = likesRepository.findByRecipeAndMember(recipe,member); @@ -327,13 +327,12 @@ public Recipe updateLikeOnRecipe(Long recipeId, Member member) { @Override @Transactional(readOnly = false) public Recipe updateScrapOnRecipe(Long recipeId, Member member) { - Recipe recipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(Code.NO_RECIPE_EXIST)); + Recipe recipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(CommonStatus.NO_RECIPE_EXIST)); if(recipe.getMember() == member) - throw new RecipeException(Code.RECIPE_OWNER); + throw new RecipeException(CommonStatus.RECIPE_OWNER); Optional scrapExist = scrapRepository.findByRecipeAndMember(recipe,member); - if(scrapExist.isEmpty()) { Scrap savedScrap = scrapRepository.save(RecipeConverter.toScrap(recipe, member)); savedScrap.setRecipe(recipe); @@ -388,7 +387,7 @@ public Page recipeListByCategory(Long categoryId, Integer pageIndex, Mem List recipeCategory = recipeCategoryRepository.findAllById(categoryId); if(recipeCategory.isEmpty()) - throw new RecipeException(Code.RECIPE_NOT_FOUND); + throw new RecipeException(CommonStatus.RECIPE_NOT_FOUND); recipeIdList = recipeCategoryMappingRepository.findByCategoryIn(recipeCategory).stream() .map(categoryMapping -> categoryMapping.getRecipe().getId()) @@ -407,7 +406,7 @@ else if(order.equals("views")) else if(order.equals("latest")) orderBy = "createdAt"; else - throw new RecipeException(Code.ORDER_BY_TYPE_ERROR); + throw new RecipeException(CommonStatus.ORDER_BY_TYPE_ERROR); if(blockedMember.isEmpty()) return recipeRepository.findByIdIn(recipeIdList, @@ -459,7 +458,7 @@ public List getRecipeBannerList() { @Transactional(readOnly = false) @Override public Boolean deleteRecipe(Long recipeId, Member member) { - Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(Code.NO_RECIPE_EXIST)); + Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(CommonStatus.NO_RECIPE_EXIST)); if (findRecipe.getMember().equals(member)) { amazonS3Manager.deleteFile(RecipeConverter.toKeyName(findRecipe.getThumbnailUrl()).substring(1)); @@ -468,7 +467,7 @@ public Boolean deleteRecipe(Long recipeId, Member member) { recipeRepository.deleteById(recipeId); } else - throw new RecipeException(Code.NOT_RECIPE_OWNER); + throw new RecipeException(CommonStatus.NOT_RECIPE_OWNER); return recipeRepository.existsById(recipeId) == false; } @@ -476,8 +475,8 @@ public Boolean deleteRecipe(Long recipeId, Member member) { @Transactional(readOnly = false) @Override public Long reportRecipe(Long recipeId, Long reportId, Member member) { - Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(Code.NO_RECIPE_EXIST)); - Report findReport = reportRepository.findById(reportId).orElseThrow(() -> new RecipeException(Code.NO_REPORT_EXIST)); + Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(CommonStatus.NO_RECIPE_EXIST)); + Report findReport = reportRepository.findById(reportId).orElseThrow(() -> new RecipeException(CommonStatus.NO_REPORT_EXIST)); if (!findRecipe.getMember().equals(member)) { ReportedRecipe mapping = RecipeConverter.toRecipeReport(findReport, findRecipe, member); @@ -486,13 +485,13 @@ public Long reportRecipe(Long recipeId, Long reportId, Member member) { return findRecipe.getId(); } else - throw new RecipeException(Code.RECIPE_OWNER); + throw new RecipeException(CommonStatus.RECIPE_OWNER); } @Transactional(readOnly = false) @Override public Comment createComment(String content, Long recipeId, Member member) { - Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(Code.NO_RECIPE_EXIST)); + Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(CommonStatus.NO_RECIPE_EXIST)); Comment buildComment = RecipeConverter.toComment(content, findRecipe, member); return commentRepository.save(buildComment); @@ -500,7 +499,7 @@ public Comment createComment(String content, Long recipeId, Member member) { @Override public Page commentList(Integer pageIndex, Long recipeId, Member member) { - recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(Code.NO_RECIPE_EXIST)); + recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(CommonStatus.NO_RECIPE_EXIST)); QComment qComment = comment; @@ -530,14 +529,14 @@ private BooleanExpression blockedMemberNotInForComment(Member member) { @Transactional(readOnly = false) @Override public Boolean deleteComment(Long recipeId, Long commentId, Member member) { - Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(Code.NO_RECIPE_EXIST)); - Comment findComment = commentRepository.findById(commentId).orElseThrow(() -> new RecipeException(Code.NO_COMMENT_EXIST)); + Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(CommonStatus.NO_RECIPE_EXIST)); + Comment findComment = commentRepository.findById(commentId).orElseThrow(() -> new RecipeException(CommonStatus.NO_COMMENT_EXIST)); if (findComment.getMember().equals(member) && findComment.getRecipe().equals(findRecipe)) { commentRepository.deleteById(commentId); } else - throw new RecipeException(Code.NOT_COMMENT_OWNER); + throw new RecipeException(CommonStatus.NOT_COMMENT_OWNER); return commentRepository.existsById(recipeId) == false; } @@ -545,23 +544,23 @@ public Boolean deleteComment(Long recipeId, Long commentId, Member member) { @Transactional(readOnly = false) @Override public Comment updateComment(RecipeRequestDto.updateCommentDto request, Long recipeId, Long commentId, Member member) { - Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(Code.NO_RECIPE_EXIST)); - Comment findComment = commentRepository.findById(commentId).orElseThrow(() -> new RecipeException(Code.NO_COMMENT_EXIST)); + Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(CommonStatus.NO_RECIPE_EXIST)); + Comment findComment = commentRepository.findById(commentId).orElseThrow(() -> new RecipeException(CommonStatus.NO_COMMENT_EXIST)); if (findComment.getMember().equals(member) && findComment.getRecipe().equals(findRecipe)) { return findComment.updateContent(request.getComment()); } else - throw new RecipeException(Code.NOT_COMMENT_OWNER); + throw new RecipeException(CommonStatus.NOT_COMMENT_OWNER); } @Transactional(readOnly = false) @Override public Long reportComment(Long recipeId, Long commentId, Long reportId, Member member) { - Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(Code.NO_RECIPE_EXIST)); - Comment findComment = commentRepository.findById(commentId).orElseThrow(() -> new RecipeException(Code.NO_COMMENT_EXIST)); - Report findReport = reportRepository.findById(reportId).orElseThrow(() -> new RecipeException(Code.NO_REPORT_EXIST)); + Recipe findRecipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(CommonStatus.NO_RECIPE_EXIST)); + Comment findComment = commentRepository.findById(commentId).orElseThrow(() -> new RecipeException(CommonStatus.NO_COMMENT_EXIST)); + Report findReport = reportRepository.findById(reportId).orElseThrow(() -> new RecipeException(CommonStatus.NO_REPORT_EXIST)); if (!findComment.getMember().equals(member) && findComment.getRecipe().equals(findRecipe)) { ReportedComment mapping = RecipeConverter.toCommentReport(findReport, findComment, member); @@ -570,6 +569,6 @@ public Long reportComment(Long recipeId, Long commentId, Long reportId, Member m return findComment.getId(); } else - throw new RecipeException(Code.COMMENT_OWNER); + throw new RecipeException(CommonStatus.COMMENT_OWNER); } } diff --git a/src/main/java/zipdabang/server/service/serviceImpl/RootServiceImpl.java b/src/main/java/zipdabang/server/service/serviceImpl/RootServiceImpl.java index c95aa10..1891253 100644 --- a/src/main/java/zipdabang/server/service/serviceImpl/RootServiceImpl.java +++ b/src/main/java/zipdabang/server/service/serviceImpl/RootServiceImpl.java @@ -4,9 +4,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.auth.provider.TokenProvider; -import zipdabang.server.base.Code; -import zipdabang.server.base.exception.handler.RootException; +import zipdabang.server.apiPayload.exception.handler.RootException; import zipdabang.server.domain.Category; import zipdabang.server.domain.Report; import zipdabang.server.domain.inform.Notification; @@ -57,16 +57,16 @@ public Boolean autoLoginService(String authorizationHeader) { result = true; else if (memberId < 0L){ if (memberId.equals(-1L)) - throw new RootException(Code.JWT_BAD_REQUEST); + throw new RootException(CommonStatus.JWT_BAD_REQUEST); else if (memberId.equals(-2L)) - throw new RootException(Code.JWT_ACCESS_TOKEN_EXPIRED); + throw new RootException(CommonStatus.JWT_ACCESS_TOKEN_EXPIRED); else if (memberId.equals(-3L)) - throw new RootException(Code.JWT_UNSUPPORTED_TOKEN); + throw new RootException(CommonStatus.JWT_UNSUPPORTED_TOKEN); else if (memberId.equals(-4L)) - throw new RootException(Code.JWT_BAD_REQUEST); + throw new RootException(CommonStatus.JWT_BAD_REQUEST); } else{ - Member member = memberRepository.findById(memberId).orElseThrow(() -> new RootException(Code.MEMBER_NOT_FOUND)); + Member member = memberRepository.findById(memberId).orElseThrow(() -> new RootException(CommonStatus.MEMBER_NOT_FOUND)); if(member.getAge() == null || member.getNickname() == null || member.getName() == null || member.getGender() == null) result = false; else diff --git a/src/main/java/zipdabang/server/sms/dto/SmsResponseDto.java b/src/main/java/zipdabang/server/sms/dto/SmsResponseDto.java index b312416..9a09552 100644 --- a/src/main/java/zipdabang/server/sms/dto/SmsResponseDto.java +++ b/src/main/java/zipdabang/server/sms/dto/SmsResponseDto.java @@ -1,7 +1,8 @@ package zipdabang.server.sms.dto; import lombok.*; -import zipdabang.server.base.Code; +import zipdabang.server.apiPayload.code.CommonStatus; + import java.time.LocalDateTime; @@ -20,6 +21,6 @@ public class SmsResponseDto { @AllArgsConstructor(access = AccessLevel.PROTECTED) @NoArgsConstructor(access = AccessLevel.PROTECTED) public static class AuthNumResultDto{ - Code responseCode; + CommonStatus responseCommonStatus; } } diff --git a/src/main/java/zipdabang/server/sms/service/serviceImpl/SmsServiceImpl.java b/src/main/java/zipdabang/server/sms/service/serviceImpl/SmsServiceImpl.java index 4f0e55c..dc28db7 100644 --- a/src/main/java/zipdabang/server/sms/service/serviceImpl/SmsServiceImpl.java +++ b/src/main/java/zipdabang/server/sms/service/serviceImpl/SmsServiceImpl.java @@ -2,22 +2,17 @@ import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestClientException; -import org.springframework.web.client.RestTemplate; import zipdabang.server.FeignClient.NaverSmsFeignClient; -import zipdabang.server.base.Code; import lombok.RequiredArgsConstructor; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.RandomStringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import zipdabang.server.base.exception.handler.AuthNumberException; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.domain.etc.AuthNumber; import zipdabang.server.repository.AuthNumberRepository; import zipdabang.server.sms.dto.MessageDto; @@ -28,7 +23,6 @@ import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import java.io.UnsupportedEncodingException; -import java.net.URI; import java.net.URISyntaxException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -88,34 +82,34 @@ public SmsResponseDto.AuthNumResultDto authNumber(Integer authNum, String phoneN Optional authNumber = authNumberRepository.findByPhoneNum(phoneNum);//.orElseThrow(() -> if(authNumber.isEmpty()){ return SmsResponseDto.AuthNumResultDto.builder() - .responseCode(Code.PHONE_AUTH_NOT_FOUND) + .responseCommonStatus(CommonStatus.PHONE_AUTH_NOT_FOUND) .build(); } - // new AuthNumberException(Code.PHONE_AUTH_NOT_FOUND)); - Code code=Code.OK; + // new AuthNumberException(CommonStatus.PHONE_AUTH_NOT_FOUND)); + CommonStatus commonStatus = CommonStatus.OK; if (!authNumber.get().getAuthNum().equals(authNum)) - code = Code.PHONE_AUTH_ERROR; + commonStatus = CommonStatus.PHONE_AUTH_ERROR; // return SmsResponseDto.AuthNumResultDto.builder() -// .responseCode(Code.PHONE_AUTH_ERROR) +// .responseCommonStatus(CommonStatus.PHONE_AUTH_ERROR) // .build(); - //throw new AuthNumberException(Code.PHONE_AUTH_ERROR); + //throw new AuthNumberException(CommonStatus.PHONE_AUTH_ERROR); else{ LocalDateTime nowTime = LocalDateTime.now(); long timeCheck = ChronoUnit.MINUTES.between(authNumber.get().getAuthNumTime(), nowTime); if (timeCheck >= 5) - code = Code.PHONE_AUTH_TIMEOUT; + commonStatus = CommonStatus.PHONE_AUTH_TIMEOUT; // return SmsResponseDto.AuthNumResultDto.builder() -// .responseCode(Code.PHONE_AUTH_TIMEOUT) +// .responseCommonStatus(CommonStatus.PHONE_AUTH_TIMEOUT) // .build(); - //throw new AuthNumberException(Code.PHONE_AUTH_TIMEOUT); + //throw new AuthNumberException(CommonStatus.PHONE_AUTH_TIMEOUT); } - if(code.equals(Code.OK)) + if(commonStatus.equals(CommonStatus.OK)) authNumberRepository.deleteByPhoneNum(authNumber.get().getPhoneNum()); return SmsResponseDto.AuthNumResultDto.builder() - .responseCode(code) + .responseCommonStatus(commonStatus) .build(); } @@ -163,7 +157,7 @@ public SmsResponseDto.AuthNumResultDto sendSms(String targetNumber) throws JsonP authNumberRepository.save(authNumber); return SmsResponseDto.AuthNumResultDto.builder() - .responseCode(Code.OK) + .responseCommonStatus(CommonStatus.OK) .build(); } diff --git a/src/main/java/zipdabang/server/validation/annotation/ExistNickname.java b/src/main/java/zipdabang/server/validation/annotation/ExistNickname.java new file mode 100644 index 0000000..a4d2703 --- /dev/null +++ b/src/main/java/zipdabang/server/validation/annotation/ExistNickname.java @@ -0,0 +1,18 @@ +package zipdabang.server.validation.annotation; + +import zipdabang.server.validation.validator.ExistMemberRequestBodyValidator; +import zipdabang.server.validation.validator.ExistNicknameValidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Documented +@Constraint(validatedBy = ExistNicknameValidator.class) +@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +public @interface ExistNickname { + String message() default "닉네임이 이미 존재합니다."; + Class[] groups() default {}; + Class[] payload() default {}; +} diff --git a/src/main/java/zipdabang/server/validation/validator/CheckDeregisterValidator.java b/src/main/java/zipdabang/server/validation/validator/CheckDeregisterValidator.java index 76391b3..0aa4a09 100644 --- a/src/main/java/zipdabang/server/validation/validator/CheckDeregisterValidator.java +++ b/src/main/java/zipdabang/server/validation/validator/CheckDeregisterValidator.java @@ -1,7 +1,6 @@ package zipdabang.server.validation.validator; -import zipdabang.server.base.Code; -import zipdabang.server.domain.member.Deregister; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.domain.member.Member; import zipdabang.server.validation.annotation.CheckDeregister; @@ -24,7 +23,7 @@ public boolean isValid(Object value, ConstraintValidatorContext context) { } if (member.getZipCode().equals("TEST")) { context.disableDefaultConstraintViolation(); - context.buildConstraintViolationWithTemplate(Code.DEREGISTER_FAIL.toString()).addConstraintViolation(); + context.buildConstraintViolationWithTemplate(CommonStatus.DEREGISTER_FAIL.toString()).addConstraintViolation(); return false; } } diff --git a/src/main/java/zipdabang/server/validation/validator/CheckPageValidator.java b/src/main/java/zipdabang/server/validation/validator/CheckPageValidator.java index 0fe8b86..269152d 100644 --- a/src/main/java/zipdabang/server/validation/validator/CheckPageValidator.java +++ b/src/main/java/zipdabang/server/validation/validator/CheckPageValidator.java @@ -2,8 +2,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; -import zipdabang.server.base.Code; -import zipdabang.server.domain.member.Member; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.validation.annotation.CheckPage; import javax.validation.ConstraintValidator; @@ -21,7 +20,7 @@ public void initialize(CheckPage constraintAnnotation) { public boolean isValid(Integer value, ConstraintValidatorContext context) { if(value < 1 || value == null) { context.disableDefaultConstraintViolation(); - context.buildConstraintViolationWithTemplate(Code.UNDER_PAGE_INDEX_ERROR.toString()).addConstraintViolation(); + context.buildConstraintViolationWithTemplate(CommonStatus.UNDER_PAGE_INDEX_ERROR.toString()).addConstraintViolation(); return false; } return true; diff --git a/src/main/java/zipdabang/server/validation/validator/CheckTempMemberValidator.java b/src/main/java/zipdabang/server/validation/validator/CheckTempMemberValidator.java index f625914..3e8cdeb 100644 --- a/src/main/java/zipdabang/server/validation/validator/CheckTempMemberValidator.java +++ b/src/main/java/zipdabang/server/validation/validator/CheckTempMemberValidator.java @@ -2,7 +2,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; -import zipdabang.server.base.Code; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.domain.member.Member; import zipdabang.server.validation.annotation.CheckTempMember; @@ -23,7 +23,7 @@ public boolean isValid(Object value, ConstraintValidatorContext context) { Member member = (Member)value; if(member.getMemberId().equals(0L)) { context.disableDefaultConstraintViolation(); - context.buildConstraintViolationWithTemplate(Code.TEMP_MEMBER_FORBIDDEN.toString()).addConstraintViolation(); + context.buildConstraintViolationWithTemplate(CommonStatus.TEMP_MEMBER_FORBIDDEN.toString()).addConstraintViolation(); return false; } } diff --git a/src/main/java/zipdabang/server/validation/validator/ExistMemberRequestBodyValidator.java b/src/main/java/zipdabang/server/validation/validator/ExistMemberRequestBodyValidator.java index 94935da..0deb941 100644 --- a/src/main/java/zipdabang/server/validation/validator/ExistMemberRequestBodyValidator.java +++ b/src/main/java/zipdabang/server/validation/validator/ExistMemberRequestBodyValidator.java @@ -2,11 +2,10 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; -import zipdabang.server.base.Code; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.domain.member.Member; import zipdabang.server.service.MemberService; import zipdabang.server.validation.annotation.ExistMember; -import zipdabang.server.web.dto.requestDto.MemberRequestDto; import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; @@ -29,7 +28,7 @@ public boolean isValid(Long value, ConstraintValidatorContext context) { Optional memberById = memberService.findMemberById(value); if(memberById.isEmpty()) { context.disableDefaultConstraintViolation(); - context.buildConstraintViolationWithTemplate(Code.TARGET_MEMBER_NOT_FOUND.toString()).addConstraintViolation(); + context.buildConstraintViolationWithTemplate(CommonStatus.TARGET_MEMBER_NOT_FOUND.toString()).addConstraintViolation(); return false; } return true; diff --git a/src/main/java/zipdabang/server/validation/validator/ExistNicknameValidator.java b/src/main/java/zipdabang/server/validation/validator/ExistNicknameValidator.java new file mode 100644 index 0000000..18daf3a --- /dev/null +++ b/src/main/java/zipdabang/server/validation/validator/ExistNicknameValidator.java @@ -0,0 +1,36 @@ +package zipdabang.server.validation.validator; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import zipdabang.server.apiPayload.code.CommonStatus; +import zipdabang.server.domain.member.Member; +import zipdabang.server.service.MemberService; +import zipdabang.server.validation.annotation.ExistNickname; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import java.util.Optional; + +@Component +@RequiredArgsConstructor +public class ExistNicknameValidator implements ConstraintValidator { + + private final MemberService memberService; + + @Override + public void initialize(ExistNickname constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + } + + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + + Optional member = memberService.checkExistNickname(value); + if (member.isPresent()){ + context.disableDefaultConstraintViolation(); + context.buildConstraintViolationWithTemplate(CommonStatus.NICKNAME_EXIST.toString()).addConstraintViolation(); + return false; + } + return true; + } +} diff --git a/src/main/java/zipdabang/server/validation/validator/ExistNotificationValidator.java b/src/main/java/zipdabang/server/validation/validator/ExistNotificationValidator.java index 0b264ad..69a0758 100644 --- a/src/main/java/zipdabang/server/validation/validator/ExistNotificationValidator.java +++ b/src/main/java/zipdabang/server/validation/validator/ExistNotificationValidator.java @@ -2,7 +2,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; -import zipdabang.server.base.Code; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.domain.inform.Notification; import zipdabang.server.repository.NotificationRepository; import zipdabang.server.validation.annotation.ExistNotification; @@ -27,7 +27,7 @@ public boolean isValid(Long value, ConstraintValidatorContext context) { Optional foundNotification = notificationRepository.findById(value); if(foundNotification.isEmpty()){ context.disableDefaultConstraintViolation(); - context.buildConstraintViolationWithTemplate(Code.NOTIFICATION_NOT_FOUND.toString()).addConstraintViolation(); + context.buildConstraintViolationWithTemplate(CommonStatus.NOTIFICATION_NOT_FOUND.toString()).addConstraintViolation(); return false; } return true; diff --git a/src/main/java/zipdabang/server/validation/validator/ExistRecipeCategoryValidator.java b/src/main/java/zipdabang/server/validation/validator/ExistRecipeCategoryValidator.java index 96bf65e..296f9f9 100644 --- a/src/main/java/zipdabang/server/validation/validator/ExistRecipeCategoryValidator.java +++ b/src/main/java/zipdabang/server/validation/validator/ExistRecipeCategoryValidator.java @@ -2,7 +2,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; -import zipdabang.server.base.Code; +import zipdabang.server.apiPayload.code.CommonStatus; import zipdabang.server.domain.recipe.RecipeCategory; import zipdabang.server.repository.recipeRepositories.RecipeCategoryRepository; import zipdabang.server.validation.annotation.ExistRecipeCategory; @@ -27,7 +27,7 @@ public boolean isValid(Long value, ConstraintValidatorContext context) { Optional findRecipeCategory = recipeCategoryRepository.findById(value); if(findRecipeCategory.isEmpty()){ context.disableDefaultConstraintViolation(); - context.buildConstraintViolationWithTemplate(Code.NO_RECIPE_CATEGORY_EXIST.toString()).addConstraintViolation(); + context.buildConstraintViolationWithTemplate(CommonStatus.NO_RECIPE_CATEGORY_EXIST.toString()).addConstraintViolation(); return false; } return true; diff --git a/src/main/java/zipdabang/server/web/controller/MarketController.java b/src/main/java/zipdabang/server/web/controller/MarketController.java index 1c9869b..c8ed33a 100644 --- a/src/main/java/zipdabang/server/web/controller/MarketController.java +++ b/src/main/java/zipdabang/server/web/controller/MarketController.java @@ -14,8 +14,8 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import zipdabang.server.apiPayload.reponse.ResponseDto; import zipdabang.server.auth.handler.annotation.AuthMember; -import zipdabang.server.base.ResponseDto; import zipdabang.server.domain.member.Member; import zipdabang.server.web.dto.responseDto.MarketResponseDto; diff --git a/src/main/java/zipdabang/server/web/controller/MemberRestController.java b/src/main/java/zipdabang/server/web/controller/MemberRestController.java index 6f3b22d..436e34d 100644 --- a/src/main/java/zipdabang/server/web/controller/MemberRestController.java +++ b/src/main/java/zipdabang/server/web/controller/MemberRestController.java @@ -20,10 +20,10 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestClientException; import zipdabang.server.FeignClient.service.KakaoOauthService; +import zipdabang.server.apiPayload.code.CommonStatus; +import zipdabang.server.apiPayload.reponse.ResponseDto; import zipdabang.server.auth.handler.annotation.AuthMember; -import zipdabang.server.base.Code; -import zipdabang.server.base.ResponseDto; -import zipdabang.server.base.exception.handler.MemberException; +import zipdabang.server.apiPayload.exception.handler.MemberException; import zipdabang.server.converter.MemberConverter; import zipdabang.server.domain.Category; import zipdabang.server.domain.member.Follow; @@ -105,7 +105,7 @@ public ResponseDto oauthKakao( @RequestBody MemberRequestDto.OAuthRequestDto oAuthRequestDto, @RequestParam(name = "type") String type) { OAuthResult.OAuthResultDto oAuthResultDto = memberService.SocialLogin(oAuthRequestDto, type); MemberResponseDto.SocialLoginDto socialLoginDto = MemberConverter.toSocialLoginDto(oAuthResultDto.getAccessToken(), oAuthResultDto.getRefreshToken()); - return oAuthResultDto.getIsLogin() ? ResponseDto.of(Code.OAUTH_LOGIN, socialLoginDto) : ResponseDto.of(Code.OAUTH_JOIN, null); + return oAuthResultDto.getIsLogin() ? ResponseDto.of(CommonStatus.OAUTH_LOGIN, socialLoginDto) : ResponseDto.of(CommonStatus.OAUTH_JOIN, null); } @@ -119,7 +119,7 @@ public ResponseDto oauthKakao( @ApiResponse(responseCode = "4053", description = "BAD_REQUEST, 선호하는 음료 카테고리 id가 이상할 경우", content = @Content(schema = @Schema(implementation = ResponseDto.class))), }) @PostMapping("/members/oauth/info") - public ResponseDto memberInfoForSignUp(@RequestBody MemberRequestDto.MemberInfoDto request, @RequestParam(name = "type", required = true) String type) { + public ResponseDto memberInfoForSignUp(@RequestBody @Valid MemberRequestDto.MemberInfoDto request, @RequestParam(name = "type", required = true) String type) { log.info("body로 넘겨온 사용자 정보: {}", request.toString()); OAuthJoin.OAuthJoinDto oAuthJoinDto = memberService.joinInfoComplete(request, type); return ResponseDto.of(MemberConverter.toSocialJoinDto(oAuthJoinDto)); @@ -149,7 +149,7 @@ public ResponseDto sendSms(@RequestBody MemberR @PostMapping("/members/phone/auth") public ResponseDto authPhoneNum(@RequestBody MemberRequestDto.PhoneNumAuthDto request) { SmsResponseDto.AuthNumResultDto authNumResultDto = smsService.authNumber(request.getAuthNum(), request.getPhoneNum()); - return ResponseDto.of(authNumResultDto.getResponseCode(), authNumResultDto); + return ResponseDto.of(authNumResultDto.getResponseCommonStatus(), authNumResultDto); } @@ -271,7 +271,7 @@ public ResponseDto checkExistNickname(@RequestParam String nickname) { Optional member = memberService.checkExistNickname(nickname); return member.isPresent() ? - ResponseDto.of(Code.NICKNAME_EXIST, nickname) : ResponseDto.of(Code.NICKNAME_OK, nickname); + ResponseDto.of(CommonStatus.NICKNAME_EXIST, nickname) : ResponseDto.of(CommonStatus.NICKNAME_OK, nickname); } @Operation(summary = "리프레쉬 토큰을 이용해 accessToken 재발급 API ✔️", description = "리프레쉬 토큰을 이용해 accessToken 재발급하는 API입니다.") @@ -406,7 +406,7 @@ public ResponseDto blockerMemberList(@Req if (page == null) page = 1; else if (page < 1) - throw new MemberException(Code.UNDER_PAGE_INDEX_ERROR); + throw new MemberException(CommonStatus.UNDER_PAGE_INDEX_ERROR); page -= 1; Page blockedMembers = memberService.findBlockedMember(page, member); diff --git a/src/main/java/zipdabang/server/web/controller/RecipeRestController.java b/src/main/java/zipdabang/server/web/controller/RecipeRestController.java index ede5bdf..4ab068a 100644 --- a/src/main/java/zipdabang/server/web/controller/RecipeRestController.java +++ b/src/main/java/zipdabang/server/web/controller/RecipeRestController.java @@ -14,10 +14,10 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import zipdabang.server.apiPayload.code.CommonStatus; +import zipdabang.server.apiPayload.reponse.ResponseDto; import zipdabang.server.auth.handler.annotation.AuthMember; -import zipdabang.server.base.Code; -import zipdabang.server.base.ResponseDto; -import zipdabang.server.base.exception.handler.RecipeException; +import zipdabang.server.apiPayload.exception.handler.RecipeException; import zipdabang.server.converter.RecipeConverter; import zipdabang.server.domain.member.Member; import zipdabang.server.domain.recipe.*; @@ -145,7 +145,7 @@ public ResponseDto deleteRecipe(@PathVariable(name = "recipeId") Long re if (recipeDeleteBoolean) return ResponseDto.of(recipeId + " 레시피 삭제 완료"); else - throw new RecipeException(Code.INTERNAL_ERROR); + throw new RecipeException(CommonStatus.INTERNAL_ERROR); } @Operation(summary = "🍹figma 레시피2, 레시피 검색 카테고리 별 preview 화면 API 🔑 ✔", description = "검색한 레시피 카테고리별 조회 화면 API입니다.") @@ -197,16 +197,16 @@ public ResponseDto searchRecipe(@ExistRecip if (pageIndex == null) pageIndex = 1; else if (pageIndex < 1) - throw new RecipeException(Code.UNDER_PAGE_INDEX_ERROR); + throw new RecipeException(CommonStatus.UNDER_PAGE_INDEX_ERROR); pageIndex -= 1; Page recipes = recipeService.searchRecipe(categoryId, keyword, pageIndex, member); if (recipes.getTotalElements() == 0) - throw new RecipeException(Code.RECIPE_NOT_FOUND); + throw new RecipeException(CommonStatus.RECIPE_NOT_FOUND); if (pageIndex >= recipes.getTotalPages()) - throw new RecipeException(Code.OVER_PAGE_INDEX_ERROR); + throw new RecipeException(CommonStatus.OVER_PAGE_INDEX_ERROR); return ResponseDto.of(RecipeConverter.toPagingRecipeDtoList(recipes, member)); } @@ -262,7 +262,7 @@ public ResponseDto recipeListByCategory(@Ex if (pageIndex == null) pageIndex = 1; else if (pageIndex < 1) - throw new RecipeException(Code.UNDER_PAGE_INDEX_ERROR); + throw new RecipeException(CommonStatus.UNDER_PAGE_INDEX_ERROR); pageIndex -= 1; @@ -272,9 +272,9 @@ else if (pageIndex < 1) log.info(recipes.toString()); if (recipes.getTotalElements() == 0) - throw new RecipeException(Code.RECIPE_NOT_FOUND); + throw new RecipeException(CommonStatus.RECIPE_NOT_FOUND); if (pageIndex >= recipes.getTotalPages()) - throw new RecipeException(Code.OVER_PAGE_INDEX_ERROR); + throw new RecipeException(CommonStatus.OVER_PAGE_INDEX_ERROR); return ResponseDto.of(RecipeConverter.toPagingRecipeDtoList(recipes, member)); } @@ -301,7 +301,7 @@ public ResponseDto recipeListPreviewWrittenBy(@ log.info(recipes.toString()); if (recipes.size() == 0) - throw new RecipeException(Code.RECIPE_NOT_FOUND); + throw new RecipeException(CommonStatus.RECIPE_NOT_FOUND); return ResponseDto.of(RecipeConverter.toPreviewRecipeDtoList(recipes, member)); } @@ -445,14 +445,14 @@ public ResponseDto reportRecipe(@PathVariable Long recipeId, @PathVariab // @Operation(summary = "레시피 차단 API 🔑 ✔", description = "래시피 차단 API입니다.") // @ApiResponses({ -// @ApiResponse(responseCode = "2000", description = "OK, 레시피가 차단 되었습니다."), -// @ApiResponse(responseCode = "4003", description = "UNAUTHORIZED, 토큰 모양이 이상함, 토큰 제대로 주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), -// @ApiResponse(responseCode = "4005", description = "UNAUTHORIZED, 엑세스 토큰 만료, 리프레시 토큰 사용", content = @Content(schema = @Schema(implementation = ResponseDto.class))), -// @ApiResponse(responseCode = "4008", description = "UNAUTHORIZED, 토큰 없음, 토큰 줘요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), -// @ApiResponse(responseCode = "4052", description = "BAD_REQUEST, 사용자가 없습니다. 이 api에서 이거 생기면 백앤드 개발자 호출", content = @Content(schema = @Schema(implementation = ResponseDto.class))), -// @ApiResponse(responseCode = "4101", description = "BAD_REQUEST, 해당 recipeId를 가진 recipe가 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), -// @ApiResponse(responseCode = "4109", description = "BAD_REQUEST, 본인의 레시피입니다. 신고/차단할 수 없습니다", content = @Content(schema = @Schema(implementation = ResponseDto.class))), -// @ApiResponse(responseCode = "5000", description = "SERVER ERROR, 백앤드 개발자에게 알려주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), +// @ApiResponse(responseCommonStatus = "2000", description = "OK, 레시피가 차단 되었습니다."), +// @ApiResponse(responseCommonStatus = "4003", description = "UNAUTHORIZED, 토큰 모양이 이상함, 토큰 제대로 주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), +// @ApiResponse(responseCommonStatus = "4005", description = "UNAUTHORIZED, 엑세스 토큰 만료, 리프레시 토큰 사용", content = @Content(schema = @Schema(implementation = ResponseDto.class))), +// @ApiResponse(responseCommonStatus = "4008", description = "UNAUTHORIZED, 토큰 없음, 토큰 줘요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), +// @ApiResponse(responseCommonStatus = "4052", description = "BAD_REQUEST, 사용자가 없습니다. 이 api에서 이거 생기면 백앤드 개발자 호출", content = @Content(schema = @Schema(implementation = ResponseDto.class))), +// @ApiResponse(responseCommonStatus = "4101", description = "BAD_REQUEST, 해당 recipeId를 가진 recipe가 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), +// @ApiResponse(responseCommonStatus = "4109", description = "BAD_REQUEST, 본인의 레시피입니다. 신고/차단할 수 없습니다", content = @Content(schema = @Schema(implementation = ResponseDto.class))), +// @ApiResponse(responseCommonStatus = "5000", description = "SERVER ERROR, 백앤드 개발자에게 알려주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), // }) // @Parameters({ // @Parameter(name = "member", hidden = true), @@ -507,7 +507,7 @@ public ResponseDto searchRecipe(@PathVaria if (pageIndex == null) pageIndex = 1; else if (pageIndex < 1) - throw new RecipeException(Code.UNDER_PAGE_INDEX_ERROR); + throw new RecipeException(CommonStatus.UNDER_PAGE_INDEX_ERROR); pageIndex -= 1; @@ -517,7 +517,7 @@ else if (pageIndex < 1) log.info(comments.toString()); if (pageIndex >= comments.getTotalPages()) - throw new RecipeException(Code.OVER_PAGE_INDEX_ERROR); + throw new RecipeException(CommonStatus.OVER_PAGE_INDEX_ERROR); return ResponseDto.of(RecipeConverter.toPagingCommentDtoList(comments, member)); } @@ -544,7 +544,7 @@ public ResponseDto deleteComment(@PathVariable(name = "recipeId") Long r if (commentDeleteBoolean) return ResponseDto.of(commentId + " 댓글 삭제 완료"); else - throw new RecipeException(Code.INTERNAL_ERROR); + throw new RecipeException(CommonStatus.INTERNAL_ERROR); } @Operation(summary = "댓글 수정 API 🔑 ✔", description = "댓글 수정 API입니다.") @@ -594,15 +594,15 @@ public ResponseDto reportComment(@PathVariable Long recipeId, @PathVaria // @Operation(summary = "댓글 차단 API 🔑 ✔", description = "댓글 차단 API입니다.") // @ApiResponses({ -// @ApiResponse(responseCode = "2000", description = "OK, 댓글이 차단 되었습니다."), -// @ApiResponse(responseCode = "4003", description = "UNAUTHORIZED, 토큰 모양이 이상함, 토큰 제대로 주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), -// @ApiResponse(responseCode = "4005", description = "UNAUTHORIZED, 엑세스 토큰 만료, 리프레시 토큰 사용", content = @Content(schema = @Schema(implementation = ResponseDto.class))), -// @ApiResponse(responseCode = "4008", description = "UNAUTHORIZED, 토큰 없음, 토큰 줘요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), -// @ApiResponse(responseCode = "4052", description = "BAD_REQUEST, 사용자가 없습니다. 이 api에서 이거 생기면 백앤드 개발자 호출", content = @Content(schema = @Schema(implementation = ResponseDto.class))), -// @ApiResponse(responseCode = "4101", description = "BAD_REQUEST, 해당 recipeId를 가진 recipe가 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), -// @ApiResponse(responseCode = "4107", description = "BAD_REQUEST, 해당 commentId를 가진 댓글이 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), -// @ApiResponse(responseCode = "4110", description = "BAD_REQUEST, 본인의 댓글입니다. 신고/차단할 수 없습니다", content = @Content(schema = @Schema(implementation = ResponseDto.class))), -// @ApiResponse(responseCode = "5000", description = "SERVER ERROR, 백앤드 개발자에게 알려주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), +// @ApiResponse(responseCommonStatus = "2000", description = "OK, 댓글이 차단 되었습니다."), +// @ApiResponse(responseCommonStatus = "4003", description = "UNAUTHORIZED, 토큰 모양이 이상함, 토큰 제대로 주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), +// @ApiResponse(responseCommonStatus = "4005", description = "UNAUTHORIZED, 엑세스 토큰 만료, 리프레시 토큰 사용", content = @Content(schema = @Schema(implementation = ResponseDto.class))), +// @ApiResponse(responseCommonStatus = "4008", description = "UNAUTHORIZED, 토큰 없음, 토큰 줘요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), +// @ApiResponse(responseCommonStatus = "4052", description = "BAD_REQUEST, 사용자가 없습니다. 이 api에서 이거 생기면 백앤드 개발자 호출", content = @Content(schema = @Schema(implementation = ResponseDto.class))), +// @ApiResponse(responseCommonStatus = "4101", description = "BAD_REQUEST, 해당 recipeId를 가진 recipe가 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), +// @ApiResponse(responseCommonStatus = "4107", description = "BAD_REQUEST, 해당 commentId를 가진 댓글이 없어요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), +// @ApiResponse(responseCommonStatus = "4110", description = "BAD_REQUEST, 본인의 댓글입니다. 신고/차단할 수 없습니다", content = @Content(schema = @Schema(implementation = ResponseDto.class))), +// @ApiResponse(responseCommonStatus = "5000", description = "SERVER ERROR, 백앤드 개발자에게 알려주세요", content = @Content(schema = @Schema(implementation = ResponseDto.class))), // }) // @Parameters({ // @Parameter(name = "member", hidden = true), diff --git a/src/main/java/zipdabang/server/web/controller/RootController.java b/src/main/java/zipdabang/server/web/controller/RootController.java index b9c1909..3c0a688 100644 --- a/src/main/java/zipdabang/server/web/controller/RootController.java +++ b/src/main/java/zipdabang/server/web/controller/RootController.java @@ -11,8 +11,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import zipdabang.server.base.Code; -import zipdabang.server.base.ResponseDto; +import zipdabang.server.apiPayload.code.CommonStatus; +import zipdabang.server.apiPayload.reponse.ResponseDto; import zipdabang.server.converter.RootConverter; import zipdabang.server.domain.Category; import zipdabang.server.domain.Report; @@ -73,9 +73,9 @@ public ResponseDto showBanners() { public ResponseDto autoLogin(@RequestHeader(value = "Authorization", required = false) String authorizationHeader){ Boolean autoResult = rootService.autoLoginService(authorizationHeader); if(autoResult) - return ResponseDto.of(Code.AUTO_LOGIN_MAIN,null); + return ResponseDto.of(CommonStatus.AUTO_LOGIN_MAIN,null); else - return ResponseDto.of(Code.AUTO_LOGIN_NOT_MAIN,null); + return ResponseDto.of(CommonStatus.AUTO_LOGIN_NOT_MAIN,null); } @GetMapping("/notices/{noticeId}") diff --git a/src/main/java/zipdabang/server/web/dto/requestDto/MemberRequestDto.java b/src/main/java/zipdabang/server/web/dto/requestDto/MemberRequestDto.java index d43bbef..caedff5 100644 --- a/src/main/java/zipdabang/server/web/dto/requestDto/MemberRequestDto.java +++ b/src/main/java/zipdabang/server/web/dto/requestDto/MemberRequestDto.java @@ -12,6 +12,7 @@ import org.springframework.lang.Nullable; import org.springframework.web.multipart.MultipartFile; import zipdabang.server.domain.enums.DeregisterType; +import zipdabang.server.validation.annotation.ExistNickname; public class MemberRequestDto { @@ -74,7 +75,7 @@ public static class MemberInfoDto { private String email; @NotBlank private String gender; - @NotBlank + @NotBlank @ExistNickname @Size(min = 4, max = 10) private String nickname; @NotBlank private String phoneNum; diff --git a/src/main/java/zipdabang/server/web/dto/requestDto/RecipeRequestDto.java b/src/main/java/zipdabang/server/web/dto/requestDto/RecipeRequestDto.java index 270c928..56c663c 100644 --- a/src/main/java/zipdabang/server/web/dto/requestDto/RecipeRequestDto.java +++ b/src/main/java/zipdabang/server/web/dto/requestDto/RecipeRequestDto.java @@ -6,13 +6,14 @@ import lombok.Setter; import org.springframework.web.multipart.MultipartFile; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; import java.util.List; public class RecipeRequestDto { @Getter @Setter public static class CreateRecipeDto{ - List categoryId; String name; String time; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b0dd1af..9324498 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -12,13 +12,13 @@ spring: enabled: always ## # local redis -# redis: -# host: localhost + redis: + host: localhost # redis: # briefing-redis.bjyb5r.ng.0001.apne1.cache.amazonaws.com - redis: - host: zipdabang-redis.osattk.ng.0001.apn2.cache.amazonaws.com +# redis: +# host: zipdabang-redis.osattk.ng.0001.apn2.cache.amazonaws.com batch: jdbc: initialize-schema: always From 8cca9856faa679f97180e40aa044ce7ed04a2489 Mon Sep 17 00:00:00 2001 From: CYY1007 Date: Fri, 6 Oct 2023 02:07:02 +0900 Subject: [PATCH 2/5] bug fix --- src/main/java/zipdabang/server/converter/MemberConverter.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/zipdabang/server/converter/MemberConverter.java b/src/main/java/zipdabang/server/converter/MemberConverter.java index da3d686..b8f1c56 100644 --- a/src/main/java/zipdabang/server/converter/MemberConverter.java +++ b/src/main/java/zipdabang/server/converter/MemberConverter.java @@ -420,3 +420,5 @@ public static MemberResponseDto.MyZipdabangDto toMyZipdabangDto(Member member, b .build(); } } + + From 7f3bc14adfeac269d5ddaef8b7987ead215e6e42 Mon Sep 17 00:00:00 2001 From: CYY1007 Date: Fri, 6 Oct 2023 02:13:52 +0900 Subject: [PATCH 3/5] bug fix --- .../server/web/dto/responseDto/RecipeResponseDto.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/zipdabang/server/web/dto/responseDto/RecipeResponseDto.java b/src/main/java/zipdabang/server/web/dto/responseDto/RecipeResponseDto.java index 0f63822..a78ef0d 100644 --- a/src/main/java/zipdabang/server/web/dto/responseDto/RecipeResponseDto.java +++ b/src/main/java/zipdabang/server/web/dto/responseDto/RecipeResponseDto.java @@ -2,11 +2,6 @@ import lombok.*; -import org.springframework.web.multipart.MultipartFile; -import zipdabang.server.base.ResponseDto; - -import java.time.LocalDate; -import java.time.LocalDateTime; import java.util.List; public class RecipeResponseDto { From e15e8cefd914a348eef5ee8b3280759287efd5b2 Mon Sep 17 00:00:00 2001 From: CYY1007 Date: Fri, 6 Oct 2023 11:59:26 +0900 Subject: [PATCH 4/5] =?UTF-8?q?redis=20=EC=97=B0=EA=B2=B0=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9324498..b0dd1af 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -12,13 +12,13 @@ spring: enabled: always ## # local redis - redis: - host: localhost +# redis: +# host: localhost # redis: # briefing-redis.bjyb5r.ng.0001.apne1.cache.amazonaws.com -# redis: -# host: zipdabang-redis.osattk.ng.0001.apn2.cache.amazonaws.com + redis: + host: zipdabang-redis.osattk.ng.0001.apn2.cache.amazonaws.com batch: jdbc: initialize-schema: always From b94820328c60c612de1e083285aed1cb7f2b36ab Mon Sep 17 00:00:00 2001 From: CYY1007 Date: Fri, 6 Oct 2023 12:13:14 +0900 Subject: [PATCH 5/5] =?UTF-8?q?redis=20=EC=97=B0=EA=B2=B0=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b0dd1af..e50765b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -14,8 +14,6 @@ spring: ## # local redis # redis: # host: localhost -# redis: -# briefing-redis.bjyb5r.ng.0001.apne1.cache.amazonaws.com redis: host: zipdabang-redis.osattk.ng.0001.apn2.cache.amazonaws.com