diff --git a/src/main/java/com/scg/stop/auth/domain/request/RegisterRequest.java b/src/main/java/com/scg/stop/auth/domain/request/RegisterRequest.java index 55f80675..8684c83a 100644 --- a/src/main/java/com/scg/stop/auth/domain/request/RegisterRequest.java +++ b/src/main/java/com/scg/stop/auth/domain/request/RegisterRequest.java @@ -15,26 +15,31 @@ import lombok.NoArgsConstructor; @Getter +@NoArgsConstructor public class RegisterRequest { @NotBlank(message = "이름을 입력해주세요.") - private final String name; + private String name; @NotBlank(message = "전화번호를 입력해주세요.") - private final String phoneNumber; + private String phoneNumber; @NotNull(message = "회원 유형을 입력해주세요.") - private final UserType userType; + private UserType userType; @NotBlank(message = "이메일을 입력해주세요.") - private final String email; + private String email; - private final String signUpSource; + private String signUpSource; - private final StudentInfoDto studentInfo; + private StudentInfoDto studentInfo; + + private String division; + + private String position; public RegisterRequest(String name, String phoneNumber, UserType userType, String email, String signUpSource, - StudentInfoDto studentInfo) { + StudentInfoDto studentInfo, String division, String position) { validateStudentInfo(userType, studentInfo); this.name = name; this.phoneNumber = phoneNumber; @@ -42,6 +47,8 @@ public RegisterRequest(String name, String phoneNumber, UserType userType, Strin this.email = email; this.signUpSource = signUpSource; this.studentInfo = studentInfo; + if (division != null) this.division = division; + if (position != null) this.position = position; } private void validateStudentInfo(UserType userType, StudentInfoDto studentInfo) { diff --git a/src/main/java/com/scg/stop/auth/service/AuthService.java b/src/main/java/com/scg/stop/auth/service/AuthService.java index 1bd1b89a..aad17ff2 100644 --- a/src/main/java/com/scg/stop/auth/service/AuthService.java +++ b/src/main/java/com/scg/stop/auth/service/AuthService.java @@ -11,13 +11,16 @@ import com.scg.stop.global.exception.BadRequestException; import com.scg.stop.global.exception.ExceptionCode; import com.scg.stop.global.exception.InvalidJwtException; +import com.scg.stop.user.domain.Application; import com.scg.stop.user.domain.Department; import com.scg.stop.user.domain.Student; import com.scg.stop.user.domain.User; import com.scg.stop.user.domain.UserType; +import com.scg.stop.user.repository.ApplicationRepository; import com.scg.stop.user.repository.DepartmentRepository; import com.scg.stop.user.repository.StudentRepository; import com.scg.stop.user.repository.UserRepository; +import java.util.Arrays; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -30,6 +33,7 @@ public class AuthService { private final StudentRepository studentRepository; private final DepartmentRepository departmentRepository; private final UserRepository userRepository; + private final ApplicationRepository applicationRepository; private final JwtUtil jwtUtil; private final KakaoOAuthProvider kakaoOAuthProvider; @@ -52,24 +56,28 @@ private User findOrCreateUser(String socialLoginId) { } public RegisterResponse finishRegister(User user, RegisterRequest registerRequest) { - User foundUser = userRepository.findById(user.getId()) - .orElseThrow(() -> new BadRequestException(ExceptionCode.NOT_FOUND_USER_ID)); - if (foundUser.getUserType().equals(UserType.STUDENT)) { + if (user.getUserType().equals(UserType.STUDENT)) { Department department = departmentRepository.findByName( registerRequest.getStudentInfo().getDepartment()) - .orElseThrow(() -> new BadRequestException(ExceptionCode.NOT_FOUND_DEPARTMENT));//TODO: department가 null인경우 예외처리 + .orElseThrow(() -> new BadRequestException(ExceptionCode.NOT_FOUND_DEPARTMENT)); Student student = Student.of(registerRequest.getStudentInfo().getStudentNumber(), - foundUser + user , department); studentRepository.save(student); } - foundUser.register(registerRequest.getName(), + else if (Arrays.asList(UserType.INACTIVE_PROFESSOR, UserType.COMPANY, UserType.INACTIVE_COMPANY, UserType.PROFESSOR) + .contains(user.getUserType())) { + Application application = new Application(registerRequest.getDivision(), registerRequest.getPosition(), + user); + applicationRepository.save(application); + } + user.register(registerRequest.getName(), registerRequest.getEmail(), registerRequest.getPhoneNumber(), registerRequest.getUserType(), registerRequest.getSignUpSource()); - return RegisterResponse.from(foundUser); + return RegisterResponse.from(user); } private User createUser(String socialLoginId) { return userRepository.save(new User(socialLoginId)); diff --git a/src/main/java/com/scg/stop/user/domain/Application.java b/src/main/java/com/scg/stop/user/domain/Application.java index 503930b2..fc7c1b08 100644 --- a/src/main/java/com/scg/stop/user/domain/Application.java +++ b/src/main/java/com/scg/stop/user/domain/Application.java @@ -10,23 +10,31 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToOne; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @Entity @Getter @NoArgsConstructor(access = PROTECTED) +@AllArgsConstructor public class Application extends BaseTimeEntity { @Id @GeneratedValue(strategy = IDENTITY) private Long id; - private String division; + private String division; //소속 - private String position; + private String position; // 직책 @OneToOne(fetch = LAZY) @JoinColumn(name = "user_id") private User user; + + public Application(String division, String position, User user) { + this.division = division; + this.position = position; + this.user = user; + } } diff --git a/src/main/java/com/scg/stop/user/repository/ApplicationRepository.java b/src/main/java/com/scg/stop/user/repository/ApplicationRepository.java new file mode 100644 index 00000000..7db54d71 --- /dev/null +++ b/src/main/java/com/scg/stop/user/repository/ApplicationRepository.java @@ -0,0 +1,8 @@ +package com.scg.stop.user.repository; + +import com.scg.stop.user.domain.Application; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ApplicationRepository extends JpaRepository { + void findByName(); +}