From 2f6654c85ac105419ab61e3d78d4d704e6fb68a9 Mon Sep 17 00:00:00 2001 From: bumwoo Date: Tue, 24 Oct 2023 16:49:55 +0900 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20MENTEE=5FONLY=5FRESUME=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resumeme/global/advice/exception/ExceptionCode.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/devcourse/resumeme/global/advice/exception/ExceptionCode.java b/src/main/java/org/devcourse/resumeme/global/advice/exception/ExceptionCode.java index bebf1e0e..b89f2c6d 100644 --- a/src/main/java/org/devcourse/resumeme/global/advice/exception/ExceptionCode.java +++ b/src/main/java/org/devcourse/resumeme/global/advice/exception/ExceptionCode.java @@ -2,7 +2,8 @@ public enum ExceptionCode { MENTEE_NOT_FOUND("해당 멘티를 찾을 수 없습니다."), - NO_EMPTY_VALUE("빈 값일 수 없습니다"); + NO_EMPTY_VALUE("빈 값일 수 없습니다"), + MENTEE_ONLY_RESUME("멘티만 이력서를 작성할 수 있습니다."); private final String message; From 0d44fed6bcae2963db08728cb9db1e71a5801e82 Mon Sep 17 00:00:00 2001 From: bumwoo Date: Tue, 24 Oct 2023 16:50:38 +0900 Subject: [PATCH 2/9] =?UTF-8?q?feat:=20Resume=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=ED=95=84=EB=93=9C=20=EC=88=98=EC=A0=95,=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resumeme/domain/resume/Resume.java | 63 +++++++------------ 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/devcourse/resumeme/domain/resume/Resume.java b/src/main/java/org/devcourse/resumeme/domain/resume/Resume.java index 000641c0..4f064253 100644 --- a/src/main/java/org/devcourse/resumeme/domain/resume/Resume.java +++ b/src/main/java/org/devcourse/resumeme/domain/resume/Resume.java @@ -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,11 +33,9 @@ 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; @@ -39,7 +43,8 @@ public class Resume { @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; } - 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; } } From d5f9d46356d729ef0bedb449503d58e55c2cd552 Mon Sep 17 00:00:00 2001 From: bumwoo Date: Tue, 24 Oct 2023 16:51:05 +0900 Subject: [PATCH 3/9] =?UTF-8?q?feat:=20Training=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=EB=A1=9C=20=EC=88=98=EC=A0=95,=20=EA=B2=80=EC=A6=9D?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resumeme/domain/resume/Training.java | 70 +++++++++++++++---- .../devcourse/resumeme/domain/user/User.java | 7 ++ 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/devcourse/resumeme/domain/resume/Training.java b/src/main/java/org/devcourse/resumeme/domain/resume/Training.java index 04bec967..abe4494d 100644 --- a/src/main/java/org/devcourse/resumeme/domain/resume/Training.java +++ b/src/main/java/org/devcourse/resumeme/domain/resume/Training.java @@ -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; + + 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", "최대 학점은 내 학점보다 커야 합니다."); + } } } diff --git a/src/main/java/org/devcourse/resumeme/domain/user/User.java b/src/main/java/org/devcourse/resumeme/domain/user/User.java index e89d5bb9..3de65812 100644 --- a/src/main/java/org/devcourse/resumeme/domain/user/User.java +++ b/src/main/java/org/devcourse/resumeme/domain/user/User.java @@ -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; + } + } From e7aa500f10f1c0f756c82ed1578ea46ab567ef4f Mon Sep 17 00:00:00 2001 From: bumwoo Date: Tue, 24 Oct 2023 16:51:20 +0900 Subject: [PATCH 4/9] =?UTF-8?q?test:=20=EA=B5=90=EC=9C=A1=20=EC=9D=B4?= =?UTF-8?q?=EB=A0=A5=20=EB=93=B1=EB=A1=9D=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resumeme/domain/resume/ResumeTest.java | 34 +++++++++++++++++++ .../resumeme/domain/resume/TrainingTest.java | 32 +++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/test/java/org/devcourse/resumeme/domain/resume/ResumeTest.java create mode 100644 src/test/java/org/devcourse/resumeme/domain/resume/TrainingTest.java diff --git a/src/test/java/org/devcourse/resumeme/domain/resume/ResumeTest.java b/src/test/java/org/devcourse/resumeme/domain/resume/ResumeTest.java new file mode 100644 index 00000000..6077b44e --- /dev/null +++ b/src/test/java/org/devcourse/resumeme/domain/resume/ResumeTest.java @@ -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); + } + +} diff --git a/src/test/java/org/devcourse/resumeme/domain/resume/TrainingTest.java b/src/test/java/org/devcourse/resumeme/domain/resume/TrainingTest.java new file mode 100644 index 00000000..a162711b --- /dev/null +++ b/src/test/java/org/devcourse/resumeme/domain/resume/TrainingTest.java @@ -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() { + 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); + } + +} From 4316bc1740870a36dc1e1b6a2bb0abcce43865a5 Mon Sep 17 00:00:00 2001 From: bumwoo Date: Tue, 24 Oct 2023 16:59:31 +0900 Subject: [PATCH 5/9] =?UTF-8?q?test:=20=EB=A9=94=EC=86=8C=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/devcourse/resumeme/domain/resume/TrainingTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/devcourse/resumeme/domain/resume/TrainingTest.java b/src/test/java/org/devcourse/resumeme/domain/resume/TrainingTest.java index a162711b..b34a0d37 100644 --- a/src/test/java/org/devcourse/resumeme/domain/resume/TrainingTest.java +++ b/src/test/java/org/devcourse/resumeme/domain/resume/TrainingTest.java @@ -20,7 +20,7 @@ public class TrainingTest { } @Test - void max_gpa_should_be_greater_than_gpa() { + void 최대학점은_내_학점보다_커야한다() { double gpa = 5.5; double maxGpa = 4.0; From 95c75ece6b7c121157f5aac06f31fa538f67aad5 Mon Sep 17 00:00:00 2001 From: bumwoo Date: Tue, 24 Oct 2023 17:03:02 +0900 Subject: [PATCH 6/9] =?UTF-8?q?feat:=20training=20null=20=EC=B2=B4?= =?UTF-8?q?=ED=81=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/devcourse/resumeme/domain/resume/Resume.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/devcourse/resumeme/domain/resume/Resume.java b/src/main/java/org/devcourse/resumeme/domain/resume/Resume.java index 4f064253..0bc5937f 100644 --- a/src/main/java/org/devcourse/resumeme/domain/resume/Resume.java +++ b/src/main/java/org/devcourse/resumeme/domain/resume/Resume.java @@ -62,15 +62,16 @@ public class Resume extends BaseEntity { private String phoneNumber; public Resume(String title, User user, Training training) { - validateResume(title, user); + validateResume(title, user, training); this.title = title; this.user = user; this.training = training; } - private static void validateResume(String title, User user) { + private static void validateResume(String title, User user, Training training) { validate(title == null, ExceptionCode.NO_EMPTY_VALUE); validate(user == null, ExceptionCode.MENTEE_NOT_FOUND); + validate(training == null, ExceptionCode.NO_EMPTY_VALUE); if (!user.isMentee()) { throw new CustomException(ExceptionCode.MENTEE_ONLY_RESUME); } From a2468a89e010b3803b3adec1d80549bd49d3fa94 Mon Sep 17 00:00:00 2001 From: bumwoo Date: Tue, 24 Oct 2023 17:03:48 +0900 Subject: [PATCH 7/9] =?UTF-8?q?feat:=20=EA=B8=B0=EA=B4=80=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/devcourse/resumeme/domain/resume/Training.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/devcourse/resumeme/domain/resume/Training.java b/src/main/java/org/devcourse/resumeme/domain/resume/Training.java index abe4494d..b9541f0f 100644 --- a/src/main/java/org/devcourse/resumeme/domain/resume/Training.java +++ b/src/main/java/org/devcourse/resumeme/domain/resume/Training.java @@ -24,7 +24,7 @@ public class Training { @Column(name = "training_id") private Long id; - private String schoolOrOrganization; + private String organization; private String major; @@ -40,11 +40,11 @@ public class Training { private String explanation; - public Training(String schoolOrOrganization, String major, String degree, LocalDate admissionDate, + public Training(String organization, String major, String degree, LocalDate admissionDate, LocalDate graduationDate, double gpa, double maxGpa, String explanation) { - validateTraining(schoolOrOrganization, major, degree, admissionDate, graduationDate, gpa, maxGpa); + validateTraining(organization, major, degree, admissionDate, graduationDate, gpa, maxGpa); - this.schoolOrOrganization = schoolOrOrganization; + this.organization = organization; this.major = major; this.degree = degree; this.admissionDate = admissionDate; From 5c61b6f04bff2a2bc200901e06290265af91de7c Mon Sep 17 00:00:00 2001 From: bumwoo Date: Tue, 24 Oct 2023 17:09:35 +0900 Subject: [PATCH 8/9] =?UTF-8?q?feat:=20=EC=97=B0=EA=B4=80=EA=B4=80?= =?UTF-8?q?=EA=B3=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devcourse/resumeme/domain/resume/Resume.java | 13 ++++--------- .../devcourse/resumeme/domain/resume/Training.java | 6 ++++++ .../resumeme/domain/resume/ResumeTest.java | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/devcourse/resumeme/domain/resume/Resume.java b/src/main/java/org/devcourse/resumeme/domain/resume/Resume.java index 0bc5937f..c57e28ea 100644 --- a/src/main/java/org/devcourse/resumeme/domain/resume/Resume.java +++ b/src/main/java/org/devcourse/resumeme/domain/resume/Resume.java @@ -10,6 +10,7 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.Lob; import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -43,10 +44,6 @@ public class Resume extends BaseEntity { @Lob private String introduce; - @ManyToOne - @JoinColumn(name = "training_id") - private Training training; - @Embedded private Career career; @@ -61,17 +58,15 @@ public class Resume extends BaseEntity { private String phoneNumber; - public Resume(String title, User user, Training training) { - validateResume(title, user, training); + public Resume(String title, User user) { + validateResume(title, user); this.title = title; this.user = user; - this.training = training; } - private static void validateResume(String title, User user, Training training) { + private static void validateResume(String title, User user) { validate(title == null, ExceptionCode.NO_EMPTY_VALUE); validate(user == null, ExceptionCode.MENTEE_NOT_FOUND); - validate(training == null, ExceptionCode.NO_EMPTY_VALUE); if (!user.isMentee()) { throw new CustomException(ExceptionCode.MENTEE_ONLY_RESUME); } diff --git a/src/main/java/org/devcourse/resumeme/domain/resume/Training.java b/src/main/java/org/devcourse/resumeme/domain/resume/Training.java index b9541f0f..e032e141 100644 --- a/src/main/java/org/devcourse/resumeme/domain/resume/Training.java +++ b/src/main/java/org/devcourse/resumeme/domain/resume/Training.java @@ -4,6 +4,8 @@ import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -24,6 +26,10 @@ public class Training { @Column(name = "training_id") private Long id; + @ManyToOne + @JoinColumn(name = "resume_id") + private Resume resume; + private String organization; private String major; diff --git a/src/test/java/org/devcourse/resumeme/domain/resume/ResumeTest.java b/src/test/java/org/devcourse/resumeme/domain/resume/ResumeTest.java index 6077b44e..05b22a10 100644 --- a/src/test/java/org/devcourse/resumeme/domain/resume/ResumeTest.java +++ b/src/test/java/org/devcourse/resumeme/domain/resume/ResumeTest.java @@ -27,7 +27,7 @@ void init() { @Test void 멘티만_이력서를_작성할_수_있다() { - assertThatThrownBy(() -> new Resume("title", user, new Training())) + assertThatThrownBy(() -> new Resume("title", user)) .isInstanceOf(CustomException.class); } From 0cd0064e09f145fa60edd91b4d5afea37b126336 Mon Sep 17 00:00:00 2001 From: bumwoo Date: Tue, 24 Oct 2023 17:12:13 +0900 Subject: [PATCH 9/9] =?UTF-8?q?refactor:=20isMentee=20inline=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/devcourse/resumeme/domain/user/User.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/org/devcourse/resumeme/domain/user/User.java b/src/main/java/org/devcourse/resumeme/domain/user/User.java index 3de65812..d6c31d96 100644 --- a/src/main/java/org/devcourse/resumeme/domain/user/User.java +++ b/src/main/java/org/devcourse/resumeme/domain/user/User.java @@ -63,10 +63,7 @@ public User(Long id, String oauthUsername, String password, String email, Role r } public boolean isMentee() { - if (this.role == Role.ROLE_MENTEE) { - return true; - } - return false; + return role.equals(Role.ROLE_MENTEE); } }