From 8273cffbd858f09f0ad6fcaee5f8dec3eb055e05 Mon Sep 17 00:00:00 2001 From: Seokyeong Date: Mon, 5 Feb 2024 03:49:33 +0900 Subject: [PATCH] feat: onboarding API --- .../application/member/CompanyMapper.java | 19 ------------------- .../application/member/MemberMapper.java | 17 +++++++++++++++++ .../application/member/MemberService.java | 8 +++----- .../fullcar/member/domain/member/Member.java | 8 ++++++-- .../presentation/member/MemberController.java | 10 +++++----- ...uestDto.java => OnboardingRequestDto.java} | 15 +++++++++++++-- 6 files changed, 44 insertions(+), 33 deletions(-) delete mode 100644 src/main/java/com/fullcar/member/application/member/CompanyMapper.java rename src/main/java/com/fullcar/member/presentation/member/dto/request/{CompanyRequestDto.java => OnboardingRequestDto.java} (54%) diff --git a/src/main/java/com/fullcar/member/application/member/CompanyMapper.java b/src/main/java/com/fullcar/member/application/member/CompanyMapper.java deleted file mode 100644 index 6bda4d3..0000000 --- a/src/main/java/com/fullcar/member/application/member/CompanyMapper.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.fullcar.member.application.member; - -import com.fullcar.member.domain.member.Company; -import com.fullcar.member.presentation.member.dto.request.CompanyRequestDto; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; - -@Component -@RequiredArgsConstructor(access = AccessLevel.PROTECTED) -public class CompanyMapper { - public Company toEntity(CompanyRequestDto companyRequestDto) { - return Company.builder() - .companyName(companyRequestDto.getCompanyName()) - .latitude(companyRequestDto.getLatitude()) - .longitude(companyRequestDto.getLongitude()) - .build(); - } -} 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 497c778..0e66375 100644 --- a/src/main/java/com/fullcar/member/application/member/MemberMapper.java +++ b/src/main/java/com/fullcar/member/application/member/MemberMapper.java @@ -1,8 +1,10 @@ package com.fullcar.member.application.member; +import com.fullcar.member.domain.member.Company; import com.fullcar.member.infra.EmailMessage; import com.fullcar.member.domain.member.Member; import com.fullcar.member.presentation.member.dto.request.EmailRequestDto; +import com.fullcar.member.presentation.member.dto.request.OnboardingRequestDto; import com.fullcar.member.presentation.member.dto.response.MemberGetResponseDto; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; @@ -28,4 +30,19 @@ public EmailMessage toEntity(EmailRequestDto emailRequestDto) { .subject("[FullCar] 회사 이메일 인증") .build(); } + + public Member toEntity(OnboardingRequestDto onboardingRequestDto) { + return Member.builder() + .company( + Company.builder() + .companyName(onboardingRequestDto.getCompanyName()) + .latitude(onboardingRequestDto.getLatitude()) + .longitude(onboardingRequestDto.getLongitude()) + .build() + ) + .email(onboardingRequestDto.getEmail()) + .nickname(onboardingRequestDto.getNickname()) + .gender(onboardingRequestDto.getGender()) + .build(); + } } 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 764bd42..d8b39bf 100644 --- a/src/main/java/com/fullcar/member/application/member/MemberService.java +++ b/src/main/java/com/fullcar/member/application/member/MemberService.java @@ -3,7 +3,7 @@ import com.fullcar.core.exception.NotFoundException; import com.fullcar.core.response.ErrorCode; import com.fullcar.member.domain.member.*; -import com.fullcar.member.presentation.member.dto.request.CompanyRequestDto; +import com.fullcar.member.presentation.member.dto.request.OnboardingRequestDto; import com.fullcar.member.presentation.member.dto.response.MemberGetResponseDto; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -15,7 +15,6 @@ @RequiredArgsConstructor public class MemberService { private final MemberRepository memberRepository; - private final CompanyMapper companyMapper; private final MemberMapper memberMapper; /** @@ -31,9 +30,8 @@ public Member findByMemberId(MemberId memberId) { } @Transactional - public void registerCompany(Member member, CompanyRequestDto companyRequestDto) { - Company company = companyMapper.toEntity(companyRequestDto); - findByMemberId(member.getId()).updateCompany(company); + public void registerOnboarding(Member member, OnboardingRequestDto onboardingRequestDto) { + findByMemberId(member.getId()).saveOnBoardingInfo(memberMapper.toEntity(onboardingRequestDto)); } @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 74e7fa2..cd28bcc 100644 --- a/src/main/java/com/fullcar/member/domain/member/Member.java +++ b/src/main/java/com/fullcar/member/domain/member/Member.java @@ -43,6 +43,7 @@ public class Member { private String email; + @Enumerated(EnumType.STRING) private Gender gender; @Builder.Default @@ -76,7 +77,10 @@ public void updateCarInformation(CarId carId) { this.carId = carId; } - public void updateCompany(Company company) { - this.company = new Company(company.getCompanyName(), company.getLatitude(), company.getLongitude()); + public void 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()); } } 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 5163892..0b3d629 100644 --- a/src/main/java/com/fullcar/member/presentation/member/MemberController.java +++ b/src/main/java/com/fullcar/member/presentation/member/MemberController.java @@ -6,7 +6,7 @@ import com.fullcar.member.application.member.MemberService; import com.fullcar.member.domain.member.Member; import com.fullcar.member.domain.member.service.MailService; -import com.fullcar.member.presentation.member.dto.request.CompanyRequestDto; +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 io.swagger.v3.oas.annotations.Operation; @@ -26,14 +26,14 @@ public class MemberController { private final MemberService memberService; private final MailService mailService; - @Operation(summary = "회사 선택 API") + @Operation(summary = "온보딩 API") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "201", description = "등록 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content) }) - @PostMapping("/onboarding/company") - public ApiResponse postCompany(@CurrentMember Member member, @RequestBody @Valid CompanyRequestDto companyRequestDto) { - memberService.registerCompany(member, companyRequestDto); + @PostMapping("/onboarding") + public ApiResponse postOnboarding(@CurrentMember Member member, @RequestBody @Valid OnboardingRequestDto onboardingRequestDto) { + memberService.registerOnboarding(member, onboardingRequestDto); return ApiResponse.success(SuccessCode.REGISTER_SUCCESS); } diff --git a/src/main/java/com/fullcar/member/presentation/member/dto/request/CompanyRequestDto.java b/src/main/java/com/fullcar/member/presentation/member/dto/request/OnboardingRequestDto.java similarity index 54% rename from src/main/java/com/fullcar/member/presentation/member/dto/request/CompanyRequestDto.java rename to src/main/java/com/fullcar/member/presentation/member/dto/request/OnboardingRequestDto.java index 3a66c67..7f1ba0f 100644 --- a/src/main/java/com/fullcar/member/presentation/member/dto/request/CompanyRequestDto.java +++ b/src/main/java/com/fullcar/member/presentation/member/dto/request/OnboardingRequestDto.java @@ -1,5 +1,6 @@ package com.fullcar.member.presentation.member.dto.request; +import com.fullcar.member.domain.member.Gender; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import lombok.*; @@ -10,8 +11,9 @@ @Builder @AllArgsConstructor(access = AccessLevel.PROTECTED) @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class CompanyRequestDto { - @Schema(description = "회사 이름", example = "네이버") +public class OnboardingRequestDto { + + @Schema(description = "회사명", example = "구글 코리아") @NotBlank private String companyName; @@ -20,4 +22,13 @@ public class CompanyRequestDto { @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; }