From 8b800ff66b557f48222e2e453f2f0fb97f3431e9 Mon Sep 17 00:00:00 2001 From: JuhyunPark Date: Mon, 8 Apr 2024 04:17:19 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Fix:=20MemberService=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/service/MemberServiceImpl.java | 2 +- .../user/service/MemberServiceTest.java | 100 ++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberServiceImpl.java b/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberServiceImpl.java index 28c24d0..ce5e5f9 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberServiceImpl.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberServiceImpl.java @@ -147,7 +147,7 @@ public Page find(MemberSearchOption option, Pageable pageable members = memberRepository.findByRole(MemberRole.TRAINER,pageable); } - if(members == null) { + if(members.getContent().isEmpty()) { throw new CustomException("회원이 없습니다", ErrorCode.MEMBER_NOT_FOUND); } diff --git a/src/test/java/com/sideProject/PlanIT/domain/user/service/MemberServiceTest.java b/src/test/java/com/sideProject/PlanIT/domain/user/service/MemberServiceTest.java index d1dae14..dc05241 100644 --- a/src/test/java/com/sideProject/PlanIT/domain/user/service/MemberServiceTest.java +++ b/src/test/java/com/sideProject/PlanIT/domain/user/service/MemberServiceTest.java @@ -278,6 +278,24 @@ void editMember() { assertThat(member.getAddress()).isEqualTo("경기"); assertThat(result).isEqualTo("수정 완료"); } + + @DisplayName("사용자가 없으면 에러를 반환한다") + @Test + void editMember2() { + + // given + MemberEditRequestDto memberEditRequestDto = MemberEditRequestDto.builder() + .name("test2") + .phone_number("010-1234-5678") + .birth(LocalDate.of(2001, 1, 1)) + .address("경기") + .build(); + + // when, then + assertThatThrownBy(() -> memberService.editMember(2L, memberEditRequestDto)) + .isInstanceOf(CustomException.class) + .hasMessage("회원을 찾을 수 없습니다"); + } } @Nested @@ -363,6 +381,26 @@ void changePassword4() { .isInstanceOf(CustomException.class) .hasMessage("변경 비밀번호가 같습니다."); } + + @DisplayName("사용자가 없으면 에러가 발생한다") + @Test + void changePassword5() { + + // given + initMember("test1", passwordEncoder.encode("test1234"), MemberRole.MEMBER); + + // when + MemberChangePasswordRequestDto memberChangePasswordRequestDto = MemberChangePasswordRequestDto.builder() + .currentPassword("test1234") + .newPassword("test1234") + .newPasswordCheck("test1234") + .build(); + + // then + assertThatThrownBy(() -> memberService.changePassword(2L, memberChangePasswordRequestDto)) + .isInstanceOf(CustomException.class) + .hasMessage("회원을 찾을 수 없습니다"); + } } @Nested @@ -387,6 +425,19 @@ void findMember() { assertThat(memberResponseDto.getRole()).isEqualTo(MemberRole.MEMBER); } + @DisplayName("member_id를 가진 멤버가 없으면 에러가 발생한다") + @Test + void findMember2() { + + // given + initMember("test1", passwordEncoder.encode("test1234"), MemberRole.MEMBER); + + // when, given + assertThatThrownBy(() -> memberService.findMember(2L)) + .isInstanceOf(CustomException.class) + .hasMessage("회원을 찾을 수 없습니다"); + } + @DisplayName("member_id로 조회한 멤버가 트레이너면 트레이너 정보와 함께 조회한다") @Test void findMemberTrainer() { @@ -421,6 +472,26 @@ void findMemberTrainer() { assertThat(memberResponseDto.getTrainerInfo().getTrainerMessage()).isEqualTo("test trainer message"); } + @DisplayName("member_id로 조회한 멤버가 트레이너이지만 트레이너 데이터가 없으면 에러가 발생한다") + @Test + void findMemberTrainer2() { + + // given + memberRepository.save(Member.builder() + .email("test1@naver.com") + .password("test1234") + .name("test1") + .birth(LocalDate.of(2000, 1, 1)) + .address("서울") + .phone_number("010-0000-0000") + .role(MemberRole.TRAINER) + .build()); + // when, then + assertThatThrownBy(() -> memberService.findMember(memberRepository.findByEmail("test1@naver.com").get().getId())) + .isInstanceOf(CustomException.class) + .hasMessage("직원을 찾을 수 없습니다"); + } + } @Nested @@ -510,6 +581,19 @@ void find3() { assertThat(result.getTotalPages()).isEqualTo(1); assertThat(result.getContent().size()).isEqualTo(2); } + + @DisplayName("회원도 트레이너도 없으면 에러가 발생한다") + @Test + void find4() { + + // when + Pageable pageable = PageRequest.of(0, 3); + + // then + assertThatThrownBy(() -> memberService.find(MemberSearchOption.ALL, pageable)) + .isInstanceOf(CustomException.class) + .hasMessage("회원이 없습니다"); + } } @Nested @@ -563,5 +647,21 @@ void grantEmployee() { // then assertThat(memberRepository.findByEmail("test1@naver.com").get().getRole()).isEqualTo(MemberRole.TRAINER); } + + @DisplayName("회원이 없으면 에러가 발생한다") + @Test + void grantEmployee2() { + // given + initMember("test1", passwordEncoder.encode("test1234"), MemberRole.MEMBER); + TrainerRequestDto trainerRequestDto = TrainerRequestDto.builder() + .career("P1Y2M3D") + .trainerMessage("test trainer message") + .build(); + + // when, then + assertThatThrownBy(() -> memberService.grantEmployeeAuth(2L, trainerRequestDto)) + .isInstanceOf(CustomException.class) + .hasMessage("회원을 찾을 수 없습니다"); + } } } From 0758457bb614a35504564929b698e60e999cac3a Mon Sep 17 00:00:00 2001 From: moonjin-kim Date: Mon, 8 Apr 2024 16:36:31 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=EC=97=90=EB=9F=AC=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80=20=EB=B0=8F?= =?UTF-8?q?=20reservationDto=20=ED=8A=B8=EB=A0=88=EC=9D=B4=EB=84=88=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 --- .../PlanIT/common/response/ApiResponse.java | 15 ++++++++++- .../response/GlobalExceptionHandler.java | 23 ++++++++++++++++- .../security/JwtAuthenticationEntryPoint.java | 14 ++++++++++- .../controller/BannerAdminController.java | 1 - .../controller/NoticeAdminController.java | 3 ++- .../post/dto/request/NoticeRequestDto.java | 4 +++ .../controller/ProductAdminController.java | 3 ++- .../dto/request/ProductRequestDto.java | 5 ++++ .../controller/ProgramAdminController.java | 3 ++- .../program/controller/ProgramController.java | 8 +++--- .../dto/request/ApproveRequestDto.java | 6 ++++- .../dto/request/ProgramModifyRequestDto.java | 3 +++ .../dto/request/ProgramRegistraionDto.java | 25 ------------------- .../dto/request/RegistrationRequestDto.java | 8 ++++-- .../programRegistrationRequestDto.java | 23 +++++++++++++++++ .../response/FindRegistrationResponseDto.java | 13 +++++++--- .../domain/program/entity/Registration.java | 11 +++++++- .../program/service/ProgramServiceImpl.java | 15 ++++++++++- .../controller/ReservationController.java | 5 ++-- .../reqeust/ChangeReservationRequestDto.java | 3 +++ .../dto/reqeust/ReservationRequestDto.java | 3 +++ .../user/controller/MemberController.java | 4 +-- ...qeustDto.java => EmailSendRequestDto.java} | 4 ++- .../member/request/MemberEditRequestDto.java | 2 ++ .../request/MemberSignUpRequestDto.java | 21 +++++++++++++++- 25 files changed, 174 insertions(+), 51 deletions(-) delete mode 100644 src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramRegistraionDto.java create mode 100644 src/main/java/com/sideProject/PlanIT/domain/program/dto/request/programRegistrationRequestDto.java rename src/main/java/com/sideProject/PlanIT/domain/user/dto/member/request/{EmailSendReqeustDto.java => EmailSendRequestDto.java} (74%) diff --git a/src/main/java/com/sideProject/PlanIT/common/response/ApiResponse.java b/src/main/java/com/sideProject/PlanIT/common/response/ApiResponse.java index 070d357..5a75924 100644 --- a/src/main/java/com/sideProject/PlanIT/common/response/ApiResponse.java +++ b/src/main/java/com/sideProject/PlanIT/common/response/ApiResponse.java @@ -22,5 +22,18 @@ public ApiResponse(int code, String message, T data) { public static ApiResponse ok(T data) {return new ApiResponse<>(HttpStatus.OK.value(), HttpStatus.OK.name(), data);} - public static ApiResponse error(ErrorCode errorCode) {return new ApiResponse<>(errorCode.getStatus(), errorCode.getMessage(),null);} + public static ApiResponse error(ErrorCode errorCode) { + return new ApiResponse<>( + errorCode.getStatus(), + errorCode.getMessage(), + null); + } + + public static ApiResponse error(int code, String message) { + return new ApiResponse<>( + code, + message, + null + ); + } } diff --git a/src/main/java/com/sideProject/PlanIT/common/response/GlobalExceptionHandler.java b/src/main/java/com/sideProject/PlanIT/common/response/GlobalExceptionHandler.java index 7af5321..450ba33 100644 --- a/src/main/java/com/sideProject/PlanIT/common/response/GlobalExceptionHandler.java +++ b/src/main/java/com/sideProject/PlanIT/common/response/GlobalExceptionHandler.java @@ -1,10 +1,15 @@ package com.sideProject.PlanIT.common.response; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.UnexpectedTypeException; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.validation.BindException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.servlet.NoHandlerFoundException; +import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; @RestControllerAdvice @Slf4j @@ -17,8 +22,24 @@ protected ResponseEntity> handleCustomException(CustomException e } @ExceptionHandler(value = HttpMessageNotReadableException.class) - protected ResponseEntity> handleHttpMessageException(HttpMessageNotReadableException ex) { + protected ResponseEntity> handleHttpException(HttpMessageNotReadableException ex) { return ResponseEntity.status(400) .body(ApiResponse.error(ErrorCode.INVALID_INPUT)); } + + @ExceptionHandler(value = BindException.class) + protected ResponseEntity> handleHttpException(BindException ex) { + return ResponseEntity.status(400) + .body( + ApiResponse.error( + 400, + ex.getBindingResult().getAllErrors().get(0).getDefaultMessage())); + } + + @ExceptionHandler(NoHandlerFoundException.class) + protected ResponseEntity> handleNoHandlerFoundException(NoHandlerFoundException e, + HttpServletRequest request) { + return ResponseEntity.status(404) + .body(ApiResponse.error(404, "잘못된 페이지 입니다.")); + } } diff --git a/src/main/java/com/sideProject/PlanIT/common/security/JwtAuthenticationEntryPoint.java b/src/main/java/com/sideProject/PlanIT/common/security/JwtAuthenticationEntryPoint.java index cf7386b..f46cb49 100644 --- a/src/main/java/com/sideProject/PlanIT/common/security/JwtAuthenticationEntryPoint.java +++ b/src/main/java/com/sideProject/PlanIT/common/security/JwtAuthenticationEntryPoint.java @@ -1,7 +1,10 @@ package com.sideProject.PlanIT.common.security; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.sideProject.PlanIT.common.response.ApiResponse; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.stereotype.Component; @@ -9,12 +12,21 @@ import java.io.IOException; @Component +@Slf4j public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { + private ObjectMapper mapper = new ObjectMapper(); @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException { + String accept = request.getHeader("Accept"); + log.info(accept); - response.sendError(HttpServletResponse.SC_UNAUTHORIZED); + ApiResponse error = ApiResponse.error(401," Authentication information not found."); + + String result = mapper.writeValueAsString(error); + + response.setStatus(401); + response.getWriter().write(result); } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerAdminController.java b/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerAdminController.java index ec95b16..e86eb3e 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerAdminController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerAdminController.java @@ -21,7 +21,6 @@ public class BannerAdminController { @PostMapping public ApiResponse createBanner(@ModelAttribute BannerRequestDto request ) { - log.info(request.getTitle()); return ApiResponse.ok(bannerService.createBanner(request)); } diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeAdminController.java b/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeAdminController.java index 5a13e39..5b413dd 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeAdminController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeAdminController.java @@ -4,6 +4,7 @@ import com.sideProject.PlanIT.domain.post.dto.request.NoticeRequestDto; import com.sideProject.PlanIT.domain.post.dto.response.NoticeResponseDto; import com.sideProject.PlanIT.domain.post.service.NoticeService; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -17,7 +18,7 @@ public class NoticeAdminController { private final NoticeService noticeService; @PostMapping - public ApiResponse createNotice(@ModelAttribute NoticeRequestDto request) { + public ApiResponse createNotice(@Valid @ModelAttribute NoticeRequestDto request) { return ApiResponse.ok(noticeService.createNotice(request)); } diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/dto/request/NoticeRequestDto.java b/src/main/java/com/sideProject/PlanIT/domain/post/dto/request/NoticeRequestDto.java index 38a9c20..e0d9f18 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/dto/request/NoticeRequestDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/dto/request/NoticeRequestDto.java @@ -1,5 +1,6 @@ package com.sideProject.PlanIT.domain.post.dto.request; +import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -10,8 +11,11 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class NoticeRequestDto { + @NotNull(message = "제목이 업습니다.") private String title; + @NotNull(message = "시작 날짜가 업습니다.") private LocalDate startAt; + @NotNull(message = "종료 날짜가 업습니다.") private LocalDate endAt; private MultipartFile attachment; private MultipartFile image; diff --git a/src/main/java/com/sideProject/PlanIT/domain/product/controller/ProductAdminController.java b/src/main/java/com/sideProject/PlanIT/domain/product/controller/ProductAdminController.java index b1e04d3..055b30c 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/product/controller/ProductAdminController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/product/controller/ProductAdminController.java @@ -4,6 +4,7 @@ import com.sideProject.PlanIT.domain.product.dto.request.ProductRequestDto; import com.sideProject.PlanIT.domain.product.entity.Product; import com.sideProject.PlanIT.domain.product.service.ProductService; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; @@ -14,7 +15,7 @@ public class ProductAdminController { private final ProductService productService; @PostMapping - public ApiResponse createProduct(@RequestBody ProductRequestDto request) { + public ApiResponse createProduct(@Valid @RequestBody ProductRequestDto request) { return ApiResponse.ok(productService.createProduct(request)); } diff --git a/src/main/java/com/sideProject/PlanIT/domain/product/dto/request/ProductRequestDto.java b/src/main/java/com/sideProject/PlanIT/domain/product/dto/request/ProductRequestDto.java index 792a1a0..3f2a728 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/product/dto/request/ProductRequestDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/product/dto/request/ProductRequestDto.java @@ -2,6 +2,7 @@ import com.sideProject.PlanIT.domain.product.entity.enums.ProductSellingType; import com.sideProject.PlanIT.domain.product.entity.enums.ProductType; +import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -12,11 +13,15 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class ProductRequestDto { + @NotNull(message = "상품명이 없습니다.") private String name; private Period period; private int number; + @NotNull(message = "금액이 없습니다.") private int price; + @NotNull(message = "상품 타입이 없습니다.") private ProductType type; + @NotNull(message = "판매 상태가 없습니다.") private ProductSellingType sellingType; @Builder diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramAdminController.java b/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramAdminController.java index d1eb41c..254a628 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramAdminController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramAdminController.java @@ -8,6 +8,7 @@ import com.sideProject.PlanIT.domain.program.entity.enums.ProgramSearchStatus; import com.sideProject.PlanIT.domain.program.entity.enums.RegistrationSearchStatus; import com.sideProject.PlanIT.domain.program.service.ProgramService; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; @@ -82,7 +83,7 @@ public ApiResponse modify( } @PostMapping("/approve/{id}") - public ApiResponse approve(@PathVariable("id") Long id, @RequestBody ApproveRequestDto request) { + public ApiResponse approve(@PathVariable("id") Long id, @Valid @RequestBody ApproveRequestDto request) { LocalDateTime now = LocalDateTime.now(); return ApiResponse.ok( programService.approve(id, request.getTrainer(), now) diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramController.java b/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramController.java index c0233b0..db0ec2f 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramController.java @@ -7,6 +7,7 @@ import com.sideProject.PlanIT.domain.program.entity.enums.ProgramSearchStatus; import com.sideProject.PlanIT.domain.program.entity.enums.RegistrationSearchStatus; import com.sideProject.PlanIT.domain.program.service.ProgramService; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; @@ -27,7 +28,7 @@ public class ProgramController { private final ProgramService programService; @PostMapping("/registration") - public ApiResponse registration(@RequestBody RegistrationRequestDto request, Principal principal){ + public ApiResponse registration(@Valid @RequestBody RegistrationRequestDto request, Principal principal){ LocalDateTime now = LocalDateTime.now(); Long id = Long.parseLong(principal.getName()); return ApiResponse.ok(programService.registration(request, id, now)); @@ -48,8 +49,7 @@ public ApiResponse> find( public ApiResponse findById( @PathVariable("id") Long id, Principal principal) { - //todo : spring security 개발 후 토큰에서 userID를 전달해 줘야함. - Long userId = Long.parseLong(principal.getName()); + long userId = Long.parseLong(principal.getName()); return ApiResponse.ok( programService.findByProgramId(id, userId) ); @@ -60,7 +60,7 @@ public ApiResponse> findRegistration( @RequestParam(value = "option", required = false, defaultValue = "ALL") RegistrationSearchStatus option, @PageableDefault(size = 10, sort = "id", direction = Sort.Direction.DESC) Pageable pageable, Principal principal) { - Long id = Long.parseLong(principal.getName()); + long id = Long.parseLong(principal.getName()); return ApiResponse.ok( programService.findRegistrationsByUser(id,option, pageable) diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ApproveRequestDto.java b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ApproveRequestDto.java index 1fda05e..b92d71c 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ApproveRequestDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ApproveRequestDto.java @@ -1,14 +1,18 @@ package com.sideProject.PlanIT.domain.program.dto.request; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import static io.lettuce.core.pubsub.PubSubOutput.Type.message; + @Getter @NoArgsConstructor public class ApproveRequestDto { + @NotNull(message="트레이너 아이디가 없습니다.") Long trainer; - @Builder public ApproveRequestDto(Long trainer) { this.trainer = trainer; diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramModifyRequestDto.java b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramModifyRequestDto.java index 165fdc2..15aa955 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramModifyRequestDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramModifyRequestDto.java @@ -1,11 +1,14 @@ package com.sideProject.PlanIT.domain.program.dto.request; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; import lombok.Builder; import lombok.Getter; @Getter public class ProgramModifyRequestDto { + @NotNull String startTime; String endTime; Long memberId; diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramRegistraionDto.java b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramRegistraionDto.java deleted file mode 100644 index 001cc7e..0000000 --- a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramRegistraionDto.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.sideProject.PlanIT.domain.program.dto.request; -import com.sideProject.PlanIT.domain.product.entity.Product; -import com.sideProject.PlanIT.domain.user.entity.Member; -import com.sideProject.PlanIT.domain.program.entity.enums.RegistrationStatus; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.time.LocalDateTime; - -public class ProgramRegistraionDto { - @Getter - @AllArgsConstructor - public static class programRegistrationrequest { - - private LocalDateTime registrationAt; - private LocalDateTime paymentAt; - private LocalDateTime refundAt; - private RegistrationStatus status; - private int discount; - private int totalPrice; - private Member member; - private Product product; - - } -} diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/RegistrationRequestDto.java b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/RegistrationRequestDto.java index 11c170e..92df55f 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/RegistrationRequestDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/RegistrationRequestDto.java @@ -1,17 +1,21 @@ package com.sideProject.PlanIT.domain.program.dto.request; +import jakarta.validation.constraints.NotNull; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDate; @Getter -@NoArgsConstructor public class RegistrationRequestDto { + @NotNull(message = "상품 아이디가 없습니다") Long productId; - Long trainerId; + @NotNull(message = "등록 날짜가 없습니다") + @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate registrationAt; + Long trainerId; @Builder public RegistrationRequestDto(Long productId, Long trainerId, LocalDate registrationAt) { diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/programRegistrationRequestDto.java b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/programRegistrationRequestDto.java new file mode 100644 index 0000000..2429008 --- /dev/null +++ b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/programRegistrationRequestDto.java @@ -0,0 +1,23 @@ +package com.sideProject.PlanIT.domain.program.dto.request; +import com.sideProject.PlanIT.domain.product.entity.Product; +import com.sideProject.PlanIT.domain.user.entity.Member; +import com.sideProject.PlanIT.domain.program.entity.enums.RegistrationStatus; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +@AllArgsConstructor +public class programRegistrationRequestDto { + + private LocalDateTime registrationAt; + private LocalDateTime paymentAt; + private LocalDateTime refundAt; + private RegistrationStatus status; + private int discount; + private int totalPrice; + private Member member; + private Product product; + +} diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/FindRegistrationResponseDto.java b/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/FindRegistrationResponseDto.java index 5aac4ad..2cd85af 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/FindRegistrationResponseDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/FindRegistrationResponseDto.java @@ -3,6 +3,7 @@ import com.sideProject.PlanIT.domain.product.dto.response.ProductResponseDto; import com.sideProject.PlanIT.domain.program.entity.Registration; import com.sideProject.PlanIT.domain.program.entity.enums.RegistrationStatus; +import com.sideProject.PlanIT.domain.user.dto.member.response.EmployeeSemiResponseDto; import com.sideProject.PlanIT.domain.user.dto.member.response.MemberSemiResponseDto; import lombok.Builder; import lombok.Getter; @@ -19,10 +20,10 @@ public class FindRegistrationResponseDto { private int totalPrice; private ProductResponseDto product; private MemberSemiResponseDto member; - private Long trainerId; + private EmployeeSemiResponseDto trainer; @Builder - public FindRegistrationResponseDto(Long id, String registrationAt, String refundAt, RegistrationStatus status, int discount, int totalPrice, ProductResponseDto product, MemberSemiResponseDto member, Long trainerId) { + public FindRegistrationResponseDto(Long id, String registrationAt, String refundAt, RegistrationStatus status, int discount, int totalPrice, ProductResponseDto product, MemberSemiResponseDto member, EmployeeSemiResponseDto trainer) { this.id = id; this.registrationAt = registrationAt; this.refundAt = refundAt; @@ -31,7 +32,11 @@ public FindRegistrationResponseDto(Long id, String registrationAt, String refund this.totalPrice = totalPrice; this.product = product; this.member = member; - this.trainerId = trainerId; + this.trainer = trainer; + } + + public void setTrainer(EmployeeSemiResponseDto trainer) { + this.trainer = trainer; } public static FindRegistrationResponseDto of(Registration registration){ @@ -50,7 +55,7 @@ public static FindRegistrationResponseDto of(Registration registration){ .totalPrice(registration.getTotalPrice()) .product(ProductResponseDto.of(registration.getProduct())) .member(MemberSemiResponseDto.of(registration.getMember())) - .trainerId(registration.getTrainerId()) + .trainer(null) .build(); } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/entity/Registration.java b/src/main/java/com/sideProject/PlanIT/domain/program/entity/Registration.java index c416eed..17587a3 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/entity/Registration.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/entity/Registration.java @@ -48,7 +48,16 @@ public class Registration { private Product product; @Builder - public Registration(LocalDateTime registrationAt, LocalDateTime paymentAt, LocalDateTime refundAt, RegistrationStatus status, int discount, int totalPrice, Member member, Product product, Long trainerId) { + public Registration( + LocalDateTime registrationAt, + LocalDateTime paymentAt, + LocalDateTime refundAt, + RegistrationStatus status, + int discount, + int totalPrice, + Member member, + Product product, + Long trainerId) { this.registrationAt = registrationAt; this.paymentAt = paymentAt; this.refundAt = refundAt; diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/service/ProgramServiceImpl.java b/src/main/java/com/sideProject/PlanIT/domain/program/service/ProgramServiceImpl.java index ed9005c..9388195 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/service/ProgramServiceImpl.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/service/ProgramServiceImpl.java @@ -18,6 +18,7 @@ import com.sideProject.PlanIT.domain.program.repository.ProgramRepository; import com.sideProject.PlanIT.domain.program.repository.RegistrationRepository; import com.sideProject.PlanIT.domain.program.dto.request.ProgramModifyRequestDto; +import com.sideProject.PlanIT.domain.user.dto.member.response.EmployeeSemiResponseDto; import com.sideProject.PlanIT.domain.user.entity.enums.MemberRole; import com.sideProject.PlanIT.domain.user.entity.Employee; import com.sideProject.PlanIT.domain.user.repository.EmployeeRepository; @@ -36,6 +37,7 @@ import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.stream.Stream; /** @@ -419,7 +421,18 @@ private Page findAndConvertRegistrations(Registrati throw new CustomException("조건을 만족하는 Registration이 없습니다.", ErrorCode.REGISTRATION_NOT_FOUND); } - return registrations.map(FindRegistrationResponseDto::of); + return registrations.map(registration -> { + FindRegistrationResponseDto dto = FindRegistrationResponseDto.of(registration); + if (registration.getTrainerId() != null) { + Optional trainer = employeeRepository.findById(registration.getTrainerId()); + + trainer.ifPresent(employee -> dto.setTrainer(new EmployeeSemiResponseDto( + employee.getId(), + employee.getMember().getName()) + )); + } + return dto; + }); } //todo : 리팩토링 여부 생각, INVALID 조회 추가 diff --git a/src/main/java/com/sideProject/PlanIT/domain/reservation/controller/ReservationController.java b/src/main/java/com/sideProject/PlanIT/domain/reservation/controller/ReservationController.java index d7e282a..71a108c 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/reservation/controller/ReservationController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/reservation/controller/ReservationController.java @@ -6,6 +6,7 @@ import com.sideProject.PlanIT.domain.reservation.dto.reqeust.ReservationRequestDto; import com.sideProject.PlanIT.domain.reservation.dto.response.ReservationResponseDto; import com.sideProject.PlanIT.domain.reservation.service.ReservationService; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.format.annotation.DateTimeFormat; @@ -27,7 +28,7 @@ public class ReservationController { @PutMapping("/change") public ApiResponse changeAvailability( Principal principal, - @RequestBody ChangeReservationRequestDto request + @Valid @RequestBody ChangeReservationRequestDto request ) { return ApiResponse.ok( reservationService.changeAvailability( @@ -42,7 +43,7 @@ public ApiResponse changeAvailability( public ApiResponse reservation( Principal principal, @PathVariable("reservationId") Long reservationId, - @RequestBody ReservationRequestDto request + @Valid @RequestBody ReservationRequestDto request ) { LocalDateTime now = LocalDateTime.now(); return ApiResponse.ok( diff --git a/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ChangeReservationRequestDto.java b/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ChangeReservationRequestDto.java index 10ac689..c8913ae 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ChangeReservationRequestDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ChangeReservationRequestDto.java @@ -1,5 +1,7 @@ package com.sideProject.PlanIT.domain.reservation.dto.reqeust; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; import lombok.Getter; import org.springframework.format.annotation.DateTimeFormat; @@ -9,6 +11,7 @@ @Getter public class ChangeReservationRequestDto { + @NotNull(message = "예약 날짜가 주어지지 않았습니다.") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate reservationDate; diff --git a/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ReservationRequestDto.java b/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ReservationRequestDto.java index 10ef7b9..c9b45d7 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ReservationRequestDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ReservationRequestDto.java @@ -1,8 +1,11 @@ package com.sideProject.PlanIT.domain.reservation.dto.reqeust; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; import lombok.Getter; @Getter public class ReservationRequestDto { + @NotNull(message = "프로그램이 주어지지 않았습니다.") Long programId; } diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/controller/MemberController.java b/src/main/java/com/sideProject/PlanIT/domain/user/controller/MemberController.java index 41c3ca5..1101d4a 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/controller/MemberController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/controller/MemberController.java @@ -29,12 +29,12 @@ public class MemberController { private final AuthService authService; @PostMapping("/signup") - public ApiResponse signUp(@RequestBody MemberSignUpRequestDto request) { + public ApiResponse signUp(@Valid @RequestBody MemberSignUpRequestDto request) { return ApiResponse.ok(memberService.signUp(request).getId()); } @PostMapping("/email") - public ApiResponse mailSend(@RequestBody @Valid EmailSendReqeustDto request) { + public ApiResponse mailSend(@RequestBody @Valid EmailSendRequestDto request) { return ApiResponse.ok(emailService.joinEmail(request.getEmail())); } diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/request/EmailSendReqeustDto.java b/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/request/EmailSendRequestDto.java similarity index 74% rename from src/main/java/com/sideProject/PlanIT/domain/user/dto/member/request/EmailSendReqeustDto.java rename to src/main/java/com/sideProject/PlanIT/domain/user/dto/member/request/EmailSendRequestDto.java index f1f7370..4e29c47 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/request/EmailSendReqeustDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/request/EmailSendRequestDto.java @@ -1,13 +1,15 @@ package com.sideProject.PlanIT.domain.user.dto.member.request; import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotEmpty; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class EmailSendReqeustDto { +public class EmailSendRequestDto { @Email + @NotEmpty private String email; } diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/request/MemberEditRequestDto.java b/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/request/MemberEditRequestDto.java index 2955541..ed36f88 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/request/MemberEditRequestDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/request/MemberEditRequestDto.java @@ -4,6 +4,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDate; @@ -12,6 +13,7 @@ public class MemberEditRequestDto { private String name; private String phone_number; + @DateTimeFormat(pattern = "yyyy-MM-dd") private LocalDate birth; private String address; diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/request/MemberSignUpRequestDto.java b/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/request/MemberSignUpRequestDto.java index a044fbe..05fadba 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/request/MemberSignUpRequestDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/request/MemberSignUpRequestDto.java @@ -1,26 +1,45 @@ package com.sideProject.PlanIT.domain.user.dto.member.request; import com.sideProject.PlanIT.domain.user.entity.enums.Gender; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDate; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class MemberSignUpRequestDto { + @NotNull(message = "이메일이 없습니다.") private String email; + @NotNull(message = "비밀번호가 없습니다.") private String password; + @NotNull(message = "이름이 없습니다.") private String name; + @NotNull(message = "전화번호가 없습니다.") private String phone_number; + @DateTimeFormat(pattern = "yyyy-MM-dd") private LocalDate birth; + @NotNull(message = "주소가 없습니다.") private String address; + @NotNull(message = "성별이 없습니다.") private Gender gender; @Builder - public MemberSignUpRequestDto(String email, String password, String name, String phone_number, LocalDate birth, String address, Gender gender) { + public MemberSignUpRequestDto( + String email, + String password, + String name, + String phone_number, + LocalDate birth, + String address, + Gender gender + ) { this.email = email; this.password = password; this.name = name;