Skip to content

Commit

Permalink
feat: 편의를 위해 Role 별로 가입 api 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
dgjinsu committed Dec 1, 2023
1 parent f3ba69e commit fc9e2fc
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@
public class MemberController {
private final MemberService memberService;

@Operation(summary = "회원 가입 요청")
@PostMapping("/join")
public ResponseEntity<Response> joinMember(@RequestBody JoinRequest request) {
Long savedMemberId = memberService.joinMember(request);
return ResponseEntity.ok(new Response("회원 가입 완료"));
@Operation(summary = "회원 가입: 노동자")
@PostMapping("/join-worker")
public ResponseEntity<Response> joinWorkerMember(@RequestBody JoinWorkerRequest request) {
Long savedMemberId = memberService.joinWorkerMember(request);
return ResponseEntity.ok(new Response("노동자 회원 가입 완료"));
}

@Operation(summary = "회원 가입: 아이디 중복 체크")
@Operation(summary = "회원 가입: 기업")
@PostMapping("/join-company")
public ResponseEntity<Response> joinCompanyMember(@RequestBody JoinCompanyRequest request) {
Long savedMemberId = memberService.joinCompanyMember(request);
return ResponseEntity.ok(new Response("기업 회원 가입 완료"));
}

@Operation(summary = "회원 가입: 휴대폰 중복 체크")
@PostMapping("/validation-phone")
public ResponseEntity<Response> validationPhone(@RequestBody ValidationUsernameRequest request) {
memberService.validationPhone(request.getPhone());
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/jikgong/domain/member/dtos/JoinCompanyRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package jikgong.domain.member.dtos;

import io.swagger.v3.oas.annotations.media.Schema;
import jikgong.domain.member.entity.Role;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Getter
public class JoinCompanyRequest {
// 공통 정보
@Schema(description = "휴대폰 번호", example = "01012345678")
private String phone;
@Schema(description = "인증 코드 6자리", example = "")
private String authCode; // 인증 코드
@Schema(description = "회원 타입 [ROLE_WORKER or ROLE_COMPANY]", example = "ROLE_COMPANY")
private Role role; // 회원 타입
@Schema(description = "계좌 번호", example = "12341234123412")
private String account; // 게좌 번호
@Schema(description = "은행 종류", example = "국민은행")
private String bank; // 은행

// 회사 정보
@Schema(description = "사업자 번호", example = "00000000")
private String businessNumber; // 사업자 번호
@Schema(description = "지역", example = "서울")
private String region; // 지역
@Schema(description = "회사 명", example = "삼성")
private String companyName; // 회사 명
@Schema(description = "이메일", example = "[email protected]")
private String email; // 이메일
@Schema(description = "담당자 이름", example = "이재용")
private String manager; // 담당자 이름
@Schema(description = "문의 내용", example = "직공 서비스에 가입하고 싶습니다.")
private String requestContent; // 문의 내용
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

@NoArgsConstructor
@Getter
public class JoinRequest {
public class JoinWorkerRequest {
// 공통 정보
@Schema(description = "휴대폰 번호", example = "01012345678")
private String phone;
@Schema(description = "인증 코드 6자리", example = "")
Expand All @@ -20,28 +21,6 @@ public class JoinRequest {
@Schema(description = "은행 종류", example = "국민은행")
private String bank; // 은행

// 위치 정보
@Schema(description = "도로명 주소", example = "부산광역시 사하구 낙동대로 550번길 37")
private String address; // 도로명 주소
@Schema(description = "위도", example = "35.116777388697734")
private Float latitude; // 위도
@Schema(description = "경도", example = "128.9685393114043")
private Float longitude; // 경도

// 회사 정보
@Schema(description = "사업자 번호", example = "00000000")
private String businessNumber; // 사업자 번호
@Schema(description = "지역", example = "서울")
private String region; // 지역
@Schema(description = "회사 명", example = "삼성")
private String companyName; // 회사 명
@Schema(description = "이메일", example = "[email protected]")
private String email; // 이메일
@Schema(description = "담당자 이름", example = "이재용")
private String manager; // 담당자 이름
@Schema(description = "문의 내용", example = "직공 서비스에 가입하고 싶습니다.")
private String requestContent; // 문의 내용

// 노동자 정보
@Schema(description = "노동자 이름", example = "홍길동")
private String workerName; // 노동자 이름
Expand All @@ -51,4 +30,12 @@ public class JoinRequest {
private Gender gender; // 성별
@Schema(description = "국적", example = "대한민국")
private String nationality; // 국적

// 위치 정보
@Schema(description = "도로명 주소", example = "부산광역시 사하구 낙동대로 550번길 37")
private String address; // 도로명 주소
@Schema(description = "위도", example = "35.116777388697734")
private Float latitude; // 위도
@Schema(description = "경도", example = "128.9685393114043")
private Float longitude; // 경도
}
2 changes: 0 additions & 2 deletions src/main/java/jikgong/domain/member/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import jakarta.persistence.*;
import jikgong.domain.certification.entity.Certification;
import jikgong.domain.common.BaseEntity;
import jikgong.domain.member.dtos.JoinRequest;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.jdbc.Work;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down
52 changes: 31 additions & 21 deletions src/main/java/jikgong/domain/member/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,16 @@ public class MemberService {
private final LocationRepository locationRepository;
private final PasswordEncoder encoder;

public Long joinMember(JoinRequest request) {
public Long joinWorkerMember(JoinWorkerRequest request) {
validationPhone(request.getPhone());

Worker worker = null;
Company company = null;

// 노동자 회원 가입
if (request.getRole() == Role.ROLE_WORKER) {
worker = Worker.builder()
// 노동자 정보
Worker worker = Worker.builder()
.workerName(request.getWorkerName())
.rrnPrefix(request.getRrnPrefix())
.gender(request.getGender())
.nationality(request.getNationality())
.build();
}
// 회사 회원 가입
if (request.getRole() == Role.ROLE_COMPANY) {
company = Company.builder()
.businessNumber(request.getBusinessNumber())
.region(request.getRegion())
.companyName(request.getCompanyName())
.email(request.getEmail())
.manager(request.getManager())
.requestContent(request.getRequestContent())
.build();
}
// 공통 부분
Member member = Member.builder()
.phone(request.getPhone())
Expand All @@ -62,7 +46,6 @@ public Long joinMember(JoinRequest request) {
.bank(request.getBank())
.role(request.getRole())
.worker(worker)
.company(company)
.build();

Location location = Location.builder()
Expand All @@ -75,10 +58,37 @@ public Long joinMember(JoinRequest request) {

Member savedMember = memberRepository.save(member); // 회원 저장
locationRepository.save(location); // 위치 정보 저장
log.info("[" + request.getPhone() + "] 회원 가입 완료");
log.info("노동자 회원 가입 완료");
return savedMember.getId();
}

public Long joinCompanyMember(JoinCompanyRequest request) {
validationPhone(request.getPhone());

// 기업 정보
Company company = Company.builder()
.businessNumber(request.getBusinessNumber())
.region(request.getRegion())
.companyName(request.getCompanyName())
.email(request.getEmail())
.manager(request.getManager())
.requestContent(request.getRequestContent())
.build();

// 공통 부분
Member member = Member.builder()
.phone(request.getPhone())
.authCode(encoder.encode(request.getAuthCode()))
.account(request.getAccount())
.bank(request.getBank())
.role(request.getRole())
.company(company)
.build();

log.info("기업 회원 가입 완료");
return memberRepository.save(member).getId(); // 회원 저장
}

public void validationPhone(String phone) {
Optional<Member> member = memberRepository.findByPhone(phone);
if (member.isPresent()) {
Expand Down

0 comments on commit fc9e2fc

Please sign in to comment.