From 86fd8f12ed9d40500c99a0d422dfb96870fcbac3 Mon Sep 17 00:00:00 2001 From: BlueRedOrange Date: Sat, 21 Dec 2024 08:37:10 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=EC=A7=80=EC=9B=90=EC=9E=90=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=EA=B0=80=EC=9E=85=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/ApplicantController.java | 32 +++++++++++++ .../request/ApplicantSignUpRequestDto.java | 14 ++++++ .../user/repository/ApplicantRepository.java | 4 ++ .../user/service/ApplicantService.java | 48 +++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 src/main/java/com/likelion/innerjoin/user/controller/ApplicantController.java create mode 100644 src/main/java/com/likelion/innerjoin/user/model/dto/request/ApplicantSignUpRequestDto.java create mode 100644 src/main/java/com/likelion/innerjoin/user/service/ApplicantService.java diff --git a/src/main/java/com/likelion/innerjoin/user/controller/ApplicantController.java b/src/main/java/com/likelion/innerjoin/user/controller/ApplicantController.java new file mode 100644 index 0000000..a9478d2 --- /dev/null +++ b/src/main/java/com/likelion/innerjoin/user/controller/ApplicantController.java @@ -0,0 +1,32 @@ +package com.likelion.innerjoin.user.controller; + +import com.likelion.innerjoin.common.response.CommonResponse; +import com.likelion.innerjoin.user.model.dto.request.ApplicantSignUpRequestDto; +import com.likelion.innerjoin.user.service.ApplicantService; +import io.swagger.v3.oas.annotations.Operation; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/user") +@RequiredArgsConstructor +public class ApplicantController { + + private final ApplicantService applicantService; + + /** + * 지원자 회원가입 + * + * @param requestDto 지원자 회원가입 요청 DTO + * @return CommonResponse + */ + @Operation(summary = "지원자 회원가입 API", description = "지원자 회원가입") + @PostMapping("/signup") + public ResponseEntity> signUpApplicant(@RequestBody ApplicantSignUpRequestDto requestDto) { + applicantService.signUpApplicant(requestDto); + return ResponseEntity.status(HttpStatus.CREATED) + .body(new CommonResponse<>("회원가입이 완료되었습니다.")); + } +} diff --git a/src/main/java/com/likelion/innerjoin/user/model/dto/request/ApplicantSignUpRequestDto.java b/src/main/java/com/likelion/innerjoin/user/model/dto/request/ApplicantSignUpRequestDto.java new file mode 100644 index 0000000..d68146a --- /dev/null +++ b/src/main/java/com/likelion/innerjoin/user/model/dto/request/ApplicantSignUpRequestDto.java @@ -0,0 +1,14 @@ +package com.likelion.innerjoin.user.model.dto.request; + +import lombok.Data; + +@Data +public class ApplicantSignUpRequestDto { + private String email; + private String password; + private String name; + private String school; + private String major; + private String studentNumber; + private String phoneNum; +} diff --git a/src/main/java/com/likelion/innerjoin/user/repository/ApplicantRepository.java b/src/main/java/com/likelion/innerjoin/user/repository/ApplicantRepository.java index 617759b..668a20a 100644 --- a/src/main/java/com/likelion/innerjoin/user/repository/ApplicantRepository.java +++ b/src/main/java/com/likelion/innerjoin/user/repository/ApplicantRepository.java @@ -1,8 +1,12 @@ package com.likelion.innerjoin.user.repository; import com.likelion.innerjoin.user.model.entity.Applicant; +import com.likelion.innerjoin.user.model.entity.Club; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface ApplicantRepository extends JpaRepository { Applicant findByEmailAndPassword(String email, String password); + Optional findByEmail(String email); } diff --git a/src/main/java/com/likelion/innerjoin/user/service/ApplicantService.java b/src/main/java/com/likelion/innerjoin/user/service/ApplicantService.java new file mode 100644 index 0000000..1221b3f --- /dev/null +++ b/src/main/java/com/likelion/innerjoin/user/service/ApplicantService.java @@ -0,0 +1,48 @@ +package com.likelion.innerjoin.user.service; + +import com.likelion.innerjoin.common.response.CommonResponse; +import com.likelion.innerjoin.user.exception.EmailValidationException; +import com.likelion.innerjoin.user.exception.SignUpIDException; +import com.likelion.innerjoin.user.model.dto.request.ApplicantSignUpRequestDto; +import com.likelion.innerjoin.user.model.entity.Applicant; +import com.likelion.innerjoin.user.repository.ApplicantRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class ApplicantService { + + private final ApplicantRepository applicantRepository; + + /** + * 지원자 회원가입 + * + * @param requestDto 지원자 회원가입 요청 DTO + */ + @Transactional + public void signUpApplicant(ApplicantSignUpRequestDto requestDto) { + String email = requestDto.getEmail(); + // 이메일 입력 형식 체크 + if (email == null || !email.matches("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$")) { + throw new EmailValidationException("이메일 형식이 잘못되었습니다."); + } + // 이메일 중복 체크 + if (applicantRepository.findByEmail(requestDto.getEmail()).isPresent()) { + throw new EmailValidationException("이미 존재하는 이메일입니다."); + } + // Applicant 엔티티 생성 및 저장 + Applicant applicant = Applicant.builder() + .email(requestDto.getEmail()) + .password(requestDto.getPassword()) + .name(requestDto.getName()) + .school(requestDto.getSchool()) + .major(requestDto.getMajor()) + .studentNumber(requestDto.getStudentNumber()) + .phoneNum(requestDto.getPhoneNum()) + .build(); + + applicantRepository.save(applicant); + } +} \ No newline at end of file