Skip to content

Commit

Permalink
Merge pull request #86 from YAPP-Github/feat/ISSUE-85
Browse files Browse the repository at this point in the history
add: onBoarding responseDto to post onBoarding API
  • Loading branch information
Seokyeong237 authored Feb 11, 2024
2 parents f308b7a + 9adc5bf commit 96e6a5a
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 11 deletions.
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;
}

0 comments on commit 96e6a5a

Please sign in to comment.