-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 교육 사항 등록 기능 구현 #37
Changes from 4 commits
2f6654c
0d44fed
d5f9d46
e7aa500
4316bc1
95c75ec
a2468a8
5c61b6f
0cd0064
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,17 +7,23 @@ | |
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.Lob; | ||
import jakarta.persistence.ManyToOne; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.devcourse.resumeme.common.domain.BaseEntity; | ||
import org.devcourse.resumeme.common.domain.Position; | ||
import org.devcourse.resumeme.domain.user.User; | ||
import org.devcourse.resumeme.global.advice.exception.CustomException; | ||
import org.devcourse.resumeme.global.advice.exception.ExceptionCode; | ||
|
||
import static org.devcourse.resumeme.common.util.Validator.validate; | ||
|
||
@Entity | ||
@NoArgsConstructor | ||
public class Resume { | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Resume extends BaseEntity { | ||
|
||
@Id | ||
@Getter | ||
|
@@ -27,19 +33,18 @@ public class Resume { | |
|
||
private String title; | ||
|
||
private boolean isWriting; | ||
|
||
private boolean isRepresentative; | ||
|
||
private Long userId; | ||
@ManyToOne | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private Position position; | ||
|
||
@Lob | ||
private String introduce; | ||
|
||
@Embedded | ||
@ManyToOne | ||
@JoinColumn(name = "training_id") | ||
private Training training; | ||
|
||
@Embedded | ||
|
@@ -56,46 +61,24 @@ public class Resume { | |
|
||
private String phoneNumber; | ||
|
||
public Resume(String title, String introduce) { | ||
validateInput(title, introduce); | ||
|
||
public Resume(String title, User user, Training training) { | ||
validateResume(title, user); | ||
this.title = title; | ||
this.introduce = introduce; | ||
this.user = user; | ||
this.training = training; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. training에 대한 null체크는 없는건가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
private void validateInput(String title, String introduce) { | ||
private static void validateResume(String title, User user) { | ||
validate(title == null, ExceptionCode.NO_EMPTY_VALUE); | ||
validate(introduce == null, ExceptionCode.NO_EMPTY_VALUE); | ||
validate(user == null, ExceptionCode.MENTEE_NOT_FOUND); | ||
if (!user.isMentee()) { | ||
throw new CustomException(ExceptionCode.MENTEE_ONLY_RESUME); | ||
} | ||
} | ||
|
||
public Resume(String title, boolean isWriting, boolean isRepresentative, Long userId, Position position, | ||
String introduce, Training training, Career career, Project project, String email, | ||
String githubAddress, String blogAddress, String phoneNumber) { | ||
public Resume(String title, String introduce) { | ||
this.title = title; | ||
this.isWriting = isWriting; | ||
this.isRepresentative = isRepresentative; | ||
this.userId = userId; | ||
this.position = position; | ||
this.introduce = introduce; | ||
this.training = training; | ||
this.career = career; | ||
this.project = project; | ||
this.email = email; | ||
this.githubAddress = githubAddress; | ||
this.blogAddress = blogAddress; | ||
this.phoneNumber = phoneNumber; | ||
} | ||
|
||
public void writing() { | ||
this.isWriting = true; | ||
} | ||
|
||
public void fininsh() { | ||
this.isWriting = false; | ||
} | ||
|
||
public void decideRepresentative() { | ||
this.isRepresentative = true; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,74 @@ | ||
package org.devcourse.resumeme.domain.resume; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.devcourse.resumeme.global.advice.exception.CustomException; | ||
import org.devcourse.resumeme.global.advice.exception.ExceptionCode; | ||
|
||
import static org.devcourse.resumeme.common.util.Validator.validate; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Embeddable | ||
@NoArgsConstructor | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Training { | ||
|
||
private String trainingName; | ||
@Id | ||
@Getter | ||
@GeneratedValue | ||
@Column(name = "training_id") | ||
private Long id; | ||
|
||
private String schoolOrOrganization; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 단순 '기관' 이라는 단어로 칭해도 될 거 같아요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
private String major; | ||
|
||
private String degree; | ||
|
||
private LocalDate admissionDate; | ||
|
||
private LocalDate graduationDate; | ||
|
||
private LocalDate enterDate; | ||
private double gpa; | ||
|
||
private double maxGpa; | ||
|
||
private String explanation; | ||
|
||
public Training(String schoolOrOrganization, String major, String degree, LocalDate admissionDate, | ||
LocalDate graduationDate, double gpa, double maxGpa, String explanation) { | ||
validateTraining(schoolOrOrganization, major, degree, admissionDate, graduationDate, gpa, maxGpa); | ||
|
||
this.schoolOrOrganization = schoolOrOrganization; | ||
this.major = major; | ||
this.degree = degree; | ||
this.admissionDate = admissionDate; | ||
this.graduationDate = graduationDate; | ||
this.gpa = gpa; | ||
this.maxGpa = maxGpa; | ||
this.explanation = explanation; | ||
} | ||
|
||
private LocalDate graduateDate; | ||
private void validateTraining(String schoolOrOrganization, String major, String degree, LocalDate admissionDate, | ||
LocalDate graduationDate, double gpa, double maxGpa) { | ||
validate(schoolOrOrganization == null, ExceptionCode.NO_EMPTY_VALUE); | ||
validate(major == null, ExceptionCode.NO_EMPTY_VALUE); | ||
validate(degree == null, ExceptionCode.NO_EMPTY_VALUE); | ||
validate(admissionDate == null, ExceptionCode.NO_EMPTY_VALUE); | ||
validate(graduationDate == null, ExceptionCode.NO_EMPTY_VALUE); | ||
|
||
private String trainingContent; | ||
if (admissionDate.isAfter(graduationDate)) { | ||
throw new CustomException("TIME_ERROR", "입학 일시는 졸업 일시보다 먼저여야 합니다."); | ||
} | ||
|
||
public Training(String trainingName, LocalDate enterDate, LocalDate graduateDate, String trainingContent) { | ||
this.trainingName = trainingName; | ||
this.enterDate = enterDate; | ||
this.graduateDate = graduateDate; | ||
this.trainingContent = trainingContent; | ||
if (maxGpa <= gpa) { | ||
throw new CustomException("GPA_ERROR", "최대 학점은 내 학점보다 커야 합니다."); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -62,4 +62,11 @@ public User(Long id, String oauthUsername, String password, String email, Role r | |||||||||||
this.refreshToken = refreshToken; | ||||||||||||
} | ||||||||||||
|
||||||||||||
public boolean isMentee() { | ||||||||||||
if (this.role == Role.ROLE_MENTEE) { | ||||||||||||
return true; | ||||||||||||
} | ||||||||||||
return false; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
} | ||||||||||||
|
||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏻 |
||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.devcourse.resumeme.domain.resume; | ||
|
||
import org.devcourse.resumeme.domain.user.Provider; | ||
import org.devcourse.resumeme.domain.user.Role; | ||
import org.devcourse.resumeme.domain.user.User; | ||
import org.devcourse.resumeme.global.advice.exception.CustomException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) | ||
public class ResumeTest { | ||
|
||
private User user; | ||
|
||
@BeforeEach | ||
void init() { | ||
user = User.builder() | ||
.email("email") | ||
.provider(Provider.KAKAO) | ||
.role(Role.ROLE_MENTOR) | ||
.build(); | ||
} | ||
|
||
@Test | ||
void 멘티만_이력서를_작성할_수_있다() { | ||
assertThatThrownBy(() -> new Resume("title", user, new Training())) | ||
.isInstanceOf(CustomException.class); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.devcourse.resumeme.domain.resume; | ||
|
||
import org.devcourse.resumeme.global.advice.exception.CustomException; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDate; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) | ||
public class TrainingTest { | ||
|
||
@Test | ||
void 입학일자는_졸업일자_보다_먼저여야_한다() { | ||
assertThatThrownBy(() -> new Training("School", "Major", "Degree", | ||
LocalDate.now(), LocalDate.now().minusDays(1), 3.5, 4.0, "Explanation")) | ||
.isInstanceOf(CustomException.class); | ||
} | ||
|
||
@Test | ||
void max_gpa_should_be_greater_than_gpa() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메서드명 한글로 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
double gpa = 5.5; | ||
double maxGpa = 4.0; | ||
|
||
assertThatThrownBy(() -> new Training("School", "Major", "Degree", | ||
LocalDate.now(), LocalDate.now().plusDays(1), gpa, maxGpa, "Explanation")) | ||
.isInstanceOf(CustomException.class); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
내가 가진 여러개의 이력서가 하나의 교육 사항을 공유하나요?
이력서 하나에 교육사항 하나만 작성 가능한지도 궁금합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feat: 연관관계 수정