-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Likelion-Inner-Join/feat/userSignUp
Feat: 지원자 회원가입 구현
- Loading branch information
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/main/java/com/likelion/innerjoin/user/controller/ApplicantController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CommonResponse<String>> signUpApplicant(@RequestBody ApplicantSignUpRequestDto requestDto) { | ||
applicantService.signUpApplicant(requestDto); | ||
return ResponseEntity.status(HttpStatus.CREATED) | ||
.body(new CommonResponse<>("회원가입이 완료되었습니다.")); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/likelion/innerjoin/user/model/dto/request/ApplicantSignUpRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/likelion/innerjoin/user/repository/ApplicantRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, Long> { | ||
Applicant findByEmailAndPassword(String email, String password); | ||
Optional<Applicant> findByEmail(String email); | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/likelion/innerjoin/user/service/ApplicantService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |