Skip to content

Commit 35c0937

Browse files
authored
feat: Applicant 도메인 구현
* feat: Applicant (지원자) 도메인 초기 구현 - 지원자 엔티티 구현, 등록 요청 DTO 구현 - ApplicantStatus Enum으로 지원자 상태 관리 * feat: 제약조건 위반 예외 핸들러 메소드 추가 * feat: 지원자 상태 변경 메소드 추가
1 parent b1d5388 commit 35c0937

File tree

7 files changed

+188
-0
lines changed

7 files changed

+188
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package dmu.dasom.api.domain.applicant.dto;
2+
3+
import dmu.dasom.api.domain.applicant.entity.Applicant;
4+
import io.swagger.v3.oas.annotations.media.Schema;
5+
import jakarta.validation.constraints.*;
6+
import lombok.Getter;
7+
8+
@Getter
9+
@Schema(name = "ApplicantCreateRequestDto", description = "지원자 생성 요청 DTO")
10+
public class ApplicantCreateRequestDto {
11+
12+
@NotNull
13+
@Pattern(regexp = "^[0-9]{8}$")
14+
@Size(min = 8, max = 8)
15+
@Schema(description = "학번", example = "20231234")
16+
private String studentNo;
17+
18+
@NotNull
19+
@Pattern(regexp = "^\\d{3}-\\d{4}-\\d{4}$")
20+
@Size(min = 13, max = 13)
21+
@Schema(description = "연락처", example = "010-1234-5678")
22+
private String contact;
23+
24+
@Email
25+
@NotNull
26+
@Size(max = 64)
27+
@Schema(description = "이메일 주소", example = "[email protected]")
28+
private String email;
29+
30+
@Min(value = 1)
31+
@Max(value = 4)
32+
@NotNull
33+
@Schema(description = "학년", example = "3")
34+
private Integer grade;
35+
36+
@NotNull
37+
@Size(max = 500)
38+
@Schema(description = "지원 동기", example = "동아리 활동에 관심이 있어서 지원합니다.")
39+
private String reasonForApply;
40+
41+
@Size(max = 200)
42+
@Schema(description = "활동 희망사항", example = "동아리 활동 참여")
43+
private String activityWish;
44+
45+
@NotNull
46+
@Schema(description = "개인정보 처리방침 동의 여부", example = "true")
47+
private Boolean isPrivacyPolicyAgreed;
48+
49+
public Applicant toEntity() {
50+
return Applicant.builder()
51+
.studentNo(this.studentNo)
52+
.contact(this.contact)
53+
.email(this.email)
54+
.grade(this.grade)
55+
.reasonForApply(this.reasonForApply)
56+
.activityWish(this.activityWish)
57+
.isPrivacyPolicyAgreed(this.isPrivacyPolicyAgreed)
58+
.build();
59+
}
60+
61+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package dmu.dasom.api.domain.applicant.entity;
2+
3+
import dmu.dasom.api.domain.applicant.enums.ApplicantStatus;
4+
import jakarta.persistence.*;
5+
import jakarta.validation.constraints.*;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Builder;
8+
import lombok.Getter;
9+
import lombok.NoArgsConstructor;
10+
import org.springframework.data.annotation.CreatedDate;
11+
import org.springframework.data.annotation.LastModifiedDate;
12+
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
13+
14+
import java.time.LocalDateTime;
15+
16+
@AllArgsConstructor
17+
@Builder
18+
@Entity
19+
@EntityListeners(AuditingEntityListener.class)
20+
@Getter
21+
@NoArgsConstructor
22+
public class Applicant {
23+
24+
@Column(name = "id")
25+
@GeneratedValue(strategy = GenerationType.IDENTITY)
26+
@Id
27+
private Long id;
28+
29+
@Column(name = "student_no", nullable = false, length = 8)
30+
@Pattern(regexp = "^[0-9]{8}$")
31+
@Size(min = 8, max = 8)
32+
private String studentNo;
33+
34+
@Column(name = "contact", nullable = false, length = 13)
35+
@Pattern(regexp = "^\\d{3}-\\d{4}-\\d{4}$")
36+
@Size(min = 13, max = 13)
37+
private String contact;
38+
39+
@Column(name = "email", nullable = false, length = 64)
40+
@Email
41+
@Size(max = 64)
42+
private String email;
43+
44+
@Column(name = "grade", nullable = false)
45+
@Min(1) @Max(4)
46+
private int grade;
47+
48+
@Column(name = "reason_for_apply", nullable = false, length = 500)
49+
@Size(max = 500)
50+
private String reasonForApply;
51+
52+
@Column(name = "activity_wish", nullable = true, length = 200)
53+
@Size(max = 200)
54+
private String activityWish;
55+
56+
@Column(name = "is_privacy_policy_agreed", nullable = false)
57+
private Boolean isPrivacyPolicyAgreed;
58+
59+
@Builder.Default
60+
@Column(name = "status", nullable = false, length = 16)
61+
@Enumerated(EnumType.STRING)
62+
private ApplicantStatus status = ApplicantStatus.PENDING;
63+
64+
@CreatedDate
65+
@Column(name = "created_at", nullable = false, updatable = false)
66+
private LocalDateTime createdAt;
67+
68+
@Column(name = "updated_at", nullable = false)
69+
@LastModifiedDate
70+
private LocalDateTime updatedAt;
71+
72+
public void updateStatus(final ApplicantStatus status) {
73+
this.status = status;
74+
}
75+
76+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dmu.dasom.api.domain.applicant.enums;
2+
3+
public enum ApplicantStatus {
4+
PENDING, // 초기 상태
5+
DOCUMENT_FAILED, // 서류 심사 불합격
6+
DOCUMENT_PASSED, // 서류 심사 합격
7+
INTERVIEW_FAILED, // 면접 불합격
8+
INTERVIEW_PASSED // 면접 합격
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package dmu.dasom.api.domain.applicant.repository;
2+
3+
import dmu.dasom.api.domain.applicant.entity.Applicant;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
public interface ApplicantRepository extends JpaRepository<Applicant, Long> {
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dmu.dasom.api.domain.applicant.service;
2+
3+
import dmu.dasom.api.domain.applicant.dto.ApplicantCreateRequestDto;
4+
5+
public interface ApplicantService {
6+
7+
void apply(final ApplicantCreateRequestDto request);
8+
9+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package dmu.dasom.api.domain.applicant.service;
2+
3+
import dmu.dasom.api.domain.applicant.dto.ApplicantCreateRequestDto;
4+
import dmu.dasom.api.domain.applicant.repository.ApplicantRepository;
5+
import lombok.RequiredArgsConstructor;
6+
import org.springframework.stereotype.Service;
7+
8+
@RequiredArgsConstructor
9+
@Service
10+
public class ApplicantServiceImpl implements ApplicantService {
11+
12+
private final ApplicantRepository applicantRepository;
13+
14+
// 지원자 저장
15+
@Override
16+
public void apply(final ApplicantCreateRequestDto request) {
17+
applicantRepository.save(request.toEntity());
18+
}
19+
20+
}

src/main/java/dmu/dasom/api/domain/common/exception/CustomControllerAdvice.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dmu.dasom.api.domain.common.exception;
22

3+
import jakarta.validation.ConstraintViolationException;
34
import org.springframework.http.HttpStatus;
45
import org.springframework.http.ResponseEntity;
56
import org.springframework.web.bind.MethodArgumentNotValidException;
@@ -19,4 +20,9 @@ public ResponseEntity<ErrorResponse> methodArgumentNotValidException(final Metho
1920
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorResponse(ErrorCode.ARGUMENT_NOT_VALID));
2021
}
2122

23+
@ExceptionHandler(ConstraintViolationException.class)
24+
public ResponseEntity<ErrorResponse> constraintViolationException(final ConstraintViolationException e) {
25+
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorResponse(ErrorCode.ARGUMENT_NOT_VALID));
26+
}
27+
2228
}

0 commit comments

Comments
 (0)