Skip to content

Commit

Permalink
Merge pull request #26 from Likelion-Inner-Join/feat/userSignUp
Browse files Browse the repository at this point in the history
Feat: 지원자 회원가입 구현
  • Loading branch information
BlueRedOrange authored Dec 20, 2024
2 parents 91232a7 + 86fd8f1 commit 01ca8c7
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
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<>("회원가입이 완료되었습니다."));
}
}
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;
}
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);
}
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);
}
}

0 comments on commit 01ca8c7

Please sign in to comment.