From 268f810dc3d31f5509893d52d24b67d8c4528fd9 Mon Sep 17 00:00:00 2001 From: Seokyeong Date: Sun, 11 Feb 2024 22:08:04 +0900 Subject: [PATCH 1/2] add: onboarding responseDto --- .../exception/CustomExceptionHandler.java | 3 ++ .../application/member/MemberMapper.java | 16 +++++++-- .../application/member/MemberService.java | 9 +++-- .../fullcar/member/domain/member/Member.java | 3 +- .../presentation/member/MemberController.java | 11 ++++--- ...uestDto.java => OnBoardingRequestDto.java} | 2 +- .../dto/response/OnBoardingResponseDto.java | 33 +++++++++++++++++++ src/main/resources/private_key.p8 | 6 ++++ 8 files changed, 72 insertions(+), 11 deletions(-) rename src/main/java/com/fullcar/member/presentation/member/dto/request/{OnboardingRequestDto.java => OnBoardingRequestDto.java} (93%) create mode 100644 src/main/java/com/fullcar/member/presentation/member/dto/response/OnBoardingResponseDto.java create mode 100644 src/main/resources/private_key.p8 diff --git a/src/main/java/com/fullcar/core/exception/CustomExceptionHandler.java b/src/main/java/com/fullcar/core/exception/CustomExceptionHandler.java index ce36d54..94ff377 100644 --- a/src/main/java/com/fullcar/core/exception/CustomExceptionHandler.java +++ b/src/main/java/com/fullcar/core/exception/CustomExceptionHandler.java @@ -1,13 +1,16 @@ package com.fullcar.core.exception; import com.fullcar.core.response.ApiResponse; +import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; @RestControllerAdvice public class CustomExceptionHandler { @ExceptionHandler(CustomException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) public ApiResponse handleCustomException(CustomException e) { return ApiResponse.builder() diff --git a/src/main/java/com/fullcar/member/application/member/MemberMapper.java b/src/main/java/com/fullcar/member/application/member/MemberMapper.java index 2a9a216..38b3cc5 100644 --- a/src/main/java/com/fullcar/member/application/member/MemberMapper.java +++ b/src/main/java/com/fullcar/member/application/member/MemberMapper.java @@ -4,8 +4,9 @@ import com.fullcar.member.domain.member.Company; import com.fullcar.member.domain.member.service.MemberIdService; import com.fullcar.member.domain.member.Member; -import com.fullcar.member.presentation.member.dto.request.OnboardingRequestDto; +import com.fullcar.member.presentation.member.dto.request.OnBoardingRequestDto; import com.fullcar.member.presentation.member.dto.response.MemberGetResponseDto; +import com.fullcar.member.presentation.member.dto.response.OnBoardingResponseDto; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -26,7 +27,18 @@ public MemberGetResponseDto toDto(Member member) { .build(); } - public Member toEntity(OnboardingRequestDto onboardingRequestDto) { + public OnBoardingResponseDto toOnBoardingDto(Member member) { + return OnBoardingResponseDto.builder() + .nickname(member.getNickname()) + .companyName(member.getCompany().getCompanyName()) + .latitude(member.getCompany().getLatitude()) + .longitude(member.getCompany().getLongitude()) + .email(member.getEmail()) + .gender(member.getGender()) + .build(); + } + + public Member toEntity(OnBoardingRequestDto onboardingRequestDto) { return Member.builder() .company( Company.builder() diff --git a/src/main/java/com/fullcar/member/application/member/MemberService.java b/src/main/java/com/fullcar/member/application/member/MemberService.java index 02a19db..70c60b3 100644 --- a/src/main/java/com/fullcar/member/application/member/MemberService.java +++ b/src/main/java/com/fullcar/member/application/member/MemberService.java @@ -5,9 +5,10 @@ import com.fullcar.core.response.ErrorCode; import com.fullcar.member.domain.member.*; import com.fullcar.member.presentation.member.dto.request.NicknameRequestDto; -import com.fullcar.member.presentation.member.dto.request.OnboardingRequestDto; +import com.fullcar.member.presentation.member.dto.request.OnBoardingRequestDto; import com.fullcar.member.presentation.member.dto.response.MemberGetResponseDto; import com.fullcar.member.presentation.member.dto.response.NicknameResponseDto; +import com.fullcar.member.presentation.member.dto.response.OnBoardingResponseDto; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -33,8 +34,10 @@ public Member findByMemberId(MemberId memberId) { } @Transactional - public void registerOnboarding(Member member, OnboardingRequestDto onboardingRequestDto) { - findByMemberId(member.getId()).saveOnBoardingInfo(memberMapper.toEntity(onboardingRequestDto)); + public OnBoardingResponseDto registerOnBoarding(Member member, OnBoardingRequestDto onboardingRequestDto) { + Member updatedMember = findByMemberId(member.getId()).saveOnBoardingInfo(memberMapper.toEntity(onboardingRequestDto)); + memberRepository.saveAndFlush(updatedMember); + return memberMapper.toOnBoardingDto(member); } @Transactional(readOnly = true) diff --git a/src/main/java/com/fullcar/member/domain/member/Member.java b/src/main/java/com/fullcar/member/domain/member/Member.java index a7c648e..85cc747 100644 --- a/src/main/java/com/fullcar/member/domain/member/Member.java +++ b/src/main/java/com/fullcar/member/domain/member/Member.java @@ -74,11 +74,12 @@ public Member addCarInformation(CarId carId) { return this; } - public void saveOnBoardingInfo(Member member) { + public Member saveOnBoardingInfo(Member member) { this.email = member.getEmail(); this.nickname = member.getNickname(); this.gender = member.getGender(); this.company = new Company(member.getCompany().getCompanyName(), member.getCompany().getLatitude(), member.getCompany().getLongitude()); + return this; } public void clearRefreshTokenAndDeviceToken() { diff --git a/src/main/java/com/fullcar/member/presentation/member/MemberController.java b/src/main/java/com/fullcar/member/presentation/member/MemberController.java index a949d23..f0afca8 100644 --- a/src/main/java/com/fullcar/member/presentation/member/MemberController.java +++ b/src/main/java/com/fullcar/member/presentation/member/MemberController.java @@ -8,10 +8,11 @@ import com.fullcar.member.domain.member.service.MailService; import com.fullcar.member.presentation.member.dto.request.CodeRequestDto; import com.fullcar.member.presentation.member.dto.request.NicknameRequestDto; -import com.fullcar.member.presentation.member.dto.request.OnboardingRequestDto; +import com.fullcar.member.presentation.member.dto.request.OnBoardingRequestDto; import com.fullcar.member.presentation.member.dto.request.EmailRequestDto; import com.fullcar.member.presentation.member.dto.response.MemberGetResponseDto; import com.fullcar.member.presentation.member.dto.response.NicknameResponseDto; +import com.fullcar.member.presentation.member.dto.response.OnBoardingResponseDto; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.responses.ApiResponses; @@ -35,9 +36,9 @@ public class MemberController { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content) }) @PostMapping("/onboarding") - public ApiResponse postOnboarding(@CurrentMember Member member, @RequestBody @Valid OnboardingRequestDto onboardingRequestDto) { - memberService.registerOnboarding(member, onboardingRequestDto); - return ApiResponse.success(SuccessCode.REGISTER_SUCCESS); + public ApiResponse postOnBoarding(@CurrentMember Member member, @RequestBody @Valid OnBoardingRequestDto onboardingRequestDto) { + OnBoardingResponseDto responseDto = memberService.registerOnBoarding(member, onboardingRequestDto); + return ApiResponse.success(SuccessCode.REGISTER_SUCCESS, responseDto); } @Operation(summary = "회원 정보 조회 API") @@ -54,6 +55,7 @@ public ApiResponse getMember(@CurrentMember Member member) @Operation(summary = "회사 메일 인증 API") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "인증메일 발송 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "블랙리스트에 있는 이메일 주소입니다.", content = @Content), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content) }) @PostMapping("/onboarding/company/email") @@ -65,6 +67,7 @@ public ApiResponse sendAuthenticationMail(@CurrentMember Member member, @Operation(summary = "닉네임 중복 검사 API") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "사용 가능한 닉네임"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "중복된 닉네임 입니다.", content = @Content), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content) }) @PostMapping("/onboarding/nickname") diff --git a/src/main/java/com/fullcar/member/presentation/member/dto/request/OnboardingRequestDto.java b/src/main/java/com/fullcar/member/presentation/member/dto/request/OnBoardingRequestDto.java similarity index 93% rename from src/main/java/com/fullcar/member/presentation/member/dto/request/OnboardingRequestDto.java rename to src/main/java/com/fullcar/member/presentation/member/dto/request/OnBoardingRequestDto.java index 7f1ba0f..62a4836 100644 --- a/src/main/java/com/fullcar/member/presentation/member/dto/request/OnboardingRequestDto.java +++ b/src/main/java/com/fullcar/member/presentation/member/dto/request/OnBoardingRequestDto.java @@ -11,7 +11,7 @@ @Builder @AllArgsConstructor(access = AccessLevel.PROTECTED) @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class OnboardingRequestDto { +public class OnBoardingRequestDto { @Schema(description = "회사명", example = "구글 코리아") @NotBlank diff --git a/src/main/java/com/fullcar/member/presentation/member/dto/response/OnBoardingResponseDto.java b/src/main/java/com/fullcar/member/presentation/member/dto/response/OnBoardingResponseDto.java new file mode 100644 index 0000000..e62c80a --- /dev/null +++ b/src/main/java/com/fullcar/member/presentation/member/dto/response/OnBoardingResponseDto.java @@ -0,0 +1,33 @@ +package com.fullcar.member.presentation.member.dto.response; + +import com.fullcar.member.domain.member.Gender; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import java.math.BigDecimal; + +@Getter +@Builder +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Schema(description = "온보딩 정보 응답 모델") +public class OnBoardingResponseDto { + + @Schema(description = "회사명", example = "구글 코리아") + private String companyName; + + @Schema(description = "위도", example = "46.652719") + private BigDecimal latitude; + + @Schema(description = "경도", example = "71.530045") + private BigDecimal longitude; + + @Schema(description = "회사 이메일", example = "whoareyou@yanolja.com") + private String email; + + @Schema(description = "닉네임", example = "피곤한 물개") + private String nickname; + + @Schema(description = "성별", example = "NONE") + private Gender gender; +} diff --git a/src/main/resources/private_key.p8 b/src/main/resources/private_key.p8 new file mode 100644 index 0000000..734e2e7 --- /dev/null +++ b/src/main/resources/private_key.p8 @@ -0,0 +1,6 @@ +-----BEGIN PRIVATE KEY----- +MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgDPHUwtX6Ep4I+p8F +ZnTqCnYEIeg6x9LUjMKLI6xcE5CgCgYIKoZIzj0DAQehRANCAATSbA86t9C09Vps +VqTP3vegKo2jRRPfTFJFCVPKdl8G4y5EWV6S9YTzmpzqFZLh7S54y+LJxMIDKvHR +ntb7Dl1Y +-----END PRIVATE KEY----- \ No newline at end of file From 9adc5bfae3bc93fb754ac97104b14b871b24e7d4 Mon Sep 17 00:00:00 2001 From: Seo-Kyeong Hwang Date: Sun, 11 Feb 2024 22:19:46 +0900 Subject: [PATCH 2/2] Delete src/main/resources/private_key.p8 --- src/main/resources/private_key.p8 | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 src/main/resources/private_key.p8 diff --git a/src/main/resources/private_key.p8 b/src/main/resources/private_key.p8 deleted file mode 100644 index 734e2e7..0000000 --- a/src/main/resources/private_key.p8 +++ /dev/null @@ -1,6 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgDPHUwtX6Ep4I+p8F -ZnTqCnYEIeg6x9LUjMKLI6xcE5CgCgYIKoZIzj0DAQehRANCAATSbA86t9C09Vps -VqTP3vegKo2jRRPfTFJFCVPKdl8G4y5EWV6S9YTzmpzqFZLh7S54y+LJxMIDKvHR -ntb7Dl1Y ------END PRIVATE KEY----- \ No newline at end of file