From 2d4bc90964fe7e2c5cacd9266e21c1ec40f45eb5 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Thu, 10 Aug 2023 18:51:32 +0900 Subject: [PATCH 01/30] =?UTF-8?q?feat:=20auth,=20global=20exception=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../funeat/auth/application/AuthService.java | 3 +- .../funeat/auth/exception/AuthErrorCode.java | 31 +++++++++++++++++++ .../funeat/auth/exception/AuthException.java | 18 +++++++++++ .../funeat/auth/exception/LoginException.java | 8 ----- .../auth/util/AuthHandlerInterceptor.java | 5 +-- .../java/com/funeat/exception/ErrorCode.java | 31 +++++++++++++++++++ .../com/funeat/exception/GlobalException.java | 23 ++++++++++++++ .../presentation/GlobalControllerAdvice.java | 30 ++++++++++++++---- .../utill/RecipeHandlerInterceptor.java | 5 +-- 9 files changed, 134 insertions(+), 20 deletions(-) create mode 100644 backend/src/main/java/com/funeat/auth/exception/AuthErrorCode.java create mode 100644 backend/src/main/java/com/funeat/auth/exception/AuthException.java delete mode 100644 backend/src/main/java/com/funeat/auth/exception/LoginException.java create mode 100644 backend/src/main/java/com/funeat/exception/ErrorCode.java create mode 100644 backend/src/main/java/com/funeat/exception/GlobalException.java diff --git a/backend/src/main/java/com/funeat/auth/application/AuthService.java b/backend/src/main/java/com/funeat/auth/application/AuthService.java index 0918aa601..a762f09e9 100644 --- a/backend/src/main/java/com/funeat/auth/application/AuthService.java +++ b/backend/src/main/java/com/funeat/auth/application/AuthService.java @@ -21,8 +21,7 @@ public AuthService(final MemberService memberService, final PlatformUserProvider public SignUserDto loginWithKakao(final String code) { final UserInfoDto userInfoDto = platformUserProvider.getPlatformUser(code); - final SignUserDto signUserDto = memberService.findOrCreateMember(userInfoDto); - return signUserDto; + return memberService.findOrCreateMember(userInfoDto); } public String getLoginRedirectUri() { diff --git a/backend/src/main/java/com/funeat/auth/exception/AuthErrorCode.java b/backend/src/main/java/com/funeat/auth/exception/AuthErrorCode.java new file mode 100644 index 000000000..be52351a2 --- /dev/null +++ b/backend/src/main/java/com/funeat/auth/exception/AuthErrorCode.java @@ -0,0 +1,31 @@ +package com.funeat.auth.exception; + +import org.springframework.http.HttpStatus; + +public enum AuthErrorCode { + + LOGIN_MEMBER_NOT_FOUND(HttpStatus.UNAUTHORIZED, "로그인 하지 않은 회원입니다. 로그인을 해주세요.", "2001"), + ; + + private final HttpStatus status; + private final String message; + private final String code; + + AuthErrorCode(final HttpStatus status, final String message, final String code) { + this.status = status; + this.message = message; + this.code = code; + } + + public HttpStatus getStatus() { + return status; + } + + public String getMessage() { + return message; + } + + public String getCode() { + return code; + } +} diff --git a/backend/src/main/java/com/funeat/auth/exception/AuthException.java b/backend/src/main/java/com/funeat/auth/exception/AuthException.java new file mode 100644 index 000000000..c8ee3ef92 --- /dev/null +++ b/backend/src/main/java/com/funeat/auth/exception/AuthException.java @@ -0,0 +1,18 @@ +package com.funeat.auth.exception; + +import com.funeat.exception.ErrorCode; +import com.funeat.exception.GlobalException; +import org.springframework.http.HttpStatus; + +public class AuthException extends GlobalException { + + public AuthException(final HttpStatus status, final ErrorCode errorCode) { + super(status, errorCode); + } + + public static class NotLoggedInException extends AuthException { + public NotLoggedInException(final AuthErrorCode errorCode) { + super(errorCode.getStatus(), new ErrorCode<>(errorCode.getCode(), errorCode.getMessage())); + } + } +} diff --git a/backend/src/main/java/com/funeat/auth/exception/LoginException.java b/backend/src/main/java/com/funeat/auth/exception/LoginException.java deleted file mode 100644 index 2b3eaca08..000000000 --- a/backend/src/main/java/com/funeat/auth/exception/LoginException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.funeat.auth.exception; - -public class LoginException extends RuntimeException { - - public LoginException(final String message) { - super(message); - } -} diff --git a/backend/src/main/java/com/funeat/auth/util/AuthHandlerInterceptor.java b/backend/src/main/java/com/funeat/auth/util/AuthHandlerInterceptor.java index f32f791ea..3a74baf8f 100644 --- a/backend/src/main/java/com/funeat/auth/util/AuthHandlerInterceptor.java +++ b/backend/src/main/java/com/funeat/auth/util/AuthHandlerInterceptor.java @@ -1,6 +1,7 @@ package com.funeat.auth.util; -import com.funeat.auth.exception.LoginException; +import com.funeat.auth.exception.AuthErrorCode; +import com.funeat.auth.exception.AuthException.NotLoggedInException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; @@ -14,7 +15,7 @@ public class AuthHandlerInterceptor implements HandlerInterceptor { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { final HttpSession session = request.getSession(); if (session.getAttribute("member") == null) { - throw new LoginException("login error"); + throw new NotLoggedInException(AuthErrorCode.LOGIN_MEMBER_NOT_FOUND); } return true; } diff --git a/backend/src/main/java/com/funeat/exception/ErrorCode.java b/backend/src/main/java/com/funeat/exception/ErrorCode.java new file mode 100644 index 000000000..f1665fb82 --- /dev/null +++ b/backend/src/main/java/com/funeat/exception/ErrorCode.java @@ -0,0 +1,31 @@ +package com.funeat.exception; + +public class ErrorCode { + + private final String code; + private final String message; + private T info; + + public ErrorCode(final String code, final String message, final T info) { + this.code = code; + this.message = message; + this.info = info; + } + + public ErrorCode(final String code, final String message) { + this.code = code; + this.message = message; + } + + public String getCode() { + return code; + } + + public String getMessage() { + return message; + } + + public T getInfo() { + return info; + } +} diff --git a/backend/src/main/java/com/funeat/exception/GlobalException.java b/backend/src/main/java/com/funeat/exception/GlobalException.java new file mode 100644 index 000000000..976619a36 --- /dev/null +++ b/backend/src/main/java/com/funeat/exception/GlobalException.java @@ -0,0 +1,23 @@ +package com.funeat.exception; + +import org.springframework.http.HttpStatus; + +public class GlobalException extends RuntimeException { + + private final HttpStatus status; + private final ErrorCode errorCode; + + public GlobalException(final HttpStatus status, final ErrorCode errorCode) { + super(errorCode.getMessage()); + this.status = status; + this.errorCode = errorCode; + } + + public HttpStatus getStatus() { + return status; + } + + public ErrorCode getErrorCode() { + return errorCode; + } +} diff --git a/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java b/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java index 0ff01c73c..9fd10bbb4 100644 --- a/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java +++ b/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java @@ -1,6 +1,9 @@ package com.funeat.exception.presentation; -import com.funeat.auth.exception.LoginException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.funeat.exception.ErrorCode; +import com.funeat.exception.GlobalException; import javax.servlet.http.HttpServletRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,14 +15,29 @@ @RestControllerAdvice public class GlobalControllerAdvice { + private static final ErrorCode errorCode = new ErrorCode<>("0000", + HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "알 수 없는 에러입니다."); + private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final ObjectMapper objectMapper; + + public GlobalControllerAdvice(final ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } - @ExceptionHandler(LoginException.class) - public ResponseEntity loginExceptionHandler(final LoginException e, final HttpServletRequest request) { + @ExceptionHandler(GlobalException.class) + public ResponseEntity handleGlobalException(final GlobalException e, final HttpServletRequest request) + throws JsonProcessingException { + log.warn("request = {} code = {} message = {} info = {}", request.getRequestURI(), e.getErrorCode().getCode(), + e.getErrorCode().getMessage(), objectMapper.writeValueAsString(e.getErrorCode().getInfo())); + + return ResponseEntity.status(e.getStatus()).body(e.getErrorCode().getMessage()); + } - log.warn("URI: {}, 쿠키값: {}, 저장된 JSESSIONID 값: {}", request.getRequestURI(), request.getHeader("Cookie"), - request.getSession().getId()); + @ExceptionHandler(Exception.class) + public ResponseEntity handleServerException(final Exception e) { + log.error("code = {} ", errorCode.getCode(), e); - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorCode); } } diff --git a/backend/src/main/java/com/funeat/recipe/utill/RecipeHandlerInterceptor.java b/backend/src/main/java/com/funeat/recipe/utill/RecipeHandlerInterceptor.java index 03f2f712f..08e484c78 100644 --- a/backend/src/main/java/com/funeat/recipe/utill/RecipeHandlerInterceptor.java +++ b/backend/src/main/java/com/funeat/recipe/utill/RecipeHandlerInterceptor.java @@ -1,6 +1,7 @@ package com.funeat.recipe.utill; -import com.funeat.auth.exception.LoginException; +import com.funeat.auth.exception.AuthErrorCode; +import com.funeat.auth.exception.AuthException.NotLoggedInException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; @@ -17,7 +18,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons } final HttpSession session = request.getSession(); if (session.getAttribute("member") == null) { - throw new LoginException("login error"); + throw new NotLoggedInException(AuthErrorCode.LOGIN_MEMBER_NOT_FOUND); } return true; } From e7263fb469d0e1928facc80a2e938ed1884c408d Mon Sep 17 00:00:00 2001 From: wugawuga Date: Thu, 10 Aug 2023 18:52:16 +0900 Subject: [PATCH 02/30] =?UTF-8?q?feat:=20memberNotFound=20exception=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/application/MemberService.java | 6 ++-- .../member/exception/MemberErrorCode.java | 31 +++++++++++++++++++ .../member/exception/MemberException.java | 18 +++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 backend/src/main/java/com/funeat/member/exception/MemberErrorCode.java create mode 100644 backend/src/main/java/com/funeat/member/exception/MemberException.java diff --git a/backend/src/main/java/com/funeat/member/application/MemberService.java b/backend/src/main/java/com/funeat/member/application/MemberService.java index 8d34a2236..7a4c1cf9f 100644 --- a/backend/src/main/java/com/funeat/member/application/MemberService.java +++ b/backend/src/main/java/com/funeat/member/application/MemberService.java @@ -7,6 +7,8 @@ import com.funeat.member.domain.Member; import com.funeat.member.dto.MemberProfileResponse; import com.funeat.member.dto.MemberRequest; +import com.funeat.member.exception.MemberErrorCode; +import com.funeat.member.exception.MemberException.MemberNotFoundException; import com.funeat.member.persistence.MemberRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -39,7 +41,7 @@ private SignUserDto save(final UserInfoDto userInfoDto) { public MemberProfileResponse getMemberProfile(final Long memberId) { final Member findMember = memberRepository.findById(memberId) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new MemberNotFoundException(MemberErrorCode.MEMBER_NOF_FOUND, memberId)); return MemberProfileResponse.toResponse(findMember); } @@ -47,7 +49,7 @@ public MemberProfileResponse getMemberProfile(final Long memberId) { @Transactional public void modify(final Long memberId, final MemberRequest request) { final Member findMember = memberRepository.findById(memberId) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new MemberNotFoundException(MemberErrorCode.MEMBER_NOF_FOUND, memberId)); final String nickname = request.getNickname(); final String profileImage = request.getProfileImage(); diff --git a/backend/src/main/java/com/funeat/member/exception/MemberErrorCode.java b/backend/src/main/java/com/funeat/member/exception/MemberErrorCode.java new file mode 100644 index 000000000..06cf9b0f0 --- /dev/null +++ b/backend/src/main/java/com/funeat/member/exception/MemberErrorCode.java @@ -0,0 +1,31 @@ +package com.funeat.member.exception; + +import org.springframework.http.HttpStatus; + +public enum MemberErrorCode { + + MEMBER_NOF_FOUND(HttpStatus.BAD_REQUEST, "존재하지 않는 회원입니다. 회원 id를 확인하세요.", "1001"), + ; + + private final HttpStatus status; + private final String message; + private final String code; + + MemberErrorCode(final HttpStatus status, final String message, final String code) { + this.status = status; + this.message = message; + this.code = code; + } + + public HttpStatus getStatus() { + return status; + } + + public String getMessage() { + return message; + } + + public String getCode() { + return code; + } +} diff --git a/backend/src/main/java/com/funeat/member/exception/MemberException.java b/backend/src/main/java/com/funeat/member/exception/MemberException.java new file mode 100644 index 000000000..92f48caae --- /dev/null +++ b/backend/src/main/java/com/funeat/member/exception/MemberException.java @@ -0,0 +1,18 @@ +package com.funeat.member.exception; + +import com.funeat.exception.ErrorCode; +import com.funeat.exception.GlobalException; +import org.springframework.http.HttpStatus; + +public class MemberException extends GlobalException { + + public MemberException(final HttpStatus status, final ErrorCode errorCode) { + super(status, errorCode); + } + + public static class MemberNotFoundException extends MemberException { + public MemberNotFoundException(final MemberErrorCode errorCode, final Long memberId) { + super(errorCode.getStatus(), new ErrorCode<>(errorCode.getMessage(), errorCode.getCode(), memberId)); + } + } +} From f870bca6a54bb2cfcd788ab87452c1ac48f0770c Mon Sep 17 00:00:00 2001 From: wugawuga Date: Thu, 10 Aug 2023 18:57:13 +0900 Subject: [PATCH 03/30] =?UTF-8?q?feat:=20bean=20validation=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/build.gradle b/backend/build.gradle index 2dcfcb7f4..1be58918b 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -16,6 +16,7 @@ repositories { } dependencies { + implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' runtimeOnly 'com.mysql:mysql-connector-j' From c153ca3f1a2aed1682723577a343d55d95ecd9c4 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 01:11:06 +0900 Subject: [PATCH 04/30] =?UTF-8?q?feat:=20Member=20api=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC,=20=EB=A1=9C=EA=B7=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/funeat/exception/CommonErrorCode.java | 32 +++++++++++++ .../java/com/funeat/exception/ErrorCode.java | 3 ++ .../presentation/GlobalControllerAdvice.java | 46 +++++++++++++++++-- .../com/funeat/member/dto/MemberRequest.java | 5 ++ .../presentation/MemberApiController.java | 3 +- 5 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 backend/src/main/java/com/funeat/exception/CommonErrorCode.java diff --git a/backend/src/main/java/com/funeat/exception/CommonErrorCode.java b/backend/src/main/java/com/funeat/exception/CommonErrorCode.java new file mode 100644 index 000000000..5b3f88964 --- /dev/null +++ b/backend/src/main/java/com/funeat/exception/CommonErrorCode.java @@ -0,0 +1,32 @@ +package com.funeat.exception; + +import org.springframework.http.HttpStatus; + +public enum CommonErrorCode { + + UNKNOWN_SERVER_ERROR_CODE(HttpStatus.INTERNAL_SERVER_ERROR, "알 수 없는 에러입니다.", "0000"), + REQUEST_VALID_ERROR_CODE(HttpStatus.INTERNAL_SERVER_ERROR, "요청을 다시 확인해주세요.", "0001"), + ; + + private final HttpStatus status; + private final String message; + private final String code; + + CommonErrorCode(final HttpStatus status, final String message, final String code) { + this.status = status; + this.message = message; + this.code = code; + } + + public HttpStatus getStatus() { + return status; + } + + public String getMessage() { + return message; + } + + public String getCode() { + return code; + } +} diff --git a/backend/src/main/java/com/funeat/exception/ErrorCode.java b/backend/src/main/java/com/funeat/exception/ErrorCode.java index f1665fb82..ee454207e 100644 --- a/backend/src/main/java/com/funeat/exception/ErrorCode.java +++ b/backend/src/main/java/com/funeat/exception/ErrorCode.java @@ -1,5 +1,8 @@ package com.funeat.exception; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) public class ErrorCode { private final String code; diff --git a/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java b/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java index 9fd10bbb4..0a3146417 100644 --- a/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java +++ b/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java @@ -1,23 +1,27 @@ package com.funeat.exception.presentation; +import static com.funeat.exception.CommonErrorCode.REQUEST_VALID_ERROR_CODE; +import static com.funeat.exception.CommonErrorCode.UNKNOWN_SERVER_ERROR_CODE; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.funeat.exception.ErrorCode; import com.funeat.exception.GlobalException; +import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @RestControllerAdvice public class GlobalControllerAdvice { - private static final ErrorCode errorCode = new ErrorCode<>("0000", - HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "알 수 없는 에러입니다."); - private final Logger log = LoggerFactory.getLogger(this.getClass()); private final ObjectMapper objectMapper; @@ -25,6 +29,36 @@ public GlobalControllerAdvice(final ObjectMapper objectMapper) { this.objectMapper = objectMapper; } + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity handleParamValidationException(final MethodArgumentNotValidException e, + final HttpServletRequest request) { + final String filedErrorLogMessages = getMethodArgumentExceptionLogMessage(e); + + final String errorMessage = e.getBindingResult() + .getAllErrors() + .stream() + .map(DefaultMessageSourceResolvable::getDefaultMessage) + .collect(Collectors.joining(", ")); + + final String responseErrorMessage = errorMessage + ". " + REQUEST_VALID_ERROR_CODE.getMessage(); + + final ErrorCode errorCode = new ErrorCode<>(REQUEST_VALID_ERROR_CODE.getCode(), responseErrorMessage); + + log.warn("method = {}, request = {}, message = {} ", request.getMethod(), request.getRequestURI(), + filedErrorLogMessages); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errorCode); + } + + private static String getMethodArgumentExceptionLogMessage(final MethodArgumentNotValidException e) { + final String filedErrorMessages = e.getBindingResult() + .getFieldErrors() + .stream() + .map(FieldError::getField) + .collect(Collectors.joining(", ")); + + return filedErrorMessages + " 요청 실패"; + } + @ExceptionHandler(GlobalException.class) public ResponseEntity handleGlobalException(final GlobalException e, final HttpServletRequest request) throws JsonProcessingException { @@ -36,8 +70,10 @@ public ResponseEntity handleGlobalException(final GlobalException e, final Ht @ExceptionHandler(Exception.class) public ResponseEntity handleServerException(final Exception e) { - log.error("code = {} ", errorCode.getCode(), e); + log.error("", e); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorCode); + ErrorCode errorCode = new ErrorCode<>(UNKNOWN_SERVER_ERROR_CODE.getCode(), + UNKNOWN_SERVER_ERROR_CODE.getMessage()); + return ResponseEntity.status(UNKNOWN_SERVER_ERROR_CODE.getStatus()).body(errorCode); } } diff --git a/backend/src/main/java/com/funeat/member/dto/MemberRequest.java b/backend/src/main/java/com/funeat/member/dto/MemberRequest.java index a4800c6ed..557ad201c 100644 --- a/backend/src/main/java/com/funeat/member/dto/MemberRequest.java +++ b/backend/src/main/java/com/funeat/member/dto/MemberRequest.java @@ -1,8 +1,13 @@ package com.funeat.member.dto; +import javax.validation.constraints.NotBlank; + public class MemberRequest { + @NotBlank(message = "닉네임을 확인해주세요") private final String nickname; + + @NotBlank(message = "프로필 이미지를 확인해주세요") private final String profileImage; public MemberRequest(final String nickname, final String profileImage) { diff --git a/backend/src/main/java/com/funeat/member/presentation/MemberApiController.java b/backend/src/main/java/com/funeat/member/presentation/MemberApiController.java index 546c5665d..a01ea5b2a 100644 --- a/backend/src/main/java/com/funeat/member/presentation/MemberApiController.java +++ b/backend/src/main/java/com/funeat/member/presentation/MemberApiController.java @@ -5,6 +5,7 @@ import com.funeat.member.application.MemberService; import com.funeat.member.dto.MemberProfileResponse; import com.funeat.member.dto.MemberRequest; +import javax.validation.Valid; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -32,7 +33,7 @@ public ResponseEntity getMemberProfile( @PutMapping("/api/members") public ResponseEntity putMemberProfile(@AuthenticationPrincipal final LoginInfo loginInfo, - @RequestBody final MemberRequest request) { + @RequestBody @Valid final MemberRequest request) { final Long memberId = loginInfo.getId(); memberService.modify(memberId, request); From 30798533ea60696021d503701303980e6620d567 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 01:28:49 +0900 Subject: [PATCH 05/30] =?UTF-8?q?feat:=20Category=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC,=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/GlobalControllerAdvice.java | 5 +-- .../member/exception/MemberException.java | 2 +- .../product/application/ProductService.java | 5 ++- .../product/exception/CategoryErrorCode.java | 31 +++++++++++++++++++ .../product/exception/CategoryException.java | 18 +++++++++++ 5 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java create mode 100644 backend/src/main/java/com/funeat/product/exception/CategoryException.java diff --git a/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java b/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java index 0a3146417..cea4dcb2e 100644 --- a/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java +++ b/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java @@ -44,7 +44,7 @@ public ResponseEntity handleParamValidationException(final MethodArgumentNotV final ErrorCode errorCode = new ErrorCode<>(REQUEST_VALID_ERROR_CODE.getCode(), responseErrorMessage); - log.warn("method = {}, request = {}, message = {} ", request.getMethod(), request.getRequestURI(), + log.warn("{} = {}, message = {} ", request.getMethod(), request.getRequestURI(), filedErrorLogMessages); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errorCode); } @@ -62,7 +62,8 @@ private static String getMethodArgumentExceptionLogMessage(final MethodArgumentN @ExceptionHandler(GlobalException.class) public ResponseEntity handleGlobalException(final GlobalException e, final HttpServletRequest request) throws JsonProcessingException { - log.warn("request = {} code = {} message = {} info = {}", request.getRequestURI(), e.getErrorCode().getCode(), + log.warn("{} = {} code = {} message = {} info = {}", request.getMethod(), request.getRequestURI(), + e.getErrorCode().getCode(), e.getErrorCode().getMessage(), objectMapper.writeValueAsString(e.getErrorCode().getInfo())); return ResponseEntity.status(e.getStatus()).body(e.getErrorCode().getMessage()); diff --git a/backend/src/main/java/com/funeat/member/exception/MemberException.java b/backend/src/main/java/com/funeat/member/exception/MemberException.java index 92f48caae..92d24ce02 100644 --- a/backend/src/main/java/com/funeat/member/exception/MemberException.java +++ b/backend/src/main/java/com/funeat/member/exception/MemberException.java @@ -12,7 +12,7 @@ public MemberException(final HttpStatus status, final ErrorCode errorCode) { public static class MemberNotFoundException extends MemberException { public MemberNotFoundException(final MemberErrorCode errorCode, final Long memberId) { - super(errorCode.getStatus(), new ErrorCode<>(errorCode.getMessage(), errorCode.getCode(), memberId)); + super(errorCode.getStatus(), new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), memberId)); } } } diff --git a/backend/src/main/java/com/funeat/product/application/ProductService.java b/backend/src/main/java/com/funeat/product/application/ProductService.java index f4c864df7..bf7d564cf 100644 --- a/backend/src/main/java/com/funeat/product/application/ProductService.java +++ b/backend/src/main/java/com/funeat/product/application/ProductService.java @@ -1,5 +1,7 @@ package com.funeat.product.application; +import static com.funeat.product.exception.CategoryErrorCode.CATEGORY_NOF_FOUND; + import com.funeat.product.domain.Category; import com.funeat.product.domain.Product; import com.funeat.product.dto.ProductInCategoryDto; @@ -9,6 +11,7 @@ import com.funeat.product.dto.ProductsInCategoryResponse; import com.funeat.product.dto.RankingProductDto; import com.funeat.product.dto.RankingProductsResponse; +import com.funeat.product.exception.CategoryException.CategoryNotFoundException; import com.funeat.product.persistence.CategoryRepository; import com.funeat.product.persistence.ProductRepository; import com.funeat.review.persistence.ReviewTagRepository; @@ -44,7 +47,7 @@ public ProductService(final CategoryRepository categoryRepository, final Product public ProductsInCategoryResponse getAllProductsInCategory(final Long categoryId, final Pageable pageable) { final Category category = categoryRepository.findById(categoryId) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new CategoryNotFoundException(CATEGORY_NOF_FOUND, categoryId)); final Page pages = getAllProductsInCategory(pageable, category); diff --git a/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java b/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java new file mode 100644 index 000000000..33238701a --- /dev/null +++ b/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java @@ -0,0 +1,31 @@ +package com.funeat.product.exception; + +import org.springframework.http.HttpStatus; + +public enum CategoryErrorCode { + + CATEGORY_NOF_FOUND(HttpStatus.BAD_REQUEST, "존재하지 않는 카테고리입니다. 카테고리 id를 확인하세요.", "2001"), + ; + + private final HttpStatus status; + private final String message; + private final String code; + + CategoryErrorCode(final HttpStatus status, final String message, final String code) { + this.status = status; + this.message = message; + this.code = code; + } + + public HttpStatus getStatus() { + return status; + } + + public String getMessage() { + return message; + } + + public String getCode() { + return code; + } +} diff --git a/backend/src/main/java/com/funeat/product/exception/CategoryException.java b/backend/src/main/java/com/funeat/product/exception/CategoryException.java new file mode 100644 index 000000000..68fea77ae --- /dev/null +++ b/backend/src/main/java/com/funeat/product/exception/CategoryException.java @@ -0,0 +1,18 @@ +package com.funeat.product.exception; + +import com.funeat.exception.ErrorCode; +import com.funeat.exception.GlobalException; +import org.springframework.http.HttpStatus; + +public class CategoryException extends GlobalException { + + public CategoryException(final HttpStatus status, final ErrorCode errorCode) { + super(status, errorCode); + } + + public static class CategoryNotFoundException extends CategoryException { + public CategoryNotFoundException(final CategoryErrorCode errorCode, final Long categoryId) { + super(errorCode.getStatus(), new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), categoryId)); + } + } +} From 7d906228cdea7ba4624ec56ed04864655d795f5d Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 01:37:43 +0900 Subject: [PATCH 06/30] =?UTF-8?q?refactor:=20bad=20request=20->=20not=20fo?= =?UTF-8?q?und=20=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/funeat/member/exception/MemberErrorCode.java | 2 +- .../java/com/funeat/product/exception/CategoryErrorCode.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/funeat/member/exception/MemberErrorCode.java b/backend/src/main/java/com/funeat/member/exception/MemberErrorCode.java index 06cf9b0f0..fea20f7c1 100644 --- a/backend/src/main/java/com/funeat/member/exception/MemberErrorCode.java +++ b/backend/src/main/java/com/funeat/member/exception/MemberErrorCode.java @@ -4,7 +4,7 @@ public enum MemberErrorCode { - MEMBER_NOF_FOUND(HttpStatus.BAD_REQUEST, "존재하지 않는 회원입니다. 회원 id를 확인하세요.", "1001"), + MEMBER_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 회원입니다. 회원 id를 확인하세요.", "1001"), ; private final HttpStatus status; diff --git a/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java b/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java index 33238701a..be556b573 100644 --- a/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java +++ b/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java @@ -4,7 +4,7 @@ public enum CategoryErrorCode { - CATEGORY_NOF_FOUND(HttpStatus.BAD_REQUEST, "존재하지 않는 카테고리입니다. 카테고리 id를 확인하세요.", "2001"), + CATEGORY_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 카테고리입니다. 카테고리 id를 확인하세요.", "2001"), ; private final HttpStatus status; From b06f4239f52d0f70a7fd9538876fbdef6e62db11 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 01:38:23 +0900 Subject: [PATCH 07/30] =?UTF-8?q?feat:=20Product=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC,=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/application/ProductService.java | 4 ++- .../product/exception/ProductErrorCode.java | 31 +++++++++++++++++++ .../product/exception/ProductException.java | 18 +++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 backend/src/main/java/com/funeat/product/exception/ProductErrorCode.java create mode 100644 backend/src/main/java/com/funeat/product/exception/ProductException.java diff --git a/backend/src/main/java/com/funeat/product/application/ProductService.java b/backend/src/main/java/com/funeat/product/application/ProductService.java index bf7d564cf..a78bf80b2 100644 --- a/backend/src/main/java/com/funeat/product/application/ProductService.java +++ b/backend/src/main/java/com/funeat/product/application/ProductService.java @@ -1,6 +1,7 @@ package com.funeat.product.application; import static com.funeat.product.exception.CategoryErrorCode.CATEGORY_NOF_FOUND; +import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOF_FOUND; import com.funeat.product.domain.Category; import com.funeat.product.domain.Product; @@ -12,6 +13,7 @@ import com.funeat.product.dto.RankingProductDto; import com.funeat.product.dto.RankingProductsResponse; import com.funeat.product.exception.CategoryException.CategoryNotFoundException; +import com.funeat.product.exception.ProductException.ProductNotFoundException; import com.funeat.product.persistence.CategoryRepository; import com.funeat.product.persistence.ProductRepository; import com.funeat.review.persistence.ReviewTagRepository; @@ -67,7 +69,7 @@ private Page getAllProductsInCategory(final Pageable pagea public ProductResponse findProductDetail(final Long productId) { final Product product = productRepository.findById(productId) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new ProductNotFoundException(PRODUCT_NOF_FOUND, productId)); final List tags = reviewTagRepository.findTop3TagsByReviewIn(productId, PageRequest.of(TOP, THREE)); diff --git a/backend/src/main/java/com/funeat/product/exception/ProductErrorCode.java b/backend/src/main/java/com/funeat/product/exception/ProductErrorCode.java new file mode 100644 index 000000000..194111d06 --- /dev/null +++ b/backend/src/main/java/com/funeat/product/exception/ProductErrorCode.java @@ -0,0 +1,31 @@ +package com.funeat.product.exception; + +import org.springframework.http.HttpStatus; + +public enum ProductErrorCode { + + PRODUCT_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 상품입니다. 상품 id를 확인하세요.", "3001"), + ; + + private final HttpStatus status; + private final String message; + private final String code; + + ProductErrorCode(final HttpStatus status, final String message, final String code) { + this.status = status; + this.message = message; + this.code = code; + } + + public HttpStatus getStatus() { + return status; + } + + public String getMessage() { + return message; + } + + public String getCode() { + return code; + } +} diff --git a/backend/src/main/java/com/funeat/product/exception/ProductException.java b/backend/src/main/java/com/funeat/product/exception/ProductException.java new file mode 100644 index 000000000..c9b1f1720 --- /dev/null +++ b/backend/src/main/java/com/funeat/product/exception/ProductException.java @@ -0,0 +1,18 @@ +package com.funeat.product.exception; + +import com.funeat.exception.ErrorCode; +import com.funeat.exception.GlobalException; +import org.springframework.http.HttpStatus; + +public class ProductException extends GlobalException { + + public ProductException(final HttpStatus status, final ErrorCode errorCode) { + super(status, errorCode); + } + + public static class ProductNotFoundException extends ProductException { + public ProductNotFoundException(final ProductErrorCode errorCode, final Long productId) { + super(errorCode.getStatus(), new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), productId)); + } + } +} From ec02b6c35b37be83af617a6cd2f7c74e30fa09c8 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 01:44:04 +0900 Subject: [PATCH 08/30] =?UTF-8?q?refactor:=20RecipeService=20=EC=BB=A4?= =?UTF-8?q?=EC=8A=A4=ED=85=80=20=EC=98=88=EC=99=B8=EB=A1=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/funeat/recipe/application/RecipeService.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/com/funeat/recipe/application/RecipeService.java b/backend/src/main/java/com/funeat/recipe/application/RecipeService.java index 0afca70e7..b352704b7 100644 --- a/backend/src/main/java/com/funeat/recipe/application/RecipeService.java +++ b/backend/src/main/java/com/funeat/recipe/application/RecipeService.java @@ -1,8 +1,14 @@ package com.funeat.recipe.application; +import static com.funeat.member.exception.MemberErrorCode.MEMBER_NOF_FOUND; +import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOF_FOUND; + +import com.funeat.common.ImageService; import com.funeat.member.domain.Member; +import com.funeat.member.exception.MemberException.MemberNotFoundException; import com.funeat.member.persistence.MemberRepository; import com.funeat.product.domain.ProductRecipe; +import com.funeat.product.exception.ProductException.ProductNotFoundException; import com.funeat.product.persistence.ProductRecipeRepository; import com.funeat.product.persistence.ProductRepository; import com.funeat.recipe.domain.Recipe; @@ -10,7 +16,6 @@ import com.funeat.recipe.dto.RecipeCreateRequest; import com.funeat.recipe.persistence.RecipeImageRepository; import com.funeat.recipe.persistence.RecipeRepository; -import com.funeat.common.ImageService; import java.util.List; import java.util.Objects; import org.springframework.stereotype.Service; @@ -44,13 +49,13 @@ public RecipeService(final MemberRepository memberRepository, final ProductRepos @Transactional public Long create(final Long memberId, final List images, final RecipeCreateRequest request) { final Member member = memberRepository.findById(memberId) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOF_FOUND, memberId)); final Recipe savedRecipe = recipeRepository.save(new Recipe(request.getName(), request.getContent(), member)); request.getProductIds() .stream() .map(it -> productRepository.findById(it) - .orElseThrow(IllegalArgumentException::new)) + .orElseThrow(() -> new ProductNotFoundException(PRODUCT_NOF_FOUND, it))) .forEach(it -> productRecipeRepository.save(new ProductRecipe(it, savedRecipe))); if (Objects.nonNull(images)) { From 3519184dc419c42698f0132f33ac1e6228fac04b Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 01:46:37 +0900 Subject: [PATCH 09/30] =?UTF-8?q?refactor:=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/com/funeat/common/WebConfig.java | 2 +- .../funeat/recipe/{utill => util}/RecipeHandlerInterceptor.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename backend/src/main/java/com/funeat/recipe/{utill => util}/RecipeHandlerInterceptor.java (96%) diff --git a/backend/src/main/java/com/funeat/common/WebConfig.java b/backend/src/main/java/com/funeat/common/WebConfig.java index 8c43fdeab..1d89f8aa7 100644 --- a/backend/src/main/java/com/funeat/common/WebConfig.java +++ b/backend/src/main/java/com/funeat/common/WebConfig.java @@ -2,7 +2,7 @@ import com.funeat.auth.util.AuthArgumentResolver; import com.funeat.auth.util.AuthHandlerInterceptor; -import com.funeat.recipe.utill.RecipeHandlerInterceptor; +import com.funeat.recipe.util.RecipeHandlerInterceptor; import java.util.List; import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; diff --git a/backend/src/main/java/com/funeat/recipe/utill/RecipeHandlerInterceptor.java b/backend/src/main/java/com/funeat/recipe/util/RecipeHandlerInterceptor.java similarity index 96% rename from backend/src/main/java/com/funeat/recipe/utill/RecipeHandlerInterceptor.java rename to backend/src/main/java/com/funeat/recipe/util/RecipeHandlerInterceptor.java index 08e484c78..8bd3b7bcb 100644 --- a/backend/src/main/java/com/funeat/recipe/utill/RecipeHandlerInterceptor.java +++ b/backend/src/main/java/com/funeat/recipe/util/RecipeHandlerInterceptor.java @@ -1,4 +1,4 @@ -package com.funeat.recipe.utill; +package com.funeat.recipe.util; import com.funeat.auth.exception.AuthErrorCode; import com.funeat.auth.exception.AuthException.NotLoggedInException; From 113f9f126bd48798a1291aea2e62d05fe26dc7cf Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 03:21:03 +0900 Subject: [PATCH 10/30] =?UTF-8?q?feat:=20Review=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC,=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/exception/CategoryErrorCode.java | 2 +- .../product/exception/ProductErrorCode.java | 2 +- .../recipe/dto/RecipeCreateRequest.java | 9 ++++++ .../presentation/RecipeApiController.java | 8 +++-- .../review/application/ReviewService.java | 19 ++++++++---- .../review/exception/ReviewErrorCode.java | 31 +++++++++++++++++++ .../review/exception/ReviewException.java | 18 +++++++++++ .../presentation/ReviewApiController.java | 5 +-- .../presentation/dto/ReviewCreateRequest.java | 10 ++++++ .../dto/ReviewFavoriteRequest.java | 2 ++ 10 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 backend/src/main/java/com/funeat/review/exception/ReviewErrorCode.java create mode 100644 backend/src/main/java/com/funeat/review/exception/ReviewException.java diff --git a/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java b/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java index be556b573..346ac0d36 100644 --- a/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java +++ b/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java @@ -4,7 +4,7 @@ public enum CategoryErrorCode { - CATEGORY_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 카테고리입니다. 카테고리 id를 확인하세요.", "2001"), + CATEGORY_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 카테고리입니다. 카테고리 id를 확인하세요.", "3001"), ; private final HttpStatus status; diff --git a/backend/src/main/java/com/funeat/product/exception/ProductErrorCode.java b/backend/src/main/java/com/funeat/product/exception/ProductErrorCode.java index 194111d06..9a956b99b 100644 --- a/backend/src/main/java/com/funeat/product/exception/ProductErrorCode.java +++ b/backend/src/main/java/com/funeat/product/exception/ProductErrorCode.java @@ -4,7 +4,7 @@ public enum ProductErrorCode { - PRODUCT_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 상품입니다. 상품 id를 확인하세요.", "3001"), + PRODUCT_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 상품입니다. 상품 id를 확인하세요.", "4001"), ; private final HttpStatus status; diff --git a/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java b/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java index 498236d76..c31b04727 100644 --- a/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java +++ b/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java @@ -1,11 +1,20 @@ package com.funeat.recipe.dto; import java.util.List; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; public class RecipeCreateRequest { + @NotBlank(message = "이름을 확인해 주세요") private final String name; + + @NotNull(message = "상품 ID 목록을 확인해 주세요") + @Size(min = 1, message = "적어도 1개의 상품 ID가 필요합니다") private final List productIds; + + @NotBlank(message = "레시피 내용을 확인해 주세요") private final String content; public RecipeCreateRequest(final String name, final List productIds, final String content) { diff --git a/backend/src/main/java/com/funeat/recipe/presentation/RecipeApiController.java b/backend/src/main/java/com/funeat/recipe/presentation/RecipeApiController.java index 87badbfd4..55625db0f 100644 --- a/backend/src/main/java/com/funeat/recipe/presentation/RecipeApiController.java +++ b/backend/src/main/java/com/funeat/recipe/presentation/RecipeApiController.java @@ -6,6 +6,7 @@ import com.funeat.recipe.dto.RecipeCreateRequest; import java.net.URI; import java.util.List; +import javax.validation.Valid; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; @@ -14,7 +15,7 @@ import org.springframework.web.multipart.MultipartFile; @RestController -public class RecipeApiController implements RecipeController{ +public class RecipeApiController implements RecipeController { private final RecipeService recipeService; @@ -22,10 +23,11 @@ public RecipeApiController(final RecipeService recipeService) { this.recipeService = recipeService; } - @PostMapping(value = "/api/recipes", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_JSON_VALUE}) + @PostMapping(value = "/api/recipes", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, + MediaType.APPLICATION_JSON_VALUE}) public ResponseEntity writeRecipe(@AuthenticationPrincipal final LoginInfo loginInfo, @RequestPart(required = false) final List images, - @RequestPart final RecipeCreateRequest recipeRequest) { + @RequestPart @Valid final RecipeCreateRequest recipeRequest) { final Long recipeId = recipeService.create(loginInfo.getId(), images, recipeRequest); return ResponseEntity.created(URI.create("/api/recipes/" + recipeId)).build(); diff --git a/backend/src/main/java/com/funeat/review/application/ReviewService.java b/backend/src/main/java/com/funeat/review/application/ReviewService.java index 6b9500c28..99af0ba4a 100644 --- a/backend/src/main/java/com/funeat/review/application/ReviewService.java +++ b/backend/src/main/java/com/funeat/review/application/ReviewService.java @@ -1,14 +1,21 @@ package com.funeat.review.application; +import static com.funeat.member.exception.MemberErrorCode.MEMBER_NOF_FOUND; +import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOF_FOUND; +import static com.funeat.review.exception.ReviewErrorCode.REVIEW_NOF_FOUND; + import com.funeat.common.ImageService; import com.funeat.member.domain.Member; import com.funeat.member.domain.favorite.ReviewFavorite; +import com.funeat.member.exception.MemberException.MemberNotFoundException; import com.funeat.member.persistence.MemberRepository; import com.funeat.member.persistence.ReviewFavoriteRepository; import com.funeat.product.domain.Product; +import com.funeat.product.exception.ProductException.ProductNotFoundException; import com.funeat.product.persistence.ProductRepository; import com.funeat.review.domain.Review; import com.funeat.review.domain.ReviewTag; +import com.funeat.review.exception.ReviewException.ReviewNotFoundException; import com.funeat.review.persistence.ReviewRepository; import com.funeat.review.persistence.ReviewTagRepository; import com.funeat.review.presentation.dto.RankingReviewDto; @@ -58,9 +65,9 @@ public ReviewService(final ReviewRepository reviewRepository, final TagRepositor public void create(final Long productId, final Long memberId, final MultipartFile image, final ReviewCreateRequest reviewRequest) { final Member findMember = memberRepository.findById(memberId) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOF_FOUND, memberId)); final Product findProduct = productRepository.findById(productId) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new ProductNotFoundException(PRODUCT_NOF_FOUND, productId)); final Review savedReview; if (Objects.isNull(image)) { @@ -89,9 +96,9 @@ public void create(final Long productId, final Long memberId, final MultipartFil @Transactional public void likeReview(final Long reviewId, final Long memberId, final ReviewFavoriteRequest request) { final Member findMember = memberRepository.findById(memberId) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOF_FOUND, memberId)); final Review findReview = reviewRepository.findById(reviewId) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new ReviewNotFoundException(REVIEW_NOF_FOUND, reviewId)); final ReviewFavorite savedReviewFavorite = reviewFavoriteRepository.findByMemberAndReview(findMember, findReview).orElseGet(() -> saveReviewFavorite(findMember, findReview, request.getFavorite())); @@ -108,10 +115,10 @@ private ReviewFavorite saveReviewFavorite(final Member member, final Review revi public SortingReviewsResponse sortingReviews(final Long productId, final Pageable pageable, final Long memberId) { final Member member = memberRepository.findById(memberId) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOF_FOUND, memberId)); final Product product = productRepository.findById(productId) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new ProductNotFoundException(PRODUCT_NOF_FOUND, productId)); final Page reviewPage = reviewRepository.findReviewsByProduct(pageable, product); diff --git a/backend/src/main/java/com/funeat/review/exception/ReviewErrorCode.java b/backend/src/main/java/com/funeat/review/exception/ReviewErrorCode.java new file mode 100644 index 000000000..0661898d3 --- /dev/null +++ b/backend/src/main/java/com/funeat/review/exception/ReviewErrorCode.java @@ -0,0 +1,31 @@ +package com.funeat.review.exception; + +import org.springframework.http.HttpStatus; + +public enum ReviewErrorCode { + + REVIEW_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 리뷰입니다. 리뷰 id를 확인하세요.", "5001"), + ; + + private final HttpStatus status; + private final String message; + private final String code; + + ReviewErrorCode(final HttpStatus status, final String message, final String code) { + this.status = status; + this.message = message; + this.code = code; + } + + public HttpStatus getStatus() { + return status; + } + + public String getMessage() { + return message; + } + + public String getCode() { + return code; + } +} diff --git a/backend/src/main/java/com/funeat/review/exception/ReviewException.java b/backend/src/main/java/com/funeat/review/exception/ReviewException.java new file mode 100644 index 000000000..4699f3af6 --- /dev/null +++ b/backend/src/main/java/com/funeat/review/exception/ReviewException.java @@ -0,0 +1,18 @@ +package com.funeat.review.exception; + +import com.funeat.exception.ErrorCode; +import com.funeat.exception.GlobalException; +import org.springframework.http.HttpStatus; + +public class ReviewException extends GlobalException { + + public ReviewException(final HttpStatus status, final ErrorCode errorCode) { + super(status, errorCode); + } + + public static class ReviewNotFoundException extends ReviewException { + public ReviewNotFoundException(final ReviewErrorCode errorCode, final Long reviewId) { + super(errorCode.getStatus(), new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), reviewId)); + } + } +} diff --git a/backend/src/main/java/com/funeat/review/presentation/ReviewApiController.java b/backend/src/main/java/com/funeat/review/presentation/ReviewApiController.java index d50526079..b7ec97062 100644 --- a/backend/src/main/java/com/funeat/review/presentation/ReviewApiController.java +++ b/backend/src/main/java/com/funeat/review/presentation/ReviewApiController.java @@ -8,6 +8,7 @@ import com.funeat.review.presentation.dto.ReviewFavoriteRequest; import com.funeat.review.presentation.dto.SortingReviewsResponse; import java.net.URI; +import javax.validation.Valid; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.http.MediaType; @@ -35,7 +36,7 @@ public ReviewApiController(final ReviewService reviewService) { public ResponseEntity writeReview(@PathVariable final Long productId, @AuthenticationPrincipal final LoginInfo loginInfo, @RequestPart(required = false) final MultipartFile image, - @RequestPart final ReviewCreateRequest reviewRequest) { + @RequestPart @Valid final ReviewCreateRequest reviewRequest) { reviewService.create(productId, loginInfo.getId(), image, reviewRequest); return ResponseEntity.created(URI.create("/api/products/" + productId)).build(); @@ -44,7 +45,7 @@ public ResponseEntity writeReview(@PathVariable final Long productId, @PatchMapping("/api/products/{productId}/reviews/{reviewId}") public ResponseEntity toggleLikeReview(@PathVariable Long reviewId, @AuthenticationPrincipal LoginInfo loginInfo, - @RequestBody ReviewFavoriteRequest request) { + @RequestBody @Valid ReviewFavoriteRequest request) { reviewService.likeReview(reviewId, loginInfo.getId(), request); return ResponseEntity.noContent().build(); diff --git a/backend/src/main/java/com/funeat/review/presentation/dto/ReviewCreateRequest.java b/backend/src/main/java/com/funeat/review/presentation/dto/ReviewCreateRequest.java index 127bd347d..19e4fcc09 100644 --- a/backend/src/main/java/com/funeat/review/presentation/dto/ReviewCreateRequest.java +++ b/backend/src/main/java/com/funeat/review/presentation/dto/ReviewCreateRequest.java @@ -1,12 +1,22 @@ package com.funeat.review.presentation.dto; import java.util.List; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; public class ReviewCreateRequest { private final Long rating; + + @NotNull(message = "태그 ID 목록을 확인해 주세요") + @Size(min = 1, message = "적어도 1개의 태그 ID가 필요합니다") private final List tagIds; + + @NotBlank(message = "리뷰 내용은 공백을 허용하지 않습니다") private final String content; + + @NotNull(message = "재구매 여부를 입력해주세요") private final Boolean rebuy; public ReviewCreateRequest(final Long rating, final List tagIds, final String content, final Boolean rebuy) { diff --git a/backend/src/main/java/com/funeat/review/presentation/dto/ReviewFavoriteRequest.java b/backend/src/main/java/com/funeat/review/presentation/dto/ReviewFavoriteRequest.java index 6dce84076..973462d64 100644 --- a/backend/src/main/java/com/funeat/review/presentation/dto/ReviewFavoriteRequest.java +++ b/backend/src/main/java/com/funeat/review/presentation/dto/ReviewFavoriteRequest.java @@ -2,9 +2,11 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import javax.validation.constraints.NotNull; public class ReviewFavoriteRequest { + @NotNull(message = "좋아요를 확인해주세요") private final Boolean favorite; @JsonCreator From 48ae9f807f955393aa7c4f862cf0d6b42433324d Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 03:21:21 +0900 Subject: [PATCH 11/30] =?UTF-8?q?feat:=20=EC=98=88=EC=99=B8=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=20=EC=A7=80=EC=A0=90=20=EB=A1=9C=EA=B7=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/GlobalControllerAdvice.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java b/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java index cea4dcb2e..c9fbd355b 100644 --- a/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java +++ b/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java @@ -62,11 +62,21 @@ private static String getMethodArgumentExceptionLogMessage(final MethodArgumentN @ExceptionHandler(GlobalException.class) public ResponseEntity handleGlobalException(final GlobalException e, final HttpServletRequest request) throws JsonProcessingException { - log.warn("{} = {} code = {} message = {} info = {}", request.getMethod(), request.getRequestURI(), - e.getErrorCode().getCode(), - e.getErrorCode().getMessage(), objectMapper.writeValueAsString(e.getErrorCode().getInfo())); + final String exceptionSource = getExceptionSource(e); + log.warn("source = {} , {} = {} code = {} message = {} info = {}", exceptionSource, request.getMethod(), + request.getRequestURI(), e.getErrorCode().getCode(), e.getErrorCode().getMessage(), + objectMapper.writeValueAsString(e.getErrorCode().getInfo())); - return ResponseEntity.status(e.getStatus()).body(e.getErrorCode().getMessage()); + ErrorCode errorCode = new ErrorCode<>(e.getErrorCode().getCode(), e.getMessage()); + return ResponseEntity.status(e.getStatus()).body(errorCode); + } + + private String getExceptionSource(final Exception e) { + StackTraceElement[] stackTrace = e.getStackTrace(); + if (stackTrace.length > 0) { + return stackTrace[0].toString(); + } + return "Unknown location"; } @ExceptionHandler(Exception.class) From 7de6bdec8c59438212b71359c302a712a1d5c313 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 16:34:56 +0900 Subject: [PATCH 12/30] =?UTF-8?q?feat:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=ED=83=80=EC=9E=85=20=EC=98=88=EC=99=B8=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/StringToCategoryTypeConverter.java | 2 +- .../com/funeat/exception/CommonErrorCode.java | 2 +- .../presentation/GlobalControllerAdvice.java | 16 ++++++++++++++-- .../com/funeat/product/domain/CategoryType.java | 14 +++++++++++++- .../product/exception/CategoryErrorCode.java | 1 + .../product/exception/CategoryException.java | 6 ++++++ 6 files changed, 36 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/com/funeat/common/StringToCategoryTypeConverter.java b/backend/src/main/java/com/funeat/common/StringToCategoryTypeConverter.java index 642c82a8c..8873f0a7b 100644 --- a/backend/src/main/java/com/funeat/common/StringToCategoryTypeConverter.java +++ b/backend/src/main/java/com/funeat/common/StringToCategoryTypeConverter.java @@ -7,6 +7,6 @@ public class StringToCategoryTypeConverter implements Converter handleParamValidationException(final Exception e, final HttpServletRequest request) { + log.warn("{} = {}, code = {} message = {}", request.getMethod(), request.getRequestURI(), + REQUEST_VALID_ERROR_CODE.getCode(), e.getMessage()); + + final ErrorCode errorCode = new ErrorCode<>(REQUEST_VALID_ERROR_CODE.getCode(), + REQUEST_VALID_ERROR_CODE.getMessage()); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errorCode); + } + @ExceptionHandler(MethodArgumentNotValidException.class) public ResponseEntity handleParamValidationException(final MethodArgumentNotValidException e, final HttpServletRequest request) { @@ -44,9 +56,9 @@ public ResponseEntity handleParamValidationException(final MethodArgumentNotV final ErrorCode errorCode = new ErrorCode<>(REQUEST_VALID_ERROR_CODE.getCode(), responseErrorMessage); - log.warn("{} = {}, message = {} ", request.getMethod(), request.getRequestURI(), + log.warn("{} = {}, message = {} ", request.getMethod(), request.getRequestURI(), filedErrorLogMessages); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errorCode); + return ResponseEntity.status(REQUEST_VALID_ERROR_CODE.getStatus()).body(errorCode); } private static String getMethodArgumentExceptionLogMessage(final MethodArgumentNotValidException e) { diff --git a/backend/src/main/java/com/funeat/product/domain/CategoryType.java b/backend/src/main/java/com/funeat/product/domain/CategoryType.java index ee55c80b6..5c4f37c01 100644 --- a/backend/src/main/java/com/funeat/product/domain/CategoryType.java +++ b/backend/src/main/java/com/funeat/product/domain/CategoryType.java @@ -1,5 +1,17 @@ package com.funeat.product.domain; +import static com.funeat.product.exception.CategoryErrorCode.CATEGORY_TYPE_NOF_FOUND; + +import com.funeat.product.exception.CategoryException.CategoryTypeNotFoundException; +import java.util.Arrays; + public enum CategoryType { - FOOD, STORE + FOOD, STORE; + + public static CategoryType findCategoryType(final String type) { + return Arrays.stream(values()) + .filter(it -> it.name().equals(type)) + .findFirst() + .orElseThrow(() -> new CategoryTypeNotFoundException(CATEGORY_TYPE_NOF_FOUND, type)); + } } diff --git a/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java b/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java index 346ac0d36..0650eb299 100644 --- a/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java +++ b/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java @@ -5,6 +5,7 @@ public enum CategoryErrorCode { CATEGORY_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 카테고리입니다. 카테고리 id를 확인하세요.", "3001"), + CATEGORY_TYPE_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 카테고리 타입입니다. 카테고리 타입 확인하세요.", "3002"), ; private final HttpStatus status; diff --git a/backend/src/main/java/com/funeat/product/exception/CategoryException.java b/backend/src/main/java/com/funeat/product/exception/CategoryException.java index 68fea77ae..6402c250a 100644 --- a/backend/src/main/java/com/funeat/product/exception/CategoryException.java +++ b/backend/src/main/java/com/funeat/product/exception/CategoryException.java @@ -15,4 +15,10 @@ public CategoryNotFoundException(final CategoryErrorCode errorCode, final Long c super(errorCode.getStatus(), new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), categoryId)); } } + + public static class CategoryTypeNotFoundException extends CategoryException { + public CategoryTypeNotFoundException(final CategoryErrorCode errorCode, final String type) { + super(errorCode.getStatus(), new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), type)); + } + } } From d375511c25394d6bccb070c69b47430451bfc3d5 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 16:41:54 +0900 Subject: [PATCH 13/30] =?UTF-8?q?feat:=20categoryType=20=EB=8C=80=EC=86=8C?= =?UTF-8?q?=EB=AC=B8=EC=9E=90=20=EA=B5=AC=EB=B6=84=20=EC=95=88=ED=95=98?= =?UTF-8?q?=EA=B3=A0=20=EB=B9=84=EA=B5=90=ED=95=98=EA=B2=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/funeat/product/domain/CategoryType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/funeat/product/domain/CategoryType.java b/backend/src/main/java/com/funeat/product/domain/CategoryType.java index 5c4f37c01..87cf18275 100644 --- a/backend/src/main/java/com/funeat/product/domain/CategoryType.java +++ b/backend/src/main/java/com/funeat/product/domain/CategoryType.java @@ -10,7 +10,7 @@ public enum CategoryType { public static CategoryType findCategoryType(final String type) { return Arrays.stream(values()) - .filter(it -> it.name().equals(type)) + .filter(it -> it.name().equals(type.toUpperCase())) .findFirst() .orElseThrow(() -> new CategoryTypeNotFoundException(CATEGORY_TYPE_NOF_FOUND, type)); } From 5a7226ff5cb7a213b62f9c4f9c3333df8f33a686 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 16:44:31 +0900 Subject: [PATCH 14/30] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=BB=A4=EC=8A=A4=ED=85=80=20=EC=98=88=EC=99=B8=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/funeat/member/application/MemberServiceTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java b/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java index 00da6630b..7258279a0 100644 --- a/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java +++ b/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java @@ -9,6 +9,7 @@ import com.funeat.member.domain.Member; import com.funeat.member.dto.MemberProfileResponse; import com.funeat.member.dto.MemberRequest; +import com.funeat.member.exception.MemberException.MemberNotFoundException; import com.funeat.member.persistence.MemberRepository; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayNameGeneration; @@ -100,7 +101,7 @@ class getMemberProfile_테스트 { // when, then assertThatThrownBy(() -> memberService.getMemberProfile(wrongMemberId)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(MemberNotFoundException.class); } } From 8cd878150272304ad129476bcc22c2b729428dd1 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 19:23:52 +0900 Subject: [PATCH 15/30] =?UTF-8?q?fix:=20custom=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EB=A1=9C=20test=20=ED=86=B5=EA=B3=BC=ED=95=98=EA=B2=8C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/application/MemberServiceTest.java | 6 +----- .../recipe/application/RecipeServiceTest.java | 6 ++++-- .../review/application/ReviewServiceTest.java | 15 +++++++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java b/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java index a89174e56..23ca2083f 100644 --- a/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java +++ b/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java @@ -11,10 +11,6 @@ import com.funeat.member.dto.MemberProfileResponse; import com.funeat.member.dto.MemberRequest; import com.funeat.member.exception.MemberException.MemberNotFoundException; -import com.funeat.member.persistence.MemberRepository; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayNameGeneration; -import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -256,7 +252,7 @@ class modify_실패_테스트 { // when assertThatThrownBy(() -> memberService.modify(wrongMemberId, request)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(MemberNotFoundException.class); } @Test diff --git a/backend/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java b/backend/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java index d84cb9dfe..7df0b4852 100644 --- a/backend/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java +++ b/backend/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java @@ -12,9 +12,11 @@ import com.funeat.common.ServiceTest; import com.funeat.member.domain.Member; +import com.funeat.member.exception.MemberException.MemberNotFoundException; import com.funeat.product.domain.Category; import com.funeat.product.domain.CategoryType; import com.funeat.product.domain.Product; +import com.funeat.product.exception.ProductException.ProductNotFoundException; import com.funeat.recipe.dto.RecipeCreateRequest; import com.funeat.recipe.dto.RecipeDetailResponse; import java.util.List; @@ -129,7 +131,7 @@ class create_실패_테스트 { // when & then assertThatThrownBy(() -> recipeService.create(wrongMemberId, images, request)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(MemberNotFoundException.class); } @Test @@ -157,7 +159,7 @@ class create_실패_테스트 { // when & then assertThatThrownBy(() -> recipeService.create(memberId, images, request)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(ProductNotFoundException.class); } } diff --git a/backend/src/test/java/com/funeat/review/application/ReviewServiceTest.java b/backend/src/test/java/com/funeat/review/application/ReviewServiceTest.java index 92849b1bf..0f0b49b52 100644 --- a/backend/src/test/java/com/funeat/review/application/ReviewServiceTest.java +++ b/backend/src/test/java/com/funeat/review/application/ReviewServiceTest.java @@ -26,7 +26,10 @@ import static org.assertj.core.api.SoftAssertions.assertSoftly; import com.funeat.common.ServiceTest; +import com.funeat.member.exception.MemberException.MemberNotFoundException; +import com.funeat.product.exception.ProductException.ProductNotFoundException; import com.funeat.review.domain.Review; +import com.funeat.review.exception.ReviewException.ReviewNotFoundException; import com.funeat.review.presentation.dto.SortingReviewDto; import com.funeat.tag.domain.Tag; import java.util.List; @@ -134,7 +137,7 @@ class create_실패_테스트 { // when & then assertThatThrownBy(() -> reviewService.create(productId, wrongMemberId, image, request)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(MemberNotFoundException.class); } @Test @@ -160,7 +163,7 @@ class create_실패_테스트 { // when & then assertThatThrownBy(() -> reviewService.create(wrongProductId, memberId, image, request)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(ProductNotFoundException.class); } } @@ -284,7 +287,7 @@ class likeReview_실패_테스트 { // when assertThatThrownBy(() -> reviewService.likeReview(reviewId, wrongMemberId, favoriteRequest)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(MemberNotFoundException.class); } @Test @@ -316,7 +319,7 @@ class likeReview_실패_테스트 { // when assertThatThrownBy(() -> reviewService.likeReview(wrongReviewId, memberId, favoriteRequest)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(ReviewNotFoundException.class); } } @@ -487,7 +490,7 @@ class sortingReviews_실패_테스트 { // when & then assertThatThrownBy(() -> reviewService.sortingReviews(productId, page, wrongMemberId)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(MemberNotFoundException.class); } @Test @@ -514,7 +517,7 @@ class sortingReviews_실패_테스트 { // when & then assertThatThrownBy(() -> reviewService.sortingReviews(wrongProductId, page, member1Id)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(ProductNotFoundException.class); } } From 6e7a9f446fef9d757c51f8b79853575e57fd14cb Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 21:23:14 +0900 Subject: [PATCH 16/30] =?UTF-8?q?feat:=20MemberController=20=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../funeat/acceptance/common/CommonSteps.java | 2 + .../member/MemberAcceptanceTest.java | 104 ++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java b/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java index e1617999e..0f3c7ea99 100644 --- a/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java +++ b/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java @@ -14,6 +14,8 @@ public class CommonSteps { public static final HttpStatus 정상_생성 = HttpStatus.CREATED; public static final HttpStatus 정상_처리_NO_CONTENT = HttpStatus.NO_CONTENT; public static final HttpStatus 리다이렉션_영구_이동 = HttpStatus.FOUND; + public static final HttpStatus 승인되지_않음 = HttpStatus.UNAUTHORIZED; + public static final HttpStatus 잘못된_요청 = HttpStatus.BAD_REQUEST; public static Long LOCATION_헤더에서_ID_추출(final ExtractableResponse response) { return Long.parseLong(response.header(LOCATION).split("/")[2]); diff --git a/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java index 642a6c4fa..75f4abf61 100644 --- a/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java @@ -2,9 +2,13 @@ import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키를_얻는다; import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다; +import static com.funeat.acceptance.common.CommonSteps.승인되지_않음; +import static com.funeat.acceptance.common.CommonSteps.잘못된_요청; import static com.funeat.acceptance.common.CommonSteps.정상_처리; import static com.funeat.acceptance.member.MemberSteps.사용자_정보_수정_요청; import static com.funeat.acceptance.member.MemberSteps.사용자_정보_조회_요청; +import static com.funeat.auth.exception.AuthErrorCode.LOGIN_MEMBER_NOT_FOUND; +import static com.funeat.exception.CommonErrorCode.REQUEST_VALID_ERROR_CODE; import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -16,6 +20,8 @@ import io.restassured.response.Response; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; @SuppressWarnings("NonAsciiCharacters") public class MemberAcceptanceTest extends AcceptanceTest { @@ -40,6 +46,20 @@ class getMemberProfile_성공_테스트 { } } + @Nested + class getMemberProfile_실패_테스트 { + + @Test + void 로그인_하지않은_사용자가_사용자_정보를_확인시_예외가_발생한다() { + // given & when + final var response = 사용자_정보_조회_요청(null); + + // then + STATUS_CODE를_검증한다(response, 승인되지_않음); + 사용자_승인되지_않음을_검증하다(response); + } + } + @Nested class putMemberProfile_성공_테스트 { @@ -60,6 +80,75 @@ class putMemberProfile_성공_테스트 { } } + @Nested + class putMemberProfile_실패_테스트 { + + @Test + void 로그인_하지않은_사용자가_사용자_정보_수정시_예외가_발생한다() { + // given + final var request = new MemberRequest("after", "http://www.after.com"); + + // when + final var response = 사용자_정보_수정_요청(null, request); + + // then + STATUS_CODE를_검증한다(response, 승인되지_않음); + 사용자_승인되지_않음을_검증하다(response); + } + + @ParameterizedTest + @NullAndEmptySource + void 사용자가_사용자_정보_수정할때_닉네임_미기입시_예외가_발생한다(final String nickname) { + // given + final var member = 멤버_멤버1_생성(); + 단일_멤버_저장(member); + + final var loginCookie = 로그인_쿠키를_얻는다(); + final var request = new MemberRequest(nickname, "http://www.after.com"); + + // when + final var response = 사용자_정보_수정_요청(loginCookie, request); + + // then + final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); + final var expectedMessage = "닉네임을 확인해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); + + STATUS_CODE를_검증한다(response, 잘못된_요청); + assertSoftly(softAssertions -> { + softAssertions.assertThat(response.jsonPath().getString("code")) + .isEqualTo(expectedCode); + softAssertions.assertThat(response.jsonPath().getString("message")) + .isEqualTo(expectedMessage); + }); + } + + @ParameterizedTest + @NullAndEmptySource + void 사용자가_사용자_정보_수정할때_이미지_미기입시_예외가_발생한다(final String image) { + // given + final var member = 멤버_멤버1_생성(); + 단일_멤버_저장(member); + + final var loginCookie = 로그인_쿠키를_얻는다(); + final var request = new MemberRequest("test", image); + + // when + final var response = 사용자_정보_수정_요청(loginCookie, request); + + // then + final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); + final var expectedMessage = "프로필 이미지를 확인해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); + + STATUS_CODE를_검증한다(response, 잘못된_요청); + assertSoftly(softAssertions -> { + softAssertions.assertThat(response.jsonPath().getString("code")) + .isEqualTo(expectedCode); + softAssertions.assertThat(response.jsonPath().getString("message")) + .isEqualTo(expectedMessage); + }); + } + } + private void 사용자_정보_조회를_검증하다(final ExtractableResponse response, final Member member) { final var expected = MemberProfileResponse.toResponse(member); final var expectedNickname = expected.getNickname(); @@ -75,4 +164,19 @@ class putMemberProfile_성공_테스트 { .isEqualTo(expectedProfileImage); }); } + + private void 사용자_승인되지_않음을_검증하다(final ExtractableResponse response) { + final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); + final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); + + final var actualCode = response.jsonPath().getString("code"); + final var actualMessage = response.jsonPath().getString("message"); + + assertSoftly(softAssertions -> { + softAssertions.assertThat(actualCode) + .isEqualTo(expectedCode); + softAssertions.assertThat(actualMessage) + .isEqualTo(expectedMessage); + }); + } } From 8333ba320b3b60bd4a57bb09ba12a393717dc58f Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 21:32:38 +0900 Subject: [PATCH 17/30] =?UTF-8?q?refactor:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=ED=8C=8C?= =?UTF-8?q?=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/funeat/acceptance/product/CategorySteps.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/test/java/com/funeat/acceptance/product/CategorySteps.java b/backend/src/test/java/com/funeat/acceptance/product/CategorySteps.java index 9ed5aa8de..342beb2fc 100644 --- a/backend/src/test/java/com/funeat/acceptance/product/CategorySteps.java +++ b/backend/src/test/java/com/funeat/acceptance/product/CategorySteps.java @@ -8,9 +8,9 @@ @SuppressWarnings("NonAsciiCharacters") public class CategorySteps { - public static ExtractableResponse 공통_상품_카테고리_목록_조회_요청() { + public static ExtractableResponse 카테고리_목록_조회_요청(final String type) { return given() - .queryParam("type", "food") + .queryParam("type", type) .when() .get("/api/categories") .then() From 700d547d53d1769a2937a43fec2002cc9aa722c3 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 21:33:24 +0900 Subject: [PATCH 18/30] =?UTF-8?q?feat:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/CategoryAcceptanceTest.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/backend/src/test/java/com/funeat/acceptance/product/CategoryAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/product/CategoryAcceptanceTest.java index 56e5b6170..3c95eae80 100644 --- a/backend/src/test/java/com/funeat/acceptance/product/CategoryAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/product/CategoryAcceptanceTest.java @@ -1,8 +1,10 @@ package com.funeat.acceptance.product; import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다; +import static com.funeat.acceptance.common.CommonSteps.잘못된_요청; import static com.funeat.acceptance.common.CommonSteps.정상_처리; -import static com.funeat.acceptance.product.CategorySteps.공통_상품_카테고리_목록_조회_요청; +import static com.funeat.acceptance.product.CategorySteps.카테고리_목록_조회_요청; +import static com.funeat.exception.CommonErrorCode.REQUEST_VALID_ERROR_CODE; import static com.funeat.fixture.CategoryFixture.카테고리_CU_생성; import static com.funeat.fixture.CategoryFixture.카테고리_간편식사_생성; import static com.funeat.fixture.CategoryFixture.카테고리_과자류_생성; @@ -18,6 +20,9 @@ import java.util.stream.Collectors; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.ValueSource; @SuppressWarnings("NonAsciiCharacters") public class CategoryAcceptanceTest extends AcceptanceTest { @@ -36,7 +41,7 @@ class getAllCategoriesByType_성공_테스트 { 복수_카테고리_저장(간편식사, 즉석조리, 과자류, CU); // when - final var response = 공통_상품_카테고리_목록_조회_요청(); + final var response = 카테고리_목록_조회_요청("food"); // then STATUS_CODE를_검증한다(response, 정상_처리); @@ -44,6 +49,24 @@ class getAllCategoriesByType_성공_테스트 { } } + @Nested + class getAllCategoriesByType_실패_테스트 { + + @ParameterizedTest + @NullAndEmptySource + @ValueSource(strings = {"a", "foo"}) + void 존재하지_않는_카테고리의_목록을_조회할때_예외가_발생한다(final String type) { + // given & when + final var response = 카테고리_목록_조회_요청(type); + + // then + final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); + + STATUS_CODE를_검증한다(response, 잘못된_요청); + assertThat(response.jsonPath().getString("code")).isEqualTo(expectedCode); + } + } + private void 공통_상품_카테고리_목록_조회_결과를_검증한다(final ExtractableResponse response, final List categories) { final var expected = categories.stream() From c4a217d93477552b927011819f12d3639bcab1e2 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 21:52:56 +0900 Subject: [PATCH 19/30] =?UTF-8?q?feat:=20=EC=83=81=ED=92=88=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=20=EC=98=88=EC=99=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../funeat/acceptance/common/CommonSteps.java | 1 + .../product/ProductAcceptanceTest.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java b/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java index 0f3c7ea99..8772b31d9 100644 --- a/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java +++ b/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java @@ -16,6 +16,7 @@ public class CommonSteps { public static final HttpStatus 리다이렉션_영구_이동 = HttpStatus.FOUND; public static final HttpStatus 승인되지_않음 = HttpStatus.UNAUTHORIZED; public static final HttpStatus 잘못된_요청 = HttpStatus.BAD_REQUEST; + public static final HttpStatus 찾을수_없음 = HttpStatus.NOT_FOUND; public static Long LOCATION_헤더에서_ID_추출(final ExtractableResponse response) { return Long.parseLong(response.header(LOCATION).split("/")[2]); diff --git a/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java index f46e7e38c..d42904e29 100644 --- a/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java @@ -3,6 +3,7 @@ import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키를_얻는다; import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다; import static com.funeat.acceptance.common.CommonSteps.정상_처리; +import static com.funeat.acceptance.common.CommonSteps.찾을수_없음; import static com.funeat.acceptance.product.ProductSteps.상품_랭킹_조회_요청; import static com.funeat.acceptance.product.ProductSteps.상품_상세_조회_요청; import static com.funeat.acceptance.product.ProductSteps.카테고리별_상품_목록_조회_요청; @@ -38,7 +39,9 @@ import static com.funeat.fixture.TagFixture.태그_간식_ETC_생성; import static com.funeat.fixture.TagFixture.태그_단짠단짠_TASTE_생성; import static com.funeat.fixture.TagFixture.태그_맛있어요_TASTE_생성; +import static com.funeat.product.exception.CategoryErrorCode.CATEGORY_NOF_FOUND; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.SoftAssertions.assertSoftly; import com.funeat.acceptance.common.AcceptanceTest; import com.funeat.product.domain.Product; @@ -431,6 +434,31 @@ class 리뷰수_기준_내림차순으로_카테고리별_상품_목록_조회 { } } + @Nested + class getAllProductsInCategory_실패_테스트 { + + @Test + void 상품을_정렬할때_카테고리가_존재하지_않으면_예외가_발생한다() { + // given + final var notExistCategoryId = 99999L; + + // when + final var response = 카테고리별_상품_목록_조회_요청(notExistCategoryId, "price", "desc", 0); + + // then + final var expectedCode = CATEGORY_NOF_FOUND.getCode(); + final var expectedMessage = CATEGORY_NOF_FOUND.getMessage(); + + STATUS_CODE를_검증한다(response, 찾을수_없음); + assertSoftly(softAssertions -> { + softAssertions.assertThat(response.jsonPath().getString("code")) + .isEqualTo(expectedCode); + softAssertions.assertThat(response.jsonPath().getString("message")) + .isEqualTo(expectedMessage); + }); + } + } + @Nested class getProductDetail_성공_테스트 { From c896a748f033b426c526a554e3f765a63bc64093 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 21:53:08 +0900 Subject: [PATCH 20/30] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../funeat/product/presentation/ProductApiController.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/funeat/product/presentation/ProductApiController.java b/backend/src/main/java/com/funeat/product/presentation/ProductApiController.java index eaa73e3ff..1b1796204 100644 --- a/backend/src/main/java/com/funeat/product/presentation/ProductApiController.java +++ b/backend/src/main/java/com/funeat/product/presentation/ProductApiController.java @@ -23,10 +23,8 @@ public ProductApiController(final ProductService productService) { } @GetMapping("/categories/{categoryId}/products") - public ResponseEntity getAllProductsInCategory( - @PathVariable final Long categoryId, - @PageableDefault Pageable pageable - ) { + public ResponseEntity getAllProductsInCategory(@PathVariable final Long categoryId, + @PageableDefault Pageable pageable) { final ProductsInCategoryResponse response = productService.getAllProductsInCategory(categoryId, pageable); return ResponseEntity.ok(response); } From 7afc0cd45a066ee9191d655ed535cd3cf2a6ce6e Mon Sep 17 00:00:00 2001 From: wugawuga Date: Fri, 11 Aug 2023 22:32:52 +0900 Subject: [PATCH 21/30] =?UTF-8?q?feat:=20=EC=83=81=ED=92=88=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=98=88=EC=99=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/ProductAcceptanceTest.java | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java index d42904e29..8c37459ea 100644 --- a/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java @@ -40,6 +40,7 @@ import static com.funeat.fixture.TagFixture.태그_단짠단짠_TASTE_생성; import static com.funeat.fixture.TagFixture.태그_맛있어요_TASTE_생성; import static com.funeat.product.exception.CategoryErrorCode.CATEGORY_NOF_FOUND; +import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOF_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -446,19 +447,22 @@ class getAllProductsInCategory_실패_테스트 { final var response = 카테고리별_상품_목록_조회_요청(notExistCategoryId, "price", "desc", 0); // then - final var expectedCode = CATEGORY_NOF_FOUND.getCode(); - final var expectedMessage = CATEGORY_NOF_FOUND.getMessage(); - STATUS_CODE를_검증한다(response, 찾을수_없음); - assertSoftly(softAssertions -> { - softAssertions.assertThat(response.jsonPath().getString("code")) - .isEqualTo(expectedCode); - softAssertions.assertThat(response.jsonPath().getString("message")) - .isEqualTo(expectedMessage); - }); + RESPONSE_CODE와_MESSAGE를_검증한다(response, CATEGORY_NOF_FOUND.getCode(), CATEGORY_NOF_FOUND.getMessage()); } } + private static void RESPONSE_CODE와_MESSAGE를_검증한다(final ExtractableResponse response, + final String expectedCode, + final String expectedMessage) { + assertSoftly(softAssertions -> { + softAssertions.assertThat(response.jsonPath().getString("code")) + .isEqualTo(expectedCode); + softAssertions.assertThat(response.jsonPath().getString("message")) + .isEqualTo(expectedMessage); + }); + } + @Nested class getProductDetail_성공_테스트 { @@ -499,6 +503,23 @@ class getProductDetail_성공_테스트 { } } + @Nested + class getProductDetail_실패_테스트 { + + @Test + void 존재하지_않는_상품_상세_정보를_조회할때_예외가_발생한다() { + // given + final var notExistProductId = 99999L; + + // when + final var response = 상품_상세_조회_요청(notExistProductId); + + // then + STATUS_CODE를_검증한다(response, 찾을수_없음); + RESPONSE_CODE와_MESSAGE를_검증한다(response, PRODUCT_NOF_FOUND.getCode(), PRODUCT_NOF_FOUND.getMessage()); + } + } + @Nested class getRankingProducts_성공_테스트 { From 7285a220426be45e00c612455b53362d6e3c45cb Mon Sep 17 00:00:00 2001 From: wugawuga Date: Sat, 12 Aug 2023 00:37:23 +0900 Subject: [PATCH 22/30] =?UTF-8?q?feat:=20Recipe=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recipe/application/RecipeService.java | 6 ++-- .../recipe/exception/RecipeErrorCode.java | 31 +++++++++++++++++++ .../recipe/exception/RecipeException.java | 18 +++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 backend/src/main/java/com/funeat/recipe/exception/RecipeErrorCode.java create mode 100644 backend/src/main/java/com/funeat/recipe/exception/RecipeException.java diff --git a/backend/src/main/java/com/funeat/recipe/application/RecipeService.java b/backend/src/main/java/com/funeat/recipe/application/RecipeService.java index e3407610f..04829f686 100644 --- a/backend/src/main/java/com/funeat/recipe/application/RecipeService.java +++ b/backend/src/main/java/com/funeat/recipe/application/RecipeService.java @@ -2,6 +2,7 @@ import static com.funeat.member.exception.MemberErrorCode.MEMBER_NOF_FOUND; import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOF_FOUND; +import static com.funeat.recipe.exception.RecipeErrorCode.RECIPE_NOF_FOUND; import com.funeat.common.ImageService; import com.funeat.member.domain.Member; @@ -17,6 +18,7 @@ import com.funeat.recipe.domain.RecipeImage; import com.funeat.recipe.dto.RecipeCreateRequest; import com.funeat.recipe.dto.RecipeDetailResponse; +import com.funeat.recipe.exception.RecipeException.RecipeNotFoundException; import com.funeat.recipe.persistence.RecipeImageRepository; import com.funeat.recipe.persistence.RecipeRepository; import java.util.List; @@ -74,7 +76,7 @@ public Long create(final Long memberId, final List images, final public RecipeDetailResponse getRecipeDetail(final Long memberId, final Long recipeId) { final Recipe recipe = recipeRepository.findById(recipeId) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new RecipeNotFoundException(RECIPE_NOF_FOUND, recipeId)); final List images = recipeImageRepository.findByRecipe(recipe); final List products = productRecipeRepository.findProductByRecipe(recipe); final Long totalPrice = products.stream() @@ -88,7 +90,7 @@ public RecipeDetailResponse getRecipeDetail(final Long memberId, final Long reci private Boolean calculateFavoriteChecked(final Long memberId, final Recipe recipe) { final Member member = memberRepository.findById(memberId) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOF_FOUND, memberId)); return recipeFavoriteRepository.existsByMemberAndRecipeAndFavoriteTrue(member, recipe); } } diff --git a/backend/src/main/java/com/funeat/recipe/exception/RecipeErrorCode.java b/backend/src/main/java/com/funeat/recipe/exception/RecipeErrorCode.java new file mode 100644 index 000000000..607100347 --- /dev/null +++ b/backend/src/main/java/com/funeat/recipe/exception/RecipeErrorCode.java @@ -0,0 +1,31 @@ +package com.funeat.recipe.exception; + +import org.springframework.http.HttpStatus; + +public enum RecipeErrorCode { + + RECIPE_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 꿀조합입니다. 꿀조합 id를 확인하세요.", "6001"), + ; + + private final HttpStatus status; + private final String message; + private final String code; + + RecipeErrorCode(final HttpStatus status, final String message, final String code) { + this.status = status; + this.message = message; + this.code = code; + } + + public HttpStatus getStatus() { + return status; + } + + public String getMessage() { + return message; + } + + public String getCode() { + return code; + } +} diff --git a/backend/src/main/java/com/funeat/recipe/exception/RecipeException.java b/backend/src/main/java/com/funeat/recipe/exception/RecipeException.java new file mode 100644 index 000000000..f7352c746 --- /dev/null +++ b/backend/src/main/java/com/funeat/recipe/exception/RecipeException.java @@ -0,0 +1,18 @@ +package com.funeat.recipe.exception; + +import com.funeat.exception.ErrorCode; +import com.funeat.exception.GlobalException; +import org.springframework.http.HttpStatus; + +public class RecipeException extends GlobalException { + + public RecipeException(final HttpStatus status, final ErrorCode errorCode) { + super(status, errorCode); + } + + public static class RecipeNotFoundException extends RecipeException { + public RecipeNotFoundException(final RecipeErrorCode errorCode, final Long RecipeId) { + super(errorCode.getStatus(), new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), RecipeId)); + } + } +} From dc747d116dad914d4f9ae9c81898d63fae22b301 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Sat, 12 Aug 2023 00:38:41 +0900 Subject: [PATCH 23/30] =?UTF-8?q?refactor:=20static=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/funeat/acceptance/product/ProductAcceptanceTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java index 8c37459ea..2ce4654cf 100644 --- a/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java @@ -452,9 +452,8 @@ class getAllProductsInCategory_실패_테스트 { } } - private static void RESPONSE_CODE와_MESSAGE를_검증한다(final ExtractableResponse response, - final String expectedCode, - final String expectedMessage) { + private void RESPONSE_CODE와_MESSAGE를_검증한다(final ExtractableResponse response, final String expectedCode, + final String expectedMessage) { assertSoftly(softAssertions -> { softAssertions.assertThat(response.jsonPath().getString("code")) .isEqualTo(expectedCode); From c9f5bbb77e9a1db10cf1a87e172c4e61d217b0ff Mon Sep 17 00:00:00 2001 From: wugawuga Date: Sat, 12 Aug 2023 02:04:24 +0900 Subject: [PATCH 24/30] =?UTF-8?q?feat:=20=EA=BF=80=EC=A1=B0=ED=95=A9=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1,=20=EC=A1=B0=ED=9A=8C=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recipe/dto/RecipeCreateRequest.java | 2 +- .../recipe/RecipeAcceptanceTest.java | 173 ++++++++++++++++++ 2 files changed, 174 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java b/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java index c0859f86f..1a6fb5d0f 100644 --- a/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java +++ b/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java @@ -7,7 +7,7 @@ public class RecipeCreateRequest { - @NotBlank(message = "이름을 확인해 주세요") + @NotBlank(message = "레시피 이름을 확인해 주세요") private final String title; @NotNull(message = "상품 ID 목록을 확인해 주세요") diff --git a/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java index a7a97a9cf..f277e4473 100644 --- a/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java @@ -2,27 +2,40 @@ import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키를_얻는다; import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다; +import static com.funeat.acceptance.common.CommonSteps.승인되지_않음; +import static com.funeat.acceptance.common.CommonSteps.잘못된_요청; import static com.funeat.acceptance.common.CommonSteps.정상_생성; import static com.funeat.acceptance.common.CommonSteps.정상_처리; +import static com.funeat.acceptance.common.CommonSteps.찾을수_없음; import static com.funeat.acceptance.recipe.RecipeSteps.레시피_상세_정보_요청; import static com.funeat.acceptance.recipe.RecipeSteps.레시피_생성_요청; import static com.funeat.acceptance.recipe.RecipeSteps.레시피_추가_요청하고_id_반환; import static com.funeat.acceptance.recipe.RecipeSteps.여러_사진_요청; +import static com.funeat.auth.exception.AuthErrorCode.LOGIN_MEMBER_NOT_FOUND; +import static com.funeat.exception.CommonErrorCode.REQUEST_VALID_ERROR_CODE; import static com.funeat.fixture.CategoryFixture.카테고리_간편식사_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점1점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점1점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격3000원_평점1점_생성; import static com.funeat.fixture.RecipeFixture.레시피추가요청_생성; +import static com.funeat.recipe.exception.RecipeErrorCode.RECIPE_NOF_FOUND; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.SoftAssertions.assertSoftly; import com.funeat.acceptance.common.AcceptanceTest; import com.funeat.product.domain.Product; +import com.funeat.recipe.dto.RecipeCreateRequest; import com.funeat.recipe.dto.RecipeDetailResponse; +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; @SuppressWarnings("NonAsciiCharacters") public class RecipeAcceptanceTest extends AcceptanceTest { @@ -56,6 +69,138 @@ class writeRecipe_성공_테스트 { } } + @Nested + class writeRecipe_실패_테스트 { + + @Test + void 로그인_하지않은_사용자가_레시피_작성시_예외가_발생한다() { + // given + final var category = 카테고리_간편식사_생성(); + 단일_카테고리_저장(category); + + final var product1 = 상품_삼각김밥_가격1000원_평점1점_생성(category); + final var product2 = 상품_삼각김밥_가격3000원_평점1점_생성(category); + final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); + 복수_상품_저장(product1, product2, product3); + + final var productIds = 상품_아이디_변환(product1, product2, product3); + final var request = 레시피추가요청_생성(productIds); + + final var images = 여러_사진_요청(3); + + // when + final var response = 레시피_생성_요청(request, images, null); + + // then + final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); + final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); + + STATUS_CODE를_검증한다(response, 승인되지_않음); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } + + @ParameterizedTest + @NullAndEmptySource + void 사용자가_레시피_작성할때_레시피이름_미기입시_예외가_발생한다(final String title) { + // given + final var category = 카테고리_간편식사_생성(); + 단일_카테고리_저장(category); + + final var product1 = 상품_삼각김밥_가격1000원_평점1점_생성(category); + final var product2 = 상품_삼각김밥_가격3000원_평점1점_생성(category); + final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); + 복수_상품_저장(product1, product2, product3); + + final var productIds = 상품_아이디_변환(product1, product2, product3); + final var request = new RecipeCreateRequest(title, productIds, "밥 추가, 밥 추가, 밥 추가.. 끝!!"); + + final var images = 여러_사진_요청(3); + + final var loginCookie = 로그인_쿠키를_얻는다(); + + // when + final var response = 레시피_생성_요청(request, images, loginCookie); + + // then + final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); + final var expectedMessage = "레시피 이름을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); + + STATUS_CODE를_검증한다(response, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } + + @Test + void 사용자가_레시피_작성할때_상품들이_NULL일시_예외가_발생한다() { + // given + final var request = new RecipeCreateRequest("title", null, "밥 추가, 밥 추가, 밥 추가.. 끝!!"); + + final var images = 여러_사진_요청(3); + + final var loginCookie = 로그인_쿠키를_얻는다(); + + // when + final var response = 레시피_생성_요청(request, images, loginCookie); + + // then + final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); + final var expectedMessage = "상품 ID 목록을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); + + STATUS_CODE를_검증한다(response, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } + + @Test + void 사용자가_레시피_작성할때_상품들이_비어있을시_예외가_발생한다() { + // given + final var request = new RecipeCreateRequest("title", Collections.emptyList(), "밥 추가, 밥 추가, 밥 추가.. 끝!!"); + + final var images = 여러_사진_요청(3); + + final var loginCookie = 로그인_쿠키를_얻는다(); + + // when + final var response = 레시피_생성_요청(request, images, loginCookie); + + // then + final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); + final var expectedMessage = "적어도 1개의 상품 ID가 필요합니다. " + REQUEST_VALID_ERROR_CODE.getMessage(); + + STATUS_CODE를_검증한다(response, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } + + @ParameterizedTest + @NullAndEmptySource + void 사용자가_레시피_작성할때_내용이_비어있을시_예외가_발생한다(final String content) { + // given + final var category = 카테고리_간편식사_생성(); + 단일_카테고리_저장(category); + + final var product1 = 상품_삼각김밥_가격1000원_평점1점_생성(category); + final var product2 = 상품_삼각김밥_가격3000원_평점1점_생성(category); + final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); + 복수_상품_저장(product1, product2, product3); + + final var productIds = 상품_아이디_변환(product1, product2, product3); + + final var request = new RecipeCreateRequest("title", productIds, content); + + final var images = 여러_사진_요청(3); + + final var loginCookie = 로그인_쿠키를_얻는다(); + + // when + final var response = 레시피_생성_요청(request, images, loginCookie); + + // then + final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); + final var expectedMessage = "레시피 내용을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); + + STATUS_CODE를_검증한다(response, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } + } + @Nested class getRecipeDetail_성공_테스트 { @@ -94,11 +239,39 @@ class getRecipeDetail_성공_테스트 { } } + @Nested + class getRecipeDetail_실패_테스트 { + + @Test + void 존재하지_않는_레시피_사용자가_레시피_상세_조회시_예외가_발생한다() { + // given + final var notExistRecipeId = 99999L; + final var loginCookie = 로그인_쿠키를_얻는다(); + + // when + final var response = 레시피_상세_정보_요청(loginCookie, notExistRecipeId); + + // then + STATUS_CODE를_검증한다(response, 찾을수_없음); + RESPONSE_CODE와_MESSAGE를_검증한다(response, RECIPE_NOF_FOUND.getCode(), RECIPE_NOF_FOUND.getMessage()); + } + } + private void 레시피_상세_정보_조회_결과를_검증한다(final RecipeDetailResponse actual, final RecipeDetailResponse expected) { assertThat(actual).usingRecursiveComparison() .isEqualTo(expected); } + private void RESPONSE_CODE와_MESSAGE를_검증한다(final ExtractableResponse response, final String expectedCode, + final String expectedMessage) { + assertSoftly(softAssertions -> { + softAssertions.assertThat(response.jsonPath().getString("code")) + .isEqualTo(expectedCode); + softAssertions.assertThat(response.jsonPath().getString("message")) + .isEqualTo(expectedMessage); + }); + } + private Long 상품_총가격_계산(final Product... products) { return Stream.of(products) .mapToLong(Product::getPrice) From 6a39e2aa6fbf3b5443f8c58fbb9fb0fbcefe53da Mon Sep 17 00:00:00 2001 From: wugawuga Date: Sat, 12 Aug 2023 02:06:24 +0900 Subject: [PATCH 25/30] =?UTF-8?q?refactor:=20test=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/MemberAcceptanceTest.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java index 75f4abf61..e50177ad7 100644 --- a/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java @@ -114,12 +114,7 @@ class putMemberProfile_실패_테스트 { final var expectedMessage = "닉네임을 확인해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); STATUS_CODE를_검증한다(response, 잘못된_요청); - assertSoftly(softAssertions -> { - softAssertions.assertThat(response.jsonPath().getString("code")) - .isEqualTo(expectedCode); - softAssertions.assertThat(response.jsonPath().getString("message")) - .isEqualTo(expectedMessage); - }); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); } @ParameterizedTest @@ -140,15 +135,20 @@ class putMemberProfile_실패_테스트 { final var expectedMessage = "프로필 이미지를 확인해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); STATUS_CODE를_검증한다(response, 잘못된_요청); - assertSoftly(softAssertions -> { - softAssertions.assertThat(response.jsonPath().getString("code")) - .isEqualTo(expectedCode); - softAssertions.assertThat(response.jsonPath().getString("message")) - .isEqualTo(expectedMessage); - }); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); } } + private void RESPONSE_CODE와_MESSAGE를_검증한다(final ExtractableResponse response, final String expectedCode, + final String expectedMessage) { + assertSoftly(softAssertions -> { + softAssertions.assertThat(response.jsonPath().getString("code")) + .isEqualTo(expectedCode); + softAssertions.assertThat(response.jsonPath().getString("message")) + .isEqualTo(expectedMessage); + }); + } + private void 사용자_정보_조회를_검증하다(final ExtractableResponse response, final Member member) { final var expected = MemberProfileResponse.toResponse(member); final var expectedNickname = expected.getNickname(); From dbc42b0fafaad9e67069c144b0c2b1e2147bf463 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Sat, 12 Aug 2023 17:05:09 +0900 Subject: [PATCH 26/30] =?UTF-8?q?feat:=20=EB=A6=AC=EB=B7=B0=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1,=20=EC=A1=B0=ED=9A=8C=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/dto/ReviewCreateRequest.java | 3 +- .../review/ReviewAcceptanceTest.java | 341 ++++++++++++++++++ 2 files changed, 343 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/com/funeat/review/presentation/dto/ReviewCreateRequest.java b/backend/src/main/java/com/funeat/review/presentation/dto/ReviewCreateRequest.java index 19e4fcc09..b62c35045 100644 --- a/backend/src/main/java/com/funeat/review/presentation/dto/ReviewCreateRequest.java +++ b/backend/src/main/java/com/funeat/review/presentation/dto/ReviewCreateRequest.java @@ -7,13 +7,14 @@ public class ReviewCreateRequest { + @NotNull(message = "평점을 확인해 주세요") private final Long rating; @NotNull(message = "태그 ID 목록을 확인해 주세요") @Size(min = 1, message = "적어도 1개의 태그 ID가 필요합니다") private final List tagIds; - @NotBlank(message = "리뷰 내용은 공백을 허용하지 않습니다") + @NotBlank(message = "리뷰 내용을 확인해 주세요") private final String content; @NotNull(message = "재구매 여부를 입력해주세요") diff --git a/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java index 6f90bf517..d7d1310cc 100644 --- a/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java @@ -2,14 +2,19 @@ import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키를_얻는다; import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다; +import static com.funeat.acceptance.common.CommonSteps.승인되지_않음; +import static com.funeat.acceptance.common.CommonSteps.잘못된_요청; import static com.funeat.acceptance.common.CommonSteps.정상_생성; import static com.funeat.acceptance.common.CommonSteps.정상_처리; import static com.funeat.acceptance.common.CommonSteps.정상_처리_NO_CONTENT; +import static com.funeat.acceptance.common.CommonSteps.찾을수_없음; import static com.funeat.acceptance.review.ReviewSteps.단일_리뷰_요청; import static com.funeat.acceptance.review.ReviewSteps.리뷰_랭킹_조회_요청; import static com.funeat.acceptance.review.ReviewSteps.리뷰_사진_명세_요청; import static com.funeat.acceptance.review.ReviewSteps.리뷰_좋아요_요청; import static com.funeat.acceptance.review.ReviewSteps.정렬된_리뷰_목록_조회_요청; +import static com.funeat.auth.exception.AuthErrorCode.LOGIN_MEMBER_NOT_FOUND; +import static com.funeat.exception.CommonErrorCode.REQUEST_VALID_ERROR_CODE; import static com.funeat.fixture.CategoryFixture.카테고리_즉석조리_생성; import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성; import static com.funeat.fixture.MemberFixture.멤버_멤버2_생성; @@ -27,6 +32,8 @@ import static com.funeat.fixture.ReviewFixture.리뷰추가요청_재구매O_생성; import static com.funeat.fixture.TagFixture.태그_맛있어요_TASTE_생성; import static com.funeat.fixture.TagFixture.태그_푸짐해요_PRICE_생성; +import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOF_FOUND; +import static com.funeat.review.exception.ReviewErrorCode.REVIEW_NOF_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -36,16 +43,21 @@ import com.funeat.product.domain.Category; import com.funeat.review.domain.Review; import com.funeat.review.presentation.dto.RankingReviewDto; +import com.funeat.review.presentation.dto.ReviewCreateRequest; +import com.funeat.review.presentation.dto.ReviewFavoriteRequest; import com.funeat.review.presentation.dto.SortingReviewDto; import com.funeat.review.presentation.dto.SortingReviewsPageDto; import com.funeat.tag.domain.Tag; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; @SuppressWarnings("NonAsciiCharacters") class ReviewAcceptanceTest extends AcceptanceTest { @@ -80,6 +92,178 @@ class writeReview_성공_테스트 { } } + @Nested + class writeReview_실패_테스트 { + + @Test + void 로그인_하지않은_사용자가_리뷰_작성시_예외가_발생한다() { + // given + final var category = 카테고리_즉석조리_생성(); + 카테고리_단일_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); + final var productId = 단일_상품_저장(product); + + final var tag1 = 태그_맛있어요_TASTE_생성(); + final var tag2 = 태그_푸짐해요_PRICE_생성(); + 복수_태그_저장(tag1, tag2); + + final var tagIds = 태그_아이디_변환(tag1, tag2); + + final var image = 리뷰_사진_명세_요청(); + final var request = 리뷰추가요청_재구매O_생성(4L, tagIds); + + // when + final var response = 단일_리뷰_요청(productId, image, request, null); + + // then + final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); + final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); + + STATUS_CODE를_검증한다(response, 승인되지_않음); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } + + @Test + void 사용자가_리뷰_작성할때_태그들이_NULL일시_예외가_발생한다() { + // given + final var category = 카테고리_즉석조리_생성(); + 카테고리_단일_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); + final var productId = 단일_상품_저장(product); + + final var image = 리뷰_사진_명세_요청(); + final var loginCookie = 로그인_쿠키를_얻는다(); + + // when + final var request = 리뷰추가요청_재구매O_생성(4L, null); + final var response = 단일_리뷰_요청(productId, image, request, loginCookie); + + // then + final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); + final var expectedMessage = "태그 ID 목록을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); + + STATUS_CODE를_검증한다(response, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } + + @Test + void 사용자가_리뷰_작성할때_태그들이_비어있을시_예외가_발생한다() { + // given + final var category = 카테고리_즉석조리_생성(); + 카테고리_단일_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); + final var productId = 단일_상품_저장(product); + + final var image = 리뷰_사진_명세_요청(); + final var loginCookie = 로그인_쿠키를_얻는다(); + + // when + final var request = 리뷰추가요청_재구매O_생성(4L, Collections.emptyList()); + final var response = 단일_리뷰_요청(productId, image, request, loginCookie); + + // then + final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); + final var expectedMessage = "적어도 1개의 태그 ID가 필요합니다. " + REQUEST_VALID_ERROR_CODE.getMessage(); + + STATUS_CODE를_검증한다(response, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } + + @Test + void 사용자가_리뷰_작성할때_평점이_비어있을시_예외가_발생한다() { + // given + final var category = 카테고리_즉석조리_생성(); + 카테고리_단일_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); + final var productId = 단일_상품_저장(product); + + final var tag1 = 태그_맛있어요_TASTE_생성(); + final var tag2 = 태그_푸짐해요_PRICE_생성(); + 복수_태그_저장(tag1, tag2); + + final var tagIds = 태그_아이디_변환(tag1, tag2); + + final var image = 리뷰_사진_명세_요청(); + final var loginCookie = 로그인_쿠키를_얻는다(); + + // when + final var request = 리뷰추가요청_재구매O_생성(null, tagIds); + final var response = 단일_리뷰_요청(productId, image, request, loginCookie); + + // then + final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); + final var expectedMessage = "평점을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); + + STATUS_CODE를_검증한다(response, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } + + @ParameterizedTest + @NullAndEmptySource + void 사용자가_리뷰_작성할때_리뷰내용이_비어있을시_예외가_발생한다(final String content) { + // given + final var category = 카테고리_즉석조리_생성(); + 카테고리_단일_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); + final var productId = 단일_상품_저장(product); + + final var tag1 = 태그_맛있어요_TASTE_생성(); + final var tag2 = 태그_푸짐해요_PRICE_생성(); + 복수_태그_저장(tag1, tag2); + + final var tagIds = 태그_아이디_변환(tag1, tag2); + + final var image = 리뷰_사진_명세_요청(); + final var loginCookie = 로그인_쿠키를_얻는다(); + + // when + final var request = new ReviewCreateRequest(1L, tagIds, content, true); + final var response = 단일_리뷰_요청(productId, image, request, loginCookie); + + // then + final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); + final var expectedMessage = "리뷰 내용을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); + + STATUS_CODE를_검증한다(response, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } + + @Test + void 사용자가_리뷰_작성할때_재구매여부가_비어있을시_예외가_발생한다() { + // given + final var category = 카테고리_즉석조리_생성(); + 카테고리_단일_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); + final var productId = 단일_상품_저장(product); + + final var tag1 = 태그_맛있어요_TASTE_생성(); + final var tag2 = 태그_푸짐해요_PRICE_생성(); + 복수_태그_저장(tag1, tag2); + + final var tagIds = 태그_아이디_변환(tag1, tag2); + + final var image = 리뷰_사진_명세_요청(); + final var loginCookie = 로그인_쿠키를_얻는다(); + + // when + final var request = new ReviewCreateRequest(1L, tagIds, "content", null); + final var response = 단일_리뷰_요청(productId, image, request, loginCookie); + + // then + final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); + final var expectedMessage = "재구매 여부를 입력해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); + + STATUS_CODE를_검증한다(response, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } + } + @Nested class toggleLikeReview_성공_테스트 { @@ -159,6 +343,105 @@ class toggleLikeReview_성공_테스트 { } } + @Nested + class toggleLikeReview_실패_테스트 { + + @Test + void 로그인_하지않은_사용자가_리뷰에_좋아요를_할때_예외가_발생한다() { + // given + final var member = 멤버_멤버1_생성(); + final var memberId = 단일_멤버_저장(member); + + final var category = 카테고리_즉석조리_생성(); + 카테고리_단일_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); + final var productId = 단일_상품_저장(product); + + final var tag1 = 태그_맛있어요_TASTE_생성(); + final var tag2 = 태그_푸짐해요_PRICE_생성(); + 복수_태그_저장(tag1, tag2); + + final var tagIds = 태그_아이디_변환(tag1, tag2); + + final var image = 리뷰_사진_명세_요청(); + final var reviewRequest = 리뷰추가요청_재구매O_생성(4L, tagIds); + final var loginCookie = 로그인_쿠키를_얻는다(); + 단일_리뷰_요청(productId, image, reviewRequest, loginCookie); + + final var reviewId = reviewRepository.findAll().get(0).getId(); + final var favoriteRequest = 리뷰좋아요요청_true_생성(); + + // when + final var response = 리뷰_좋아요_요청(productId, reviewId, favoriteRequest, null); + + // then + final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); + final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); + + STATUS_CODE를_검증한다(response, 승인되지_않음); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } + + @Test + void 사용자가_리뷰에_좋아요를_할때_좋아요_미기입시_예외가_발생한다() { + // given + final var member = 멤버_멤버1_생성(); + final var memberId = 단일_멤버_저장(member); + + final var category = 카테고리_즉석조리_생성(); + 카테고리_단일_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); + final var productId = 단일_상품_저장(product); + + final var tag1 = 태그_맛있어요_TASTE_생성(); + final var tag2 = 태그_푸짐해요_PRICE_생성(); + 복수_태그_저장(tag1, tag2); + + final var tagIds = 태그_아이디_변환(tag1, tag2); + + final var image = 리뷰_사진_명세_요청(); + final var reviewRequest = 리뷰추가요청_재구매O_생성(4L, tagIds); + final var loginCookie = 로그인_쿠키를_얻는다(); + 단일_리뷰_요청(productId, image, reviewRequest, loginCookie); + + final var reviewId = reviewRepository.findAll().get(0).getId(); + + // when + final var request = new ReviewFavoriteRequest(null); + final var response = 리뷰_좋아요_요청(productId, reviewId, request, loginCookie); + + // then + final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); + final var expectedMessage = "좋아요를 확인해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); + + STATUS_CODE를_검증한다(response, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } + + @Test + void 존재하지_않는_리뷰에_사용자가_좋아요를_할때_예외가_발생한다() { + // given + final var category = 카테고리_즉석조리_생성(); + 카테고리_단일_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); + final var productId = 단일_상품_저장(product); + + final var favoriteRequest = 리뷰좋아요요청_true_생성(); + final var loginCookie = 로그인_쿠키를_얻는다(); + + // when + final var notExistReviewId = 99999L; + final var response = 리뷰_좋아요_요청(productId, notExistReviewId, favoriteRequest, loginCookie); + + // then + STATUS_CODE를_검증한다(response, 찾을수_없음); + RESPONSE_CODE와_MESSAGE를_검증한다(response, REVIEW_NOF_FOUND.getCode(), REVIEW_NOF_FOUND.getMessage()); + } + } + @Nested class getSortingReviews_성공_테스트 { @@ -397,6 +680,54 @@ class 최신순으로_리뷰_목록을_조회 { } } + @Nested + class getSortingReviews_실패_테스트 { + + @Test + void 로그인_하지않은_사용자가_리뷰_목록을_조회시_예외가_발생한다() { + // given + final var category = 카테고리_즉석조리_생성(); + 카테고리_단일_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); + final var productId = 단일_상품_저장(product); + + final var member1 = 멤버_멤버1_생성(); + final var member2 = 멤버_멤버2_생성(); + final var member3 = 멤버_멤버3_생성(); + 복수_멤버_저장(member1, member2, member3); + + final var review1 = 리뷰_이미지test3_평점3점_재구매O_생성(member1, product, 5L); + final var review2 = 리뷰_이미지test4_평점4점_재구매O_생성(member2, product, 351L); + final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product, 130L); + 복수_리뷰_저장(review1, review2, review3); + + // when + final var response = 정렬된_리뷰_목록_조회_요청(null, productId, "favoriteCount,desc", 0); + + // then + final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); + final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); + + STATUS_CODE를_검증한다(response, 승인되지_않음); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } + + @Test + void 존재하지_않는_상품의_리뷰_목록을_조회시_예외가_발생한다() { + // given + final var notExistProductId = 99999L; + final var loginCookie = 로그인_쿠키를_얻는다(); + + // when + final var response = 정렬된_리뷰_목록_조회_요청(loginCookie, notExistProductId, "favoriteCount,desc", 0); + + // then + STATUS_CODE를_검증한다(response, 찾을수_없음); + RESPONSE_CODE와_MESSAGE를_검증한다(response, PRODUCT_NOF_FOUND.getCode(), PRODUCT_NOF_FOUND.getMessage()); + } + } + @Nested class getRankingReviews_성공_테스트 { @@ -452,6 +783,16 @@ class getRankingReviews_성공_테스트 { }); } + private void RESPONSE_CODE와_MESSAGE를_검증한다(final ExtractableResponse response, final String expectedCode, + final String expectedMessage) { + assertSoftly(softAssertions -> { + softAssertions.assertThat(response.jsonPath().getString("code")) + .isEqualTo(expectedCode); + softAssertions.assertThat(response.jsonPath().getString("message")) + .isEqualTo(expectedMessage); + }); + } + private Long 카테고리_단일_저장(final Category category) { return categoryRepository.save(category).getId(); } From 35a6f8bebee44694c3149774a9d8d766c1a0b516 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Sat, 12 Aug 2023 17:15:41 +0900 Subject: [PATCH 27/30] =?UTF-8?q?refactor:=20=EC=BB=A8=EB=B2=A4=EC=85=98?= =?UTF-8?q?=20=EB=A7=9E=EA=B2=8C=20=EC=88=98=EC=A0=95,=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/presentation/GlobalControllerAdvice.java | 6 +++--- .../com/funeat/product/exception/CategoryErrorCode.java | 2 +- .../java/com/funeat/recipe/dto/RecipeCreateRequest.java | 1 + .../funeat/review/presentation/dto/ReviewCreateRequest.java | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java b/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java index 0ff584cbd..3d806575d 100644 --- a/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java +++ b/backend/src/main/java/com/funeat/exception/presentation/GlobalControllerAdvice.java @@ -79,12 +79,12 @@ public ResponseEntity handleGlobalException(final GlobalException e, final Ht request.getRequestURI(), e.getErrorCode().getCode(), e.getErrorCode().getMessage(), objectMapper.writeValueAsString(e.getErrorCode().getInfo())); - ErrorCode errorCode = new ErrorCode<>(e.getErrorCode().getCode(), e.getMessage()); + final ErrorCode errorCode = new ErrorCode<>(e.getErrorCode().getCode(), e.getMessage()); return ResponseEntity.status(e.getStatus()).body(errorCode); } private String getExceptionSource(final Exception e) { - StackTraceElement[] stackTrace = e.getStackTrace(); + final StackTraceElement[] stackTrace = e.getStackTrace(); if (stackTrace.length > 0) { return stackTrace[0].toString(); } @@ -95,7 +95,7 @@ private String getExceptionSource(final Exception e) { public ResponseEntity handleServerException(final Exception e) { log.error("", e); - ErrorCode errorCode = new ErrorCode<>(UNKNOWN_SERVER_ERROR_CODE.getCode(), + final ErrorCode errorCode = new ErrorCode<>(UNKNOWN_SERVER_ERROR_CODE.getCode(), UNKNOWN_SERVER_ERROR_CODE.getMessage()); return ResponseEntity.status(UNKNOWN_SERVER_ERROR_CODE.getStatus()).body(errorCode); } diff --git a/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java b/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java index 0650eb299..d519dc45e 100644 --- a/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java +++ b/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java @@ -5,7 +5,7 @@ public enum CategoryErrorCode { CATEGORY_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 카테고리입니다. 카테고리 id를 확인하세요.", "3001"), - CATEGORY_TYPE_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 카테고리 타입입니다. 카테고리 타입 확인하세요.", "3002"), + CATEGORY_TYPE_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 카테고리 타입입니다. 카테고리 타입을 확인하세요.", "3002"), ; private final HttpStatus status; diff --git a/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java b/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java index 1a6fb5d0f..f332498a1 100644 --- a/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java +++ b/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java @@ -15,6 +15,7 @@ public class RecipeCreateRequest { private final List productIds; @NotBlank(message = "레시피 내용을 확인해 주세요") + @Size(max = 500, message = "리뷰 내용은 최대 500자까지 입력 가능합니다") private final String content; public RecipeCreateRequest(final String title, final List productIds, final String content) { diff --git a/backend/src/main/java/com/funeat/review/presentation/dto/ReviewCreateRequest.java b/backend/src/main/java/com/funeat/review/presentation/dto/ReviewCreateRequest.java index b62c35045..aeda36555 100644 --- a/backend/src/main/java/com/funeat/review/presentation/dto/ReviewCreateRequest.java +++ b/backend/src/main/java/com/funeat/review/presentation/dto/ReviewCreateRequest.java @@ -15,6 +15,7 @@ public class ReviewCreateRequest { private final List tagIds; @NotBlank(message = "리뷰 내용을 확인해 주세요") + @Size(max = 200, message = "리뷰 내용은 최대 200자까지 입력 가능합니다") private final String content; @NotNull(message = "재구매 여부를 입력해주세요") From 4df248fb049bb95e6f8f22ee4de9d0632e62067a Mon Sep 17 00:00:00 2001 From: wugawuga Date: Sat, 12 Aug 2023 17:23:49 +0900 Subject: [PATCH 28/30] =?UTF-8?q?feat:=20review,=20recipe=20content=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recipe/RecipeAcceptanceTest.java | 30 ++++++++++++++++++ .../review/ReviewAcceptanceTest.java | 31 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java index f277e4473..444743919 100644 --- a/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java @@ -199,6 +199,36 @@ class writeRecipe_실패_테스트 { STATUS_CODE를_검증한다(response, 잘못된_요청); RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); } + + @Test + void 사용자가_레시피_작성할때_레시피내용이_500자_초과시_예외가_발생한다() { + // given + final var category = 카테고리_간편식사_생성(); + 단일_카테고리_저장(category); + + final var product1 = 상품_삼각김밥_가격1000원_평점1점_생성(category); + final var product2 = 상품_삼각김밥_가격3000원_평점1점_생성(category); + final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); + 복수_상품_저장(product1, product2, product3); + + final var productIds = 상품_아이디_변환(product1, product2, product3); + + final var images = 여러_사진_요청(3); + + final var loginCookie = 로그인_쿠키를_얻는다(); + + // when + final var maxContent = "tests".repeat(100) + "a"; + final var request = new RecipeCreateRequest("title", productIds, maxContent); + final var response = 레시피_생성_요청(request, images, loginCookie); + + // then + final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); + final var expectedMessage = "리뷰 내용은 최대 500자까지 입력 가능합니다. " + REQUEST_VALID_ERROR_CODE.getMessage(); + + STATUS_CODE를_검증한다(response, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } } @Nested diff --git a/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java index d7d1310cc..93e2814ec 100644 --- a/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java @@ -262,6 +262,37 @@ class writeReview_실패_테스트 { STATUS_CODE를_검증한다(response, 잘못된_요청); RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); } + + @Test + void 사용자가_리뷰_작성할때_리뷰내용이_200자_초과시_예외가_발생한다() { + // given + final var category = 카테고리_즉석조리_생성(); + 카테고리_단일_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); + final var productId = 단일_상품_저장(product); + + final var tag1 = 태그_맛있어요_TASTE_생성(); + final var tag2 = 태그_푸짐해요_PRICE_생성(); + 복수_태그_저장(tag1, tag2); + + final var tagIds = 태그_아이디_변환(tag1, tag2); + + final var image = 리뷰_사진_명세_요청(); + final var loginCookie = 로그인_쿠키를_얻는다(); + + // when + final var maxContent = "test".repeat(50) + "a"; + final var request = new ReviewCreateRequest(1L, tagIds, maxContent, true); + final var response = 단일_리뷰_요청(productId, image, request, loginCookie); + + // then + final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); + final var expectedMessage = "리뷰 내용은 최대 200자까지 입력 가능합니다. " + REQUEST_VALID_ERROR_CODE.getMessage(); + + STATUS_CODE를_검증한다(response, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + } } @Nested From 23884d7820b0a392a150461bd8c397d3f69c273b Mon Sep 17 00:00:00 2001 From: wugawuga Date: Sat, 12 Aug 2023 17:55:33 +0900 Subject: [PATCH 29/30] =?UTF-8?q?refactor:=20=EC=98=A4=ED=83=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95,=20api=20=EB=AA=85=EC=84=B8=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20=EC=BD=94=EB=93=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../funeat/auth/exception/AuthErrorCode.java | 2 +- .../member/application/MemberService.java | 4 ++-- .../member/exception/MemberErrorCode.java | 2 +- .../product/application/ProductService.java | 8 ++++---- .../funeat/product/domain/CategoryType.java | 4 ++-- .../product/exception/CategoryErrorCode.java | 4 ++-- .../product/exception/ProductErrorCode.java | 2 +- .../recipe/application/RecipeService.java | 14 +++++++------- .../funeat/recipe/dto/RecipeCreateRequest.java | 6 +++--- .../recipe/exception/RecipeErrorCode.java | 2 +- .../review/application/ReviewService.java | 18 +++++++++--------- .../review/exception/ReviewErrorCode.java | 2 +- .../product/ProductAcceptanceTest.java | 8 ++++---- .../recipe/RecipeAcceptanceTest.java | 10 +++++----- .../review/ReviewAcceptanceTest.java | 8 ++++---- 15 files changed, 47 insertions(+), 47 deletions(-) diff --git a/backend/src/main/java/com/funeat/auth/exception/AuthErrorCode.java b/backend/src/main/java/com/funeat/auth/exception/AuthErrorCode.java index be52351a2..3508ff142 100644 --- a/backend/src/main/java/com/funeat/auth/exception/AuthErrorCode.java +++ b/backend/src/main/java/com/funeat/auth/exception/AuthErrorCode.java @@ -4,7 +4,7 @@ public enum AuthErrorCode { - LOGIN_MEMBER_NOT_FOUND(HttpStatus.UNAUTHORIZED, "로그인 하지 않은 회원입니다. 로그인을 해주세요.", "2001"), + LOGIN_MEMBER_NOT_FOUND(HttpStatus.UNAUTHORIZED, "로그인 하지 않은 회원입니다. 로그인을 해주세요.", "6001"), ; private final HttpStatus status; diff --git a/backend/src/main/java/com/funeat/member/application/MemberService.java b/backend/src/main/java/com/funeat/member/application/MemberService.java index 7a4c1cf9f..506d8cdc2 100644 --- a/backend/src/main/java/com/funeat/member/application/MemberService.java +++ b/backend/src/main/java/com/funeat/member/application/MemberService.java @@ -41,7 +41,7 @@ private SignUserDto save(final UserInfoDto userInfoDto) { public MemberProfileResponse getMemberProfile(final Long memberId) { final Member findMember = memberRepository.findById(memberId) - .orElseThrow(() -> new MemberNotFoundException(MemberErrorCode.MEMBER_NOF_FOUND, memberId)); + .orElseThrow(() -> new MemberNotFoundException(MemberErrorCode.MEMBER_NOT_FOUND, memberId)); return MemberProfileResponse.toResponse(findMember); } @@ -49,7 +49,7 @@ public MemberProfileResponse getMemberProfile(final Long memberId) { @Transactional public void modify(final Long memberId, final MemberRequest request) { final Member findMember = memberRepository.findById(memberId) - .orElseThrow(() -> new MemberNotFoundException(MemberErrorCode.MEMBER_NOF_FOUND, memberId)); + .orElseThrow(() -> new MemberNotFoundException(MemberErrorCode.MEMBER_NOT_FOUND, memberId)); final String nickname = request.getNickname(); final String profileImage = request.getProfileImage(); diff --git a/backend/src/main/java/com/funeat/member/exception/MemberErrorCode.java b/backend/src/main/java/com/funeat/member/exception/MemberErrorCode.java index fea20f7c1..7a4d30651 100644 --- a/backend/src/main/java/com/funeat/member/exception/MemberErrorCode.java +++ b/backend/src/main/java/com/funeat/member/exception/MemberErrorCode.java @@ -4,7 +4,7 @@ public enum MemberErrorCode { - MEMBER_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 회원입니다. 회원 id를 확인하세요.", "1001"), + MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 회원입니다. 회원 id를 확인하세요.", "5001"), ; private final HttpStatus status; diff --git a/backend/src/main/java/com/funeat/product/application/ProductService.java b/backend/src/main/java/com/funeat/product/application/ProductService.java index a78bf80b2..0e5287bbd 100644 --- a/backend/src/main/java/com/funeat/product/application/ProductService.java +++ b/backend/src/main/java/com/funeat/product/application/ProductService.java @@ -1,7 +1,7 @@ package com.funeat.product.application; -import static com.funeat.product.exception.CategoryErrorCode.CATEGORY_NOF_FOUND; -import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOF_FOUND; +import static com.funeat.product.exception.CategoryErrorCode.CATEGORY_NOT_FOUND; +import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOT_FOUND; import com.funeat.product.domain.Category; import com.funeat.product.domain.Product; @@ -49,7 +49,7 @@ public ProductService(final CategoryRepository categoryRepository, final Product public ProductsInCategoryResponse getAllProductsInCategory(final Long categoryId, final Pageable pageable) { final Category category = categoryRepository.findById(categoryId) - .orElseThrow(() -> new CategoryNotFoundException(CATEGORY_NOF_FOUND, categoryId)); + .orElseThrow(() -> new CategoryNotFoundException(CATEGORY_NOT_FOUND, categoryId)); final Page pages = getAllProductsInCategory(pageable, category); @@ -69,7 +69,7 @@ private Page getAllProductsInCategory(final Pageable pagea public ProductResponse findProductDetail(final Long productId) { final Product product = productRepository.findById(productId) - .orElseThrow(() -> new ProductNotFoundException(PRODUCT_NOF_FOUND, productId)); + .orElseThrow(() -> new ProductNotFoundException(PRODUCT_NOT_FOUND, productId)); final List tags = reviewTagRepository.findTop3TagsByReviewIn(productId, PageRequest.of(TOP, THREE)); diff --git a/backend/src/main/java/com/funeat/product/domain/CategoryType.java b/backend/src/main/java/com/funeat/product/domain/CategoryType.java index 87cf18275..6568dea89 100644 --- a/backend/src/main/java/com/funeat/product/domain/CategoryType.java +++ b/backend/src/main/java/com/funeat/product/domain/CategoryType.java @@ -1,6 +1,6 @@ package com.funeat.product.domain; -import static com.funeat.product.exception.CategoryErrorCode.CATEGORY_TYPE_NOF_FOUND; +import static com.funeat.product.exception.CategoryErrorCode.CATEGORY_TYPE_NOT_FOUND; import com.funeat.product.exception.CategoryException.CategoryTypeNotFoundException; import java.util.Arrays; @@ -12,6 +12,6 @@ public static CategoryType findCategoryType(final String type) { return Arrays.stream(values()) .filter(it -> it.name().equals(type.toUpperCase())) .findFirst() - .orElseThrow(() -> new CategoryTypeNotFoundException(CATEGORY_TYPE_NOF_FOUND, type)); + .orElseThrow(() -> new CategoryTypeNotFoundException(CATEGORY_TYPE_NOT_FOUND, type)); } } diff --git a/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java b/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java index d519dc45e..5214a03b6 100644 --- a/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java +++ b/backend/src/main/java/com/funeat/product/exception/CategoryErrorCode.java @@ -4,8 +4,8 @@ public enum CategoryErrorCode { - CATEGORY_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 카테고리입니다. 카테고리 id를 확인하세요.", "3001"), - CATEGORY_TYPE_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 카테고리 타입입니다. 카테고리 타입을 확인하세요.", "3002"), + CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 카테고리입니다. 카테고리 id를 확인하세요.", "2001"), + CATEGORY_TYPE_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 카테고리 타입입니다. 카테고리 타입을 확인하세요.", "2002"), ; private final HttpStatus status; diff --git a/backend/src/main/java/com/funeat/product/exception/ProductErrorCode.java b/backend/src/main/java/com/funeat/product/exception/ProductErrorCode.java index 9a956b99b..933f91098 100644 --- a/backend/src/main/java/com/funeat/product/exception/ProductErrorCode.java +++ b/backend/src/main/java/com/funeat/product/exception/ProductErrorCode.java @@ -4,7 +4,7 @@ public enum ProductErrorCode { - PRODUCT_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 상품입니다. 상품 id를 확인하세요.", "4001"), + PRODUCT_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 상품입니다. 상품 id를 확인하세요.", "1001"), ; private final HttpStatus status; diff --git a/backend/src/main/java/com/funeat/recipe/application/RecipeService.java b/backend/src/main/java/com/funeat/recipe/application/RecipeService.java index 04829f686..ee9563bf1 100644 --- a/backend/src/main/java/com/funeat/recipe/application/RecipeService.java +++ b/backend/src/main/java/com/funeat/recipe/application/RecipeService.java @@ -1,8 +1,8 @@ package com.funeat.recipe.application; -import static com.funeat.member.exception.MemberErrorCode.MEMBER_NOF_FOUND; -import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOF_FOUND; -import static com.funeat.recipe.exception.RecipeErrorCode.RECIPE_NOF_FOUND; +import static com.funeat.member.exception.MemberErrorCode.MEMBER_NOT_FOUND; +import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOT_FOUND; +import static com.funeat.recipe.exception.RecipeErrorCode.RECIPE_NOT_FOUND; import com.funeat.common.ImageService; import com.funeat.member.domain.Member; @@ -56,13 +56,13 @@ public RecipeService(final MemberRepository memberRepository, final ProductRepos @Transactional public Long create(final Long memberId, final List images, final RecipeCreateRequest request) { final Member member = memberRepository.findById(memberId) - .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOF_FOUND, memberId)); + .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOT_FOUND, memberId)); final Recipe savedRecipe = recipeRepository.save(new Recipe(request.getTitle(), request.getContent(), member)); request.getProductIds() .stream() .map(it -> productRepository.findById(it) - .orElseThrow(() -> new ProductNotFoundException(PRODUCT_NOF_FOUND, it))) + .orElseThrow(() -> new ProductNotFoundException(PRODUCT_NOT_FOUND, it))) .forEach(it -> productRecipeRepository.save(new ProductRecipe(it, savedRecipe))); if (Objects.nonNull(images)) { @@ -76,7 +76,7 @@ public Long create(final Long memberId, final List images, final public RecipeDetailResponse getRecipeDetail(final Long memberId, final Long recipeId) { final Recipe recipe = recipeRepository.findById(recipeId) - .orElseThrow(() -> new RecipeNotFoundException(RECIPE_NOF_FOUND, recipeId)); + .orElseThrow(() -> new RecipeNotFoundException(RECIPE_NOT_FOUND, recipeId)); final List images = recipeImageRepository.findByRecipe(recipe); final List products = productRecipeRepository.findProductByRecipe(recipe); final Long totalPrice = products.stream() @@ -90,7 +90,7 @@ public RecipeDetailResponse getRecipeDetail(final Long memberId, final Long reci private Boolean calculateFavoriteChecked(final Long memberId, final Recipe recipe) { final Member member = memberRepository.findById(memberId) - .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOF_FOUND, memberId)); + .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOT_FOUND, memberId)); return recipeFavoriteRepository.existsByMemberAndRecipeAndFavoriteTrue(member, recipe); } } diff --git a/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java b/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java index f332498a1..201c28cf0 100644 --- a/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java +++ b/backend/src/main/java/com/funeat/recipe/dto/RecipeCreateRequest.java @@ -7,15 +7,15 @@ public class RecipeCreateRequest { - @NotBlank(message = "레시피 이름을 확인해 주세요") + @NotBlank(message = "꿀조합 이름을 확인해 주세요") private final String title; @NotNull(message = "상품 ID 목록을 확인해 주세요") @Size(min = 1, message = "적어도 1개의 상품 ID가 필요합니다") private final List productIds; - @NotBlank(message = "레시피 내용을 확인해 주세요") - @Size(max = 500, message = "리뷰 내용은 최대 500자까지 입력 가능합니다") + @NotBlank(message = "꿀조합 내용을 확인해 주세요") + @Size(max = 500, message = "꿀조합 내용은 최대 500자까지 입력 가능합니다") private final String content; public RecipeCreateRequest(final String title, final List productIds, final String content) { diff --git a/backend/src/main/java/com/funeat/recipe/exception/RecipeErrorCode.java b/backend/src/main/java/com/funeat/recipe/exception/RecipeErrorCode.java index 607100347..887da8864 100644 --- a/backend/src/main/java/com/funeat/recipe/exception/RecipeErrorCode.java +++ b/backend/src/main/java/com/funeat/recipe/exception/RecipeErrorCode.java @@ -4,7 +4,7 @@ public enum RecipeErrorCode { - RECIPE_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 꿀조합입니다. 꿀조합 id를 확인하세요.", "6001"), + RECIPE_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 꿀조합입니다. 꿀조합 id를 확인하세요.", "7001"), ; private final HttpStatus status; diff --git a/backend/src/main/java/com/funeat/review/application/ReviewService.java b/backend/src/main/java/com/funeat/review/application/ReviewService.java index 99af0ba4a..6a186135c 100644 --- a/backend/src/main/java/com/funeat/review/application/ReviewService.java +++ b/backend/src/main/java/com/funeat/review/application/ReviewService.java @@ -1,8 +1,8 @@ package com.funeat.review.application; -import static com.funeat.member.exception.MemberErrorCode.MEMBER_NOF_FOUND; -import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOF_FOUND; -import static com.funeat.review.exception.ReviewErrorCode.REVIEW_NOF_FOUND; +import static com.funeat.member.exception.MemberErrorCode.MEMBER_NOT_FOUND; +import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOT_FOUND; +import static com.funeat.review.exception.ReviewErrorCode.REVIEW_NOT_FOUND; import com.funeat.common.ImageService; import com.funeat.member.domain.Member; @@ -65,9 +65,9 @@ public ReviewService(final ReviewRepository reviewRepository, final TagRepositor public void create(final Long productId, final Long memberId, final MultipartFile image, final ReviewCreateRequest reviewRequest) { final Member findMember = memberRepository.findById(memberId) - .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOF_FOUND, memberId)); + .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOT_FOUND, memberId)); final Product findProduct = productRepository.findById(productId) - .orElseThrow(() -> new ProductNotFoundException(PRODUCT_NOF_FOUND, productId)); + .orElseThrow(() -> new ProductNotFoundException(PRODUCT_NOT_FOUND, productId)); final Review savedReview; if (Objects.isNull(image)) { @@ -96,9 +96,9 @@ public void create(final Long productId, final Long memberId, final MultipartFil @Transactional public void likeReview(final Long reviewId, final Long memberId, final ReviewFavoriteRequest request) { final Member findMember = memberRepository.findById(memberId) - .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOF_FOUND, memberId)); + .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOT_FOUND, memberId)); final Review findReview = reviewRepository.findById(reviewId) - .orElseThrow(() -> new ReviewNotFoundException(REVIEW_NOF_FOUND, reviewId)); + .orElseThrow(() -> new ReviewNotFoundException(REVIEW_NOT_FOUND, reviewId)); final ReviewFavorite savedReviewFavorite = reviewFavoriteRepository.findByMemberAndReview(findMember, findReview).orElseGet(() -> saveReviewFavorite(findMember, findReview, request.getFavorite())); @@ -115,10 +115,10 @@ private ReviewFavorite saveReviewFavorite(final Member member, final Review revi public SortingReviewsResponse sortingReviews(final Long productId, final Pageable pageable, final Long memberId) { final Member member = memberRepository.findById(memberId) - .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOF_FOUND, memberId)); + .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOT_FOUND, memberId)); final Product product = productRepository.findById(productId) - .orElseThrow(() -> new ProductNotFoundException(PRODUCT_NOF_FOUND, productId)); + .orElseThrow(() -> new ProductNotFoundException(PRODUCT_NOT_FOUND, productId)); final Page reviewPage = reviewRepository.findReviewsByProduct(pageable, product); diff --git a/backend/src/main/java/com/funeat/review/exception/ReviewErrorCode.java b/backend/src/main/java/com/funeat/review/exception/ReviewErrorCode.java index 0661898d3..d91c0c8c3 100644 --- a/backend/src/main/java/com/funeat/review/exception/ReviewErrorCode.java +++ b/backend/src/main/java/com/funeat/review/exception/ReviewErrorCode.java @@ -4,7 +4,7 @@ public enum ReviewErrorCode { - REVIEW_NOF_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 리뷰입니다. 리뷰 id를 확인하세요.", "5001"), + REVIEW_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 리뷰입니다. 리뷰 id를 확인하세요.", "3001"), ; private final HttpStatus status; diff --git a/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java index 2ce4654cf..3256a61e9 100644 --- a/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java @@ -39,8 +39,8 @@ import static com.funeat.fixture.TagFixture.태그_간식_ETC_생성; import static com.funeat.fixture.TagFixture.태그_단짠단짠_TASTE_생성; import static com.funeat.fixture.TagFixture.태그_맛있어요_TASTE_생성; -import static com.funeat.product.exception.CategoryErrorCode.CATEGORY_NOF_FOUND; -import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOF_FOUND; +import static com.funeat.product.exception.CategoryErrorCode.CATEGORY_NOT_FOUND; +import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -448,7 +448,7 @@ class getAllProductsInCategory_실패_테스트 { // then STATUS_CODE를_검증한다(response, 찾을수_없음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, CATEGORY_NOF_FOUND.getCode(), CATEGORY_NOF_FOUND.getMessage()); + RESPONSE_CODE와_MESSAGE를_검증한다(response, CATEGORY_NOT_FOUND.getCode(), CATEGORY_NOT_FOUND.getMessage()); } } @@ -515,7 +515,7 @@ class getProductDetail_실패_테스트 { // then STATUS_CODE를_검증한다(response, 찾을수_없음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, PRODUCT_NOF_FOUND.getCode(), PRODUCT_NOF_FOUND.getMessage()); + RESPONSE_CODE와_MESSAGE를_검증한다(response, PRODUCT_NOT_FOUND.getCode(), PRODUCT_NOT_FOUND.getMessage()); } } diff --git a/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java index 444743919..adbf621c8 100644 --- a/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java @@ -18,7 +18,7 @@ import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점1점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격3000원_평점1점_생성; import static com.funeat.fixture.RecipeFixture.레시피추가요청_생성; -import static com.funeat.recipe.exception.RecipeErrorCode.RECIPE_NOF_FOUND; +import static com.funeat.recipe.exception.RecipeErrorCode.RECIPE_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -123,7 +123,7 @@ class writeRecipe_실패_테스트 { // then final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "레시피 이름을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); + final var expectedMessage = "꿀조합 이름을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); STATUS_CODE를_검증한다(response, 잘못된_요청); RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); @@ -194,7 +194,7 @@ class writeRecipe_실패_테스트 { // then final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "레시피 내용을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); + final var expectedMessage = "꿀조합 내용을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); STATUS_CODE를_검증한다(response, 잘못된_요청); RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); @@ -224,7 +224,7 @@ class writeRecipe_실패_테스트 { // then final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "리뷰 내용은 최대 500자까지 입력 가능합니다. " + REQUEST_VALID_ERROR_CODE.getMessage(); + final var expectedMessage = "꿀조합 내용은 최대 500자까지 입력 가능합니다. " + REQUEST_VALID_ERROR_CODE.getMessage(); STATUS_CODE를_검증한다(response, 잘못된_요청); RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); @@ -283,7 +283,7 @@ class getRecipeDetail_실패_테스트 { // then STATUS_CODE를_검증한다(response, 찾을수_없음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, RECIPE_NOF_FOUND.getCode(), RECIPE_NOF_FOUND.getMessage()); + RESPONSE_CODE와_MESSAGE를_검증한다(response, RECIPE_NOT_FOUND.getCode(), RECIPE_NOT_FOUND.getMessage()); } } diff --git a/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java index 93e2814ec..43ce1e9c3 100644 --- a/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java @@ -32,8 +32,8 @@ import static com.funeat.fixture.ReviewFixture.리뷰추가요청_재구매O_생성; import static com.funeat.fixture.TagFixture.태그_맛있어요_TASTE_생성; import static com.funeat.fixture.TagFixture.태그_푸짐해요_PRICE_생성; -import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOF_FOUND; -import static com.funeat.review.exception.ReviewErrorCode.REVIEW_NOF_FOUND; +import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOT_FOUND; +import static com.funeat.review.exception.ReviewErrorCode.REVIEW_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -469,7 +469,7 @@ class toggleLikeReview_실패_테스트 { // then STATUS_CODE를_검증한다(response, 찾을수_없음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, REVIEW_NOF_FOUND.getCode(), REVIEW_NOF_FOUND.getMessage()); + RESPONSE_CODE와_MESSAGE를_검증한다(response, REVIEW_NOT_FOUND.getCode(), REVIEW_NOT_FOUND.getMessage()); } } @@ -755,7 +755,7 @@ class getSortingReviews_실패_테스트 { // then STATUS_CODE를_검증한다(response, 찾을수_없음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, PRODUCT_NOF_FOUND.getCode(), PRODUCT_NOF_FOUND.getMessage()); + RESPONSE_CODE와_MESSAGE를_검증한다(response, PRODUCT_NOT_FOUND.getCode(), PRODUCT_NOT_FOUND.getMessage()); } } From c16e3235adefaba6e7da9633853e6bcc550eed31 Mon Sep 17 00:00:00 2001 From: wugawuga Date: Sat, 12 Aug 2023 21:54:19 +0900 Subject: [PATCH 30/30] =?UTF-8?q?refactor:=20=EC=8A=B9=EC=9D=B8=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EC=9D=8C=20->=20=EC=9D=B8=EC=A6=9D?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EC=9D=8C=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/funeat/acceptance/common/CommonSteps.java | 2 +- .../funeat/acceptance/member/MemberAcceptanceTest.java | 6 +++--- .../funeat/acceptance/recipe/RecipeAcceptanceTest.java | 4 ++-- .../funeat/acceptance/review/ReviewAcceptanceTest.java | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java b/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java index 8772b31d9..dc8d201b8 100644 --- a/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java +++ b/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java @@ -14,7 +14,7 @@ public class CommonSteps { public static final HttpStatus 정상_생성 = HttpStatus.CREATED; public static final HttpStatus 정상_처리_NO_CONTENT = HttpStatus.NO_CONTENT; public static final HttpStatus 리다이렉션_영구_이동 = HttpStatus.FOUND; - public static final HttpStatus 승인되지_않음 = HttpStatus.UNAUTHORIZED; + public static final HttpStatus 인증되지_않음 = HttpStatus.UNAUTHORIZED; public static final HttpStatus 잘못된_요청 = HttpStatus.BAD_REQUEST; public static final HttpStatus 찾을수_없음 = HttpStatus.NOT_FOUND; diff --git a/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java index e50177ad7..afe78f147 100644 --- a/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java @@ -2,7 +2,7 @@ import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키를_얻는다; import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다; -import static com.funeat.acceptance.common.CommonSteps.승인되지_않음; +import static com.funeat.acceptance.common.CommonSteps.인증되지_않음; import static com.funeat.acceptance.common.CommonSteps.잘못된_요청; import static com.funeat.acceptance.common.CommonSteps.정상_처리; import static com.funeat.acceptance.member.MemberSteps.사용자_정보_수정_요청; @@ -55,7 +55,7 @@ class getMemberProfile_실패_테스트 { final var response = 사용자_정보_조회_요청(null); // then - STATUS_CODE를_검증한다(response, 승인되지_않음); + STATUS_CODE를_검증한다(response, 인증되지_않음); 사용자_승인되지_않음을_검증하다(response); } } @@ -92,7 +92,7 @@ class putMemberProfile_실패_테스트 { final var response = 사용자_정보_수정_요청(null, request); // then - STATUS_CODE를_검증한다(response, 승인되지_않음); + STATUS_CODE를_검증한다(response, 인증되지_않음); 사용자_승인되지_않음을_검증하다(response); } diff --git a/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java index adbf621c8..36e94f003 100644 --- a/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java @@ -2,7 +2,7 @@ import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키를_얻는다; import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다; -import static com.funeat.acceptance.common.CommonSteps.승인되지_않음; +import static com.funeat.acceptance.common.CommonSteps.인증되지_않음; import static com.funeat.acceptance.common.CommonSteps.잘못된_요청; import static com.funeat.acceptance.common.CommonSteps.정상_생성; import static com.funeat.acceptance.common.CommonSteps.정상_처리; @@ -95,7 +95,7 @@ class writeRecipe_실패_테스트 { final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); - STATUS_CODE를_검증한다(response, 승인되지_않음); + STATUS_CODE를_검증한다(response, 인증되지_않음); RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); } diff --git a/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java index 43ce1e9c3..f3804e241 100644 --- a/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java @@ -2,7 +2,7 @@ import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키를_얻는다; import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다; -import static com.funeat.acceptance.common.CommonSteps.승인되지_않음; +import static com.funeat.acceptance.common.CommonSteps.인증되지_않음; import static com.funeat.acceptance.common.CommonSteps.잘못된_요청; import static com.funeat.acceptance.common.CommonSteps.정상_생성; import static com.funeat.acceptance.common.CommonSteps.정상_처리; @@ -120,7 +120,7 @@ class writeReview_실패_테스트 { final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); - STATUS_CODE를_검증한다(response, 승인되지_않음); + STATUS_CODE를_검증한다(response, 인증되지_않음); RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); } @@ -410,7 +410,7 @@ class toggleLikeReview_실패_테스트 { final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); - STATUS_CODE를_검증한다(response, 승인되지_않음); + STATUS_CODE를_검증한다(response, 인증되지_않음); RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); } @@ -740,7 +740,7 @@ class getSortingReviews_실패_테스트 { final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); - STATUS_CODE를_검증한다(response, 승인되지_않음); + STATUS_CODE를_검증한다(response, 인증되지_않음); RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); }