Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: onBoarding responseDto to post onBoarding API #86

Merged
merged 2 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<Object> handleCustomException(CustomException e) {

return ApiResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/fullcar/member/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,9 +36,9 @@ public class MemberController {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "μ„œλ²„ λ‚΄λΆ€ 였λ₯˜", content = @Content)
})
@PostMapping("/onboarding")
public ApiResponse<Object> postOnboarding(@CurrentMember Member member, @RequestBody @Valid OnboardingRequestDto onboardingRequestDto) {
memberService.registerOnboarding(member, onboardingRequestDto);
return ApiResponse.success(SuccessCode.REGISTER_SUCCESS);
public ApiResponse<OnBoardingResponseDto> postOnBoarding(@CurrentMember Member member, @RequestBody @Valid OnBoardingRequestDto onboardingRequestDto) {
OnBoardingResponseDto responseDto = memberService.registerOnBoarding(member, onboardingRequestDto);
return ApiResponse.success(SuccessCode.REGISTER_SUCCESS, responseDto);
}

@Operation(summary = "νšŒμ› 정보 쑰회 API")
Expand All @@ -54,6 +55,7 @@ public ApiResponse<MemberGetResponseDto> 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")
Expand All @@ -65,6 +67,7 @@ public ApiResponse<Object> 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class OnboardingRequestDto {
public class OnBoardingRequestDto {

@Schema(description = "νšŒμ‚¬λͺ…", example = "ꡬ글 코리아")
@NotBlank
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]")
private String email;

@Schema(description = "λ‹‰λ„€μž„", example = "ν”Όκ³€ν•œ 물개")
private String nickname;

@Schema(description = "성별", example = "NONE")
private Gender gender;
}
Loading