From d3a18a018eaf82cd9bdaeef033bf3542e54d5fca Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Tue, 13 Aug 2024 21:18:41 +0900 Subject: [PATCH 1/6] =?UTF-8?q?refactor=20:=20UserException=20->=20CustomE?= =?UTF-8?q?xception=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserController.java | 8 +++----- .../space_spring/exception/UserException.java | 20 ------------------- .../space_spring/service/UserService.java | 6 +----- .../space_spring/util/user/UserUtils.java | 6 +++--- 4 files changed, 7 insertions(+), 33 deletions(-) delete mode 100644 src/main/java/space/space_spring/exception/UserException.java diff --git a/src/main/java/space/space_spring/controller/UserController.java b/src/main/java/space/space_spring/controller/UserController.java index 9a69f6df..958f1599 100644 --- a/src/main/java/space/space_spring/controller/UserController.java +++ b/src/main/java/space/space_spring/controller/UserController.java @@ -11,7 +11,7 @@ import space.space_spring.dto.user.request.PostUserLoginRequest; import space.space_spring.dto.user.request.PostUserSignupRequest; import space.space_spring.dto.user.response.GetSpaceInfoForUserResponse; -import space.space_spring.exception.UserException; +import space.space_spring.exception.CustomException; import space.space_spring.response.BaseResponse; import space.space_spring.service.UserService; import space.space_spring.util.userSpace.UserSpaceUtils; @@ -34,7 +34,7 @@ public class UserController { @PostMapping("/signup") public BaseResponse signup(@Validated @RequestBody PostUserSignupRequest postUserSignupRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { - throw new UserException(INVALID_USER_SIGNUP, getErrorMessage(bindingResult)); + throw new CustomException(INVALID_USER_SIGNUP, getErrorMessage(bindingResult)); } userService.signup(postUserSignupRequest); @@ -48,7 +48,7 @@ public BaseResponse signup(@Validated @RequestBody PostUserSignupRequest @PostMapping("/login") public BaseResponse login(@Validated @RequestBody PostUserLoginRequest postUserLoginRequest, BindingResult bindingResult, HttpServletResponse response) { if (bindingResult.hasErrors()) { - throw new UserException(INVALID_USER_LOGIN, getErrorMessage(bindingResult)); + throw new CustomException(INVALID_USER_LOGIN, getErrorMessage(bindingResult)); } String jwtLogin = userService.login(postUserLoginRequest); @@ -75,8 +75,6 @@ public BaseResponse showUserSpaceList(@JwtLoginAuth @GetMapping("/profile") public BaseResponse showUserProfileList(@JwtLoginAuth Long userId) { - log.info("userId = {}", userId); - return new BaseResponse<>(userService.getUserProfileList(userId)); } } diff --git a/src/main/java/space/space_spring/exception/UserException.java b/src/main/java/space/space_spring/exception/UserException.java deleted file mode 100644 index 64bb9fef..00000000 --- a/src/main/java/space/space_spring/exception/UserException.java +++ /dev/null @@ -1,20 +0,0 @@ -package space.space_spring.exception; - -import lombok.Getter; -import space.space_spring.response.status.ResponseStatus; - -@Getter -public class UserException extends RuntimeException { - - private final ResponseStatus exceptionStatus; - - public UserException(ResponseStatus exceptionStatus) { - super(exceptionStatus.getMessage()); - this.exceptionStatus = exceptionStatus; - } - - public UserException(ResponseStatus exceptionStatus, String message) { - super(message); - this.exceptionStatus = exceptionStatus; - } -} diff --git a/src/main/java/space/space_spring/service/UserService.java b/src/main/java/space/space_spring/service/UserService.java index 25d8036a..88887e6a 100644 --- a/src/main/java/space/space_spring/service/UserService.java +++ b/src/main/java/space/space_spring/service/UserService.java @@ -10,16 +10,13 @@ import space.space_spring.dto.user.request.PostUserLoginRequest; import space.space_spring.dto.user.request.PostUserSignupRequest; import space.space_spring.dto.user.response.GetSpaceInfoForUserResponse; -import space.space_spring.dto.userSpace.GetUserProfileInSpaceDto; import space.space_spring.entity.UserSpace; import space.space_spring.entity.enumStatus.UserSignupType; import space.space_spring.exception.CustomException; import space.space_spring.jwt.JwtLoginProvider; import space.space_spring.dao.UserDao; import space.space_spring.entity.User; -import space.space_spring.exception.UserException; import space.space_spring.util.user.UserUtils; -import space.space_spring.util.userSpace.UserSpaceUtils; import java.util.ArrayList; import java.util.List; @@ -57,7 +54,6 @@ public Long signup(PostUserSignupRequest postUserSignupRequest) { private void validateEmailForLocalSignup(String email) { if (userDao.hasDuplicateEmail(email, UserSignupType.LOCAL)) { - //throw new UserException(DUPLICATE_EMAIL); throw new CustomException(DUPLICATE_EMAIL); } } @@ -80,7 +76,7 @@ public String login(PostUserLoginRequest postUserLoginRequest) { private void validatePassword(User userByEmail, String password) { if (!userByEmail.passwordMatch(password)) { - throw new UserException(PASSWORD_NO_MATCH); + throw new CustomException(PASSWORD_NO_MATCH); } } diff --git a/src/main/java/space/space_spring/util/user/UserUtils.java b/src/main/java/space/space_spring/util/user/UserUtils.java index 1c766ddf..c3b92d6f 100644 --- a/src/main/java/space/space_spring/util/user/UserUtils.java +++ b/src/main/java/space/space_spring/util/user/UserUtils.java @@ -6,7 +6,7 @@ import space.space_spring.dao.UserDao; import space.space_spring.entity.User; import space.space_spring.entity.enumStatus.UserSignupType; -import space.space_spring.exception.UserException; +import space.space_spring.exception.CustomException; import java.util.UUID; @@ -23,7 +23,7 @@ public class UserUtils { public User findUserByEmail(String email) { User findUser = userDao.getUserByEmail(email); if (findUser == null) { - throw new UserException(EMAIL_NOT_FOUND); + throw new CustomException(EMAIL_NOT_FOUND); } return findUser; } @@ -32,7 +32,7 @@ public User findUserByEmail(String email) { public User findUserByUserId(Long userId) { User userByUserId = userDao.findUserByUserId(userId); if (userByUserId == null) { - throw new UserException(USER_NOT_FOUND); + throw new CustomException(USER_NOT_FOUND); } return userByUserId; } From 94839c214dc520655b4a259ad0072d8eec976ff6 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Tue, 13 Aug 2024 22:09:00 +0900 Subject: [PATCH 2/6] =?UTF-8?q?fix=20:=20CustomExceptionControllerAdvice?= =?UTF-8?q?=20BaseErrorResponse=20=EA=B5=AC=EC=84=B1=EC=8B=9C=20errorMessa?= =?UTF-8?q?ge=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/space/space_spring/controller/UserController.java | 4 ++++ .../space_spring/dto/user/request/PostUserSignupRequest.java | 2 +- .../java/space/space_spring/exception/CustomException.java | 1 + .../exceptionHandler/CustomExceptionControllerAdvice.java | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/space/space_spring/controller/UserController.java b/src/main/java/space/space_spring/controller/UserController.java index 958f1599..d4e8110f 100644 --- a/src/main/java/space/space_spring/controller/UserController.java +++ b/src/main/java/space/space_spring/controller/UserController.java @@ -3,6 +3,7 @@ import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -12,10 +13,13 @@ import space.space_spring.dto.user.request.PostUserSignupRequest; import space.space_spring.dto.user.response.GetSpaceInfoForUserResponse; import space.space_spring.exception.CustomException; +import space.space_spring.exception.SpaceException; import space.space_spring.response.BaseResponse; import space.space_spring.service.UserService; import space.space_spring.util.userSpace.UserSpaceUtils; +import java.util.stream.Collectors; + import static space.space_spring.response.status.BaseExceptionResponseStatus.*; import static space.space_spring.util.bindingResult.BindingResultUtils.getErrorMessage; diff --git a/src/main/java/space/space_spring/dto/user/request/PostUserSignupRequest.java b/src/main/java/space/space_spring/dto/user/request/PostUserSignupRequest.java index 982a5ce1..bf797af5 100644 --- a/src/main/java/space/space_spring/dto/user/request/PostUserSignupRequest.java +++ b/src/main/java/space/space_spring/dto/user/request/PostUserSignupRequest.java @@ -21,7 +21,7 @@ public class PostUserSignupRequest { @Pattern( regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,16}$", - message = "8~16글자의 영문 대/소문자, 숫자, 특수문자가 포함되어야 합니다." + message = "비밀번호에는 8~16글자의 영문 대/소문자, 숫자, 특수문자가 포함되어야 합니다." ) @NotBlank private String password; diff --git a/src/main/java/space/space_spring/exception/CustomException.java b/src/main/java/space/space_spring/exception/CustomException.java index 03048083..d7305f96 100644 --- a/src/main/java/space/space_spring/exception/CustomException.java +++ b/src/main/java/space/space_spring/exception/CustomException.java @@ -2,6 +2,7 @@ import lombok.Getter; import space.space_spring.response.status.ResponseStatus; + @Getter public class CustomException extends RuntimeException{ diff --git a/src/main/java/space/space_spring/exceptionHandler/CustomExceptionControllerAdvice.java b/src/main/java/space/space_spring/exceptionHandler/CustomExceptionControllerAdvice.java index f3db23d3..06b811a1 100644 --- a/src/main/java/space/space_spring/exceptionHandler/CustomExceptionControllerAdvice.java +++ b/src/main/java/space/space_spring/exceptionHandler/CustomExceptionControllerAdvice.java @@ -19,7 +19,7 @@ public class CustomExceptionControllerAdvice { @ExceptionHandler(CustomException.class) public ResponseEntity handle_JwtBadRequestException(CustomException e) { log.error("[handle_JwtBadRequestException]", e); - BaseErrorResponse errorResponse = new BaseErrorResponse(e.getExceptionStatus()); + BaseErrorResponse errorResponse = new BaseErrorResponse(e.getExceptionStatus(), e.getMessage()); return ResponseEntity.status(e.getExceptionStatus().getStatus()).body(errorResponse); } } From f4098495bdd90686ccae46306a74c4c32fd35013 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Tue, 13 Aug 2024 22:25:12 +0900 Subject: [PATCH 3/6] =?UTF-8?q?refactor=20:=20=EB=82=98=EB=A8=B8=EC=A7=80?= =?UTF-8?q?=20exception=20->=20customException=20=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SpaceController.java | 9 +++----- .../controller/UserController.java | 1 - .../exception/MultipartFileException.java | 20 ------------------ .../exception/SpaceException.java | 21 ------------------- .../space_spring/service/PayService.java | 4 ++-- .../space_spring/service/SpaceService.java | 6 +++--- .../space_spring/util/space/SpaceUtils.java | 4 ++-- .../util/userSpace/MemoryUserSpaceUtils.java | 6 +++--- 8 files changed, 13 insertions(+), 58 deletions(-) delete mode 100644 src/main/java/space/space_spring/exception/MultipartFileException.java delete mode 100644 src/main/java/space/space_spring/exception/SpaceException.java diff --git a/src/main/java/space/space_spring/controller/SpaceController.java b/src/main/java/space/space_spring/controller/SpaceController.java index 640d3228..7952df0e 100644 --- a/src/main/java/space/space_spring/controller/SpaceController.java +++ b/src/main/java/space/space_spring/controller/SpaceController.java @@ -14,10 +14,7 @@ import space.space_spring.dto.userSpace.GetUserProfileInSpaceDto; import space.space_spring.dto.userSpace.PutUserProfileInSpaceDto; -import space.space_spring.entity.UserSpace; import space.space_spring.exception.CustomException; -import space.space_spring.exception.MultipartFileException; -import space.space_spring.exception.SpaceException; import space.space_spring.response.BaseResponse; import space.space_spring.service.S3Uploader; import space.space_spring.service.SpaceService; @@ -44,7 +41,7 @@ public class SpaceController { @PostMapping("") public BaseResponse createSpace(@JwtLoginAuth Long userId, @Validated @ModelAttribute PostSpaceCreateRequest postSpaceCreateRequest, BindingResult bindingResult) throws IOException { if (bindingResult.hasErrors()) { - throw new SpaceException(INVALID_SPACE_CREATE, getErrorMessage(bindingResult)); + throw new CustomException(INVALID_SPACE_CREATE, getErrorMessage(bindingResult)); } // TODO 1. 스페이스 썸네일을 s3에 upload @@ -67,7 +64,7 @@ private String processSpaceImage(MultipartFile spaceProfileImg) throws IOExcepti private void validateImageFile(MultipartFile spaceProfileImg) { if (!s3Uploader.isFileImage(spaceProfileImg)) { - throw new MultipartFileException(IS_NOT_IMAGE_FILE); + throw new CustomException(IS_NOT_IMAGE_FILE); } } @@ -133,7 +130,7 @@ private void validateIsUserInSpace(Long userId, Long spaceId) { @PutMapping("/{spaceId}/member-profile") public BaseResponse updateUserProfileInSpace(@JwtLoginAuth Long userId, @PathVariable Long spaceId, @Validated @ModelAttribute PutUserProfileInSpaceDto.Request request, BindingResult bindingResult) throws IOException { if (bindingResult.hasErrors()) { - throw new SpaceException(INVALID_USER_SPACE_PROFILE, getErrorMessage(bindingResult)); + throw new CustomException(INVALID_USER_SPACE_PROFILE, getErrorMessage(bindingResult)); } // TODO 1. 유저가 스페이스에 가입되어 있는지 검증 diff --git a/src/main/java/space/space_spring/controller/UserController.java b/src/main/java/space/space_spring/controller/UserController.java index d4e8110f..9de56efe 100644 --- a/src/main/java/space/space_spring/controller/UserController.java +++ b/src/main/java/space/space_spring/controller/UserController.java @@ -13,7 +13,6 @@ import space.space_spring.dto.user.request.PostUserSignupRequest; import space.space_spring.dto.user.response.GetSpaceInfoForUserResponse; import space.space_spring.exception.CustomException; -import space.space_spring.exception.SpaceException; import space.space_spring.response.BaseResponse; import space.space_spring.service.UserService; import space.space_spring.util.userSpace.UserSpaceUtils; diff --git a/src/main/java/space/space_spring/exception/MultipartFileException.java b/src/main/java/space/space_spring/exception/MultipartFileException.java deleted file mode 100644 index 3292f14a..00000000 --- a/src/main/java/space/space_spring/exception/MultipartFileException.java +++ /dev/null @@ -1,20 +0,0 @@ -package space.space_spring.exception; - -import lombok.Getter; -import space.space_spring.response.status.ResponseStatus; - -@Getter -public class MultipartFileException extends RuntimeException { - - private final ResponseStatus exceptionStatus; - - public MultipartFileException(ResponseStatus exceptionStatus) { - super(exceptionStatus.getMessage()); - this.exceptionStatus = exceptionStatus; - } - - public MultipartFileException(ResponseStatus exceptionStatus, String message) { - super(message); - this.exceptionStatus = exceptionStatus; - } -} diff --git a/src/main/java/space/space_spring/exception/SpaceException.java b/src/main/java/space/space_spring/exception/SpaceException.java deleted file mode 100644 index d8369c8f..00000000 --- a/src/main/java/space/space_spring/exception/SpaceException.java +++ /dev/null @@ -1,21 +0,0 @@ -package space.space_spring.exception; - -import lombok.Getter; -import space.space_spring.response.status.ResponseStatus; - -@Getter -public class SpaceException extends RuntimeException { - - private final ResponseStatus exceptionStatus; - - public SpaceException(ResponseStatus exceptionStatus) { - super(exceptionStatus.getMessage()); - this.exceptionStatus = exceptionStatus; - } - - public SpaceException(ResponseStatus exceptionStatus, String message) { - super(message); - this.exceptionStatus = exceptionStatus; - } - -} diff --git a/src/main/java/space/space_spring/service/PayService.java b/src/main/java/space/space_spring/service/PayService.java index 35e80e8b..63ed47e4 100644 --- a/src/main/java/space/space_spring/service/PayService.java +++ b/src/main/java/space/space_spring/service/PayService.java @@ -11,7 +11,7 @@ import space.space_spring.dto.pay.response.GetRecentPayRequestBankInfoResponse; import space.space_spring.dto.pay.response.PostPayCompleteResponse; import space.space_spring.entity.*; -import space.space_spring.exception.UserSpaceException; +import space.space_spring.exception.CustomException; import space.space_spring.util.space.SpaceUtils; import space.space_spring.util.user.UserUtils; @@ -186,7 +186,7 @@ private PayTargetInfoDto createPayTargetInfoDto(PayRequestTarget payRequestTarge User userByUserId = userDao.findUserByUserId(targetUserId); UserSpace userSpace = userSpaceDao.findUserSpaceByUserAndSpace(userByUserId, space) - .orElseThrow(() -> new UserSpaceException(USER_IS_NOT_IN_SPACE)); + .orElseThrow(() -> new CustomException(USER_IS_NOT_IN_SPACE)); String userName = userSpace.getUserName(); String userProfileImg = userSpace.getUserProfileImg(); diff --git a/src/main/java/space/space_spring/service/SpaceService.java b/src/main/java/space/space_spring/service/SpaceService.java index d7e8f15a..04f067dd 100644 --- a/src/main/java/space/space_spring/service/SpaceService.java +++ b/src/main/java/space/space_spring/service/SpaceService.java @@ -15,7 +15,7 @@ import space.space_spring.entity.User; import space.space_spring.entity.UserSpace; import space.space_spring.entity.enumStatus.UserSpaceAuth; -import space.space_spring.exception.UserSpaceException; +import space.space_spring.exception.CustomException; import space.space_spring.util.space.SpaceUtils; import space.space_spring.util.user.UserUtils; import space.space_spring.util.userSpace.UserSpaceUtils; @@ -106,7 +106,7 @@ public GetUserProfileInSpaceDto.Response getUserProfileInSpace(Long userId, Long // userSpaceUtils.isUserInSpace 메서드에서도 해당 에러를 던지기는 하지만 // 컴파일 에러의 방지를 위해 일단 이중으로 예외를 던지도록 구현했습니다 - throw new UserSpaceException(USER_IS_NOT_IN_SPACE); + throw new CustomException(USER_IS_NOT_IN_SPACE); } @Transactional @@ -134,7 +134,7 @@ public PutUserProfileInSpaceDto.Response changeUserProfileInSpace(Long userId, L // userSpaceUtils.isUserInSpace 메서드에서도 해당 에러를 던지기는 하지만 // 컴파일 에러의 방지를 위해 일단 이중으로 예외를 던지도록 구현했습니다 - throw new UserSpaceException(USER_IS_NOT_IN_SPACE); + throw new CustomException(USER_IS_NOT_IN_SPACE); } diff --git a/src/main/java/space/space_spring/util/space/SpaceUtils.java b/src/main/java/space/space_spring/util/space/SpaceUtils.java index 2943bcbc..d050e09b 100644 --- a/src/main/java/space/space_spring/util/space/SpaceUtils.java +++ b/src/main/java/space/space_spring/util/space/SpaceUtils.java @@ -5,7 +5,7 @@ import org.springframework.transaction.annotation.Transactional; import space.space_spring.dao.SpaceDao; import space.space_spring.entity.Space; -import space.space_spring.exception.SpaceException; +import space.space_spring.exception.CustomException; import static space.space_spring.response.status.BaseExceptionResponseStatus.SPACE_NOT_FOUND; @@ -19,7 +19,7 @@ public class SpaceUtils { public Space findSpaceBySpaceId(Long spaceId) { Space spaceBySpaceId = spaceDao.findSpaceBySpaceId(spaceId); if (spaceBySpaceId == null) { - throw new SpaceException(SPACE_NOT_FOUND); + throw new CustomException(SPACE_NOT_FOUND); } return spaceBySpaceId; } diff --git a/src/main/java/space/space_spring/util/userSpace/MemoryUserSpaceUtils.java b/src/main/java/space/space_spring/util/userSpace/MemoryUserSpaceUtils.java index 419d4694..a7f34c0e 100644 --- a/src/main/java/space/space_spring/util/userSpace/MemoryUserSpaceUtils.java +++ b/src/main/java/space/space_spring/util/userSpace/MemoryUserSpaceUtils.java @@ -10,7 +10,7 @@ import space.space_spring.entity.User; import space.space_spring.entity.UserSpace; import space.space_spring.entity.enumStatus.UserSpaceAuth; -import space.space_spring.exception.UserSpaceException; +import space.space_spring.exception.CustomException; import java.util.Optional; @@ -32,7 +32,7 @@ public Optional isUserInSpace(Long userId, Long spaceId) { Space spaceBySpaceId = spaceDao.findSpaceBySpaceId(spaceId); return Optional.ofNullable(userSpaceDao.findUserSpaceByUserAndSpace(userByUserId, spaceBySpaceId) - .orElseThrow(() -> new UserSpaceException(USER_IS_NOT_IN_SPACE))); + .orElseThrow(() -> new CustomException(USER_IS_NOT_IN_SPACE))); } @Override @@ -59,7 +59,7 @@ public void isUserAlreadySpaceMember(Long userId, Long spaceId) { Optional userSpaceByUserAndSpace = userSpaceDao.findUserSpaceByUserAndSpace(userByUserId, spaceBySpaceId); if (userSpaceByUserAndSpace.isPresent()) { - throw new UserSpaceException(USER_IS_ALREADY_IN_SPACE); + throw new CustomException(USER_IS_ALREADY_IN_SPACE); } } } From 92842bbb7d8ad2c4b7c34dab356234e7c648ef76 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Tue, 13 Aug 2024 22:27:55 +0900 Subject: [PATCH 4/6] =?UTF-8?q?refactor=20:=20UserSpaceException=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/UserSpaceException.java | 20 ------------------- .../UserSpaceValidationInterceptor.java | 1 - 2 files changed, 21 deletions(-) delete mode 100644 src/main/java/space/space_spring/exception/UserSpaceException.java diff --git a/src/main/java/space/space_spring/exception/UserSpaceException.java b/src/main/java/space/space_spring/exception/UserSpaceException.java deleted file mode 100644 index 68e486eb..00000000 --- a/src/main/java/space/space_spring/exception/UserSpaceException.java +++ /dev/null @@ -1,20 +0,0 @@ -package space.space_spring.exception; - -import lombok.Getter; -import space.space_spring.response.status.ResponseStatus; - -@Getter -public class UserSpaceException extends RuntimeException { - - private final ResponseStatus exceptionStatus; - - public UserSpaceException(ResponseStatus exceptionStatus) { - super(exceptionStatus.getMessage()); - this.exceptionStatus = exceptionStatus; - } - - public UserSpaceException(ResponseStatus exceptionStatus, String message) { - super(message); - this.exceptionStatus = exceptionStatus; - } -} diff --git a/src/main/java/space/space_spring/interceptor/UserSpaceValidationInterceptor.java b/src/main/java/space/space_spring/interceptor/UserSpaceValidationInterceptor.java index 4b8398a0..062cd029 100644 --- a/src/main/java/space/space_spring/interceptor/UserSpaceValidationInterceptor.java +++ b/src/main/java/space/space_spring/interceptor/UserSpaceValidationInterceptor.java @@ -15,7 +15,6 @@ import space.space_spring.entity.User; import space.space_spring.entity.UserSpace; import space.space_spring.exception.CustomException; -import space.space_spring.exception.UserSpaceException; import java.util.Map; import java.util.Optional; From cc1e5fb6ed810fbdc1528f3abc22b4db2e1fae3c Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Tue, 13 Aug 2024 22:59:20 +0900 Subject: [PATCH 5/6] =?UTF-8?q?refactor=20:=20=EC=8A=A4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=83=9D=EC=84=B1=20=EC=8B=9C=20response=EB=A1=9C?= =?UTF-8?q?=20spaceId=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SpaceController.java | 9 +++--- .../dto/space/request/PostSpaceCreateDto.java | 32 +++++++++++++++++++ .../space/request/PostSpaceCreateRequest.java | 22 ------------- .../space_spring/service/SpaceService.java | 4 +-- 4 files changed, 39 insertions(+), 28 deletions(-) create mode 100644 src/main/java/space/space_spring/dto/space/request/PostSpaceCreateDto.java delete mode 100644 src/main/java/space/space_spring/dto/space/request/PostSpaceCreateRequest.java diff --git a/src/main/java/space/space_spring/controller/SpaceController.java b/src/main/java/space/space_spring/controller/SpaceController.java index 7952df0e..102fadf4 100644 --- a/src/main/java/space/space_spring/controller/SpaceController.java +++ b/src/main/java/space/space_spring/controller/SpaceController.java @@ -9,11 +9,12 @@ import space.space_spring.argumentResolver.jwtLogin.JwtLoginAuth; import space.space_spring.dto.space.GetSpaceJoinDto; import space.space_spring.dto.space.PostSpaceJoinDto; +import space.space_spring.dto.space.request.PostSpaceCreateDto; import space.space_spring.dto.space.response.GetUserInfoBySpaceResponse; -import space.space_spring.dto.space.request.PostSpaceCreateRequest; import space.space_spring.dto.userSpace.GetUserProfileInSpaceDto; import space.space_spring.dto.userSpace.PutUserProfileInSpaceDto; +import space.space_spring.entity.Space; import space.space_spring.exception.CustomException; import space.space_spring.response.BaseResponse; import space.space_spring.service.S3Uploader; @@ -39,7 +40,7 @@ public class SpaceController { private final UserSpaceUtils userSpaceUtils; @PostMapping("") - public BaseResponse createSpace(@JwtLoginAuth Long userId, @Validated @ModelAttribute PostSpaceCreateRequest postSpaceCreateRequest, BindingResult bindingResult) throws IOException { + public BaseResponse createSpace(@JwtLoginAuth Long userId, @Validated @ModelAttribute PostSpaceCreateDto.Request postSpaceCreateRequest, BindingResult bindingResult) throws IOException { if (bindingResult.hasErrors()) { throw new CustomException(INVALID_SPACE_CREATE, getErrorMessage(bindingResult)); } @@ -48,9 +49,9 @@ public BaseResponse createSpace(@JwtLoginAuth Long userId, @Validated @M String spaceImgUrl = processSpaceImage(postSpaceCreateRequest.getSpaceProfileImg()); // TODO 2. s3에 저장하고 받은 이미지 url 정보와 spaceName 정보로 space create 작업 수행 - spaceService.createSpace(userId, postSpaceCreateRequest.getSpaceName(), spaceImgUrl); + Space createSpace = spaceService.createSpace(userId, postSpaceCreateRequest.getSpaceName(), spaceImgUrl); - return new BaseResponse<>("스페이스 생성 성공"); + return new BaseResponse<>(new PostSpaceCreateDto.Response(createSpace.getSpaceId())); } private String processSpaceImage(MultipartFile spaceProfileImg) throws IOException { diff --git a/src/main/java/space/space_spring/dto/space/request/PostSpaceCreateDto.java b/src/main/java/space/space_spring/dto/space/request/PostSpaceCreateDto.java new file mode 100644 index 00000000..de71436d --- /dev/null +++ b/src/main/java/space/space_spring/dto/space/request/PostSpaceCreateDto.java @@ -0,0 +1,32 @@ +package space.space_spring.dto.space.request; + +import jakarta.annotation.Nullable; +import jakarta.validation.constraints.NotBlank; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.hibernate.validator.constraints.Length; +import org.springframework.web.multipart.MultipartFile; + +public class PostSpaceCreateDto { + + @Getter + @Setter + @NoArgsConstructor + public static class Request { + @Length(min = 1, max = 10, message = "이름은 10자이내의 문자열이어야 합니다.") + @NotBlank(message = "스페이스 이름은 공백일 수 없습니다.") + private String spaceName; + + @Nullable + private MultipartFile spaceProfileImg; // 스페이스 프로필 이미지 (썸네일) + } + + @Getter + @AllArgsConstructor + public static class Response { + + private Long spaceId; + } +} diff --git a/src/main/java/space/space_spring/dto/space/request/PostSpaceCreateRequest.java b/src/main/java/space/space_spring/dto/space/request/PostSpaceCreateRequest.java deleted file mode 100644 index 42d7964b..00000000 --- a/src/main/java/space/space_spring/dto/space/request/PostSpaceCreateRequest.java +++ /dev/null @@ -1,22 +0,0 @@ -package space.space_spring.dto.space.request; - -import jakarta.annotation.Nullable; -import jakarta.validation.constraints.NotBlank; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.hibernate.validator.constraints.Length; -import org.springframework.web.multipart.MultipartFile; - -@Getter -@Setter -@NoArgsConstructor -public class PostSpaceCreateRequest { - - @Length(min = 1, max = 10, message = "이름은 10자이내의 문자열이어야 합니다.") - @NotBlank(message = "스페이스 이름은 공백일 수 없습니다.") - private String spaceName; - - @Nullable - private MultipartFile spaceProfileImg; // 스페이스 프로필 이미지 (썸네일) -} diff --git a/src/main/java/space/space_spring/service/SpaceService.java b/src/main/java/space/space_spring/service/SpaceService.java index 04f067dd..f1dd8bcc 100644 --- a/src/main/java/space/space_spring/service/SpaceService.java +++ b/src/main/java/space/space_spring/service/SpaceService.java @@ -38,7 +38,7 @@ public class SpaceService { private final UserUtils userUtils; @Transactional - public Long createSpace(Long userId, String spaceName, String spaceImgUrl) { + public Space createSpace(Long userId, String spaceName, String spaceImgUrl) { // TODO 1. 스페이스 생성 정보 db insert Space saveSpace = spaceDao.saveSpace(spaceName, spaceImgUrl); @@ -47,7 +47,7 @@ public Long createSpace(Long userId, String spaceName, String spaceImgUrl) { User manager = userDao.findUserByUserId(userId); UserSpace userSpace = userSpaceDao.createUserSpace(manager, saveSpace, UserSpaceAuth.MANAGER); - return saveSpace.getSpaceId(); + return saveSpace; } @Transactional From f2fc786ad417dae9bc52fdb406f783c251a54123 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Tue, 13 Aug 2024 23:36:29 +0900 Subject: [PATCH 6/6] =?UTF-8?q?refactor=20:=20=EB=82=B4=EA=B0=80=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=EB=B0=9B=EC=9D=80=20=EC=A0=95=EC=82=B0=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20api=20response=EC=97=90=20=EC=86=A1?= =?UTF-8?q?=EA=B8=88=ED=95=B4=EC=95=BC=ED=95=A0=20=EC=9D=80=ED=96=89=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space/space_spring/dto/pay/dto/PayReceiveInfoDto.java | 4 ++++ src/main/java/space/space_spring/service/PayService.java | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/space/space_spring/dto/pay/dto/PayReceiveInfoDto.java b/src/main/java/space/space_spring/dto/pay/dto/PayReceiveInfoDto.java index 61146f5a..cce7ba60 100644 --- a/src/main/java/space/space_spring/dto/pay/dto/PayReceiveInfoDto.java +++ b/src/main/java/space/space_spring/dto/pay/dto/PayReceiveInfoDto.java @@ -12,4 +12,8 @@ public class PayReceiveInfoDto { private String payCreatorName; private int requestAmount; + + private String bankName; + + private String bankAccountNum; } diff --git a/src/main/java/space/space_spring/service/PayService.java b/src/main/java/space/space_spring/service/PayService.java index 63ed47e4..307edde5 100644 --- a/src/main/java/space/space_spring/service/PayService.java +++ b/src/main/java/space/space_spring/service/PayService.java @@ -107,7 +107,11 @@ private PayReceiveInfoDto createPayReceiveInfoDto(PayRequestTarget payRequestTar String payCreatorName = payRequestTarget.getPayRequest().getPayCreateUser().getUserName(); // 리펙토링 필요 int requestAmount = payRequestTarget.getRequestAmount(); - return new PayReceiveInfoDto(payRequestTarget.getPayRequestTargetId(), payCreatorName, requestAmount); + // 정산 생성자가 요청한 은행 정보도 response에 추가 + String bankName = payRequestTarget.getPayRequest().getBankName(); + String bankAccountNum = payRequestTarget.getPayRequest().getBankAccountNum(); + + return new PayReceiveInfoDto(payRequestTarget.getPayRequestTargetId(), payCreatorName, requestAmount, bankName, bankAccountNum); } @Transactional