-
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.
feat: 스터디 수료 필드와 우수 스터디원 테이블 추가 (#782)
* feat: 스터디 수료 필드와 우수 스터디원 테이블 추가 * feat: @Enumerated 어노테이션 추가 * feat: unique constraint 추가 * test: 스터디 히스토리 테스트 추가 * feat: 수료 여부 타입을 enum으로 변경
- Loading branch information
1 parent
add30b8
commit efa9a65
Showing
5 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/main/java/com/gdschongik/gdsc/domain/study/domain/AchievementType.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,13 @@ | ||
package com.gdschongik.gdsc.domain.study.domain; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum AchievementType { | ||
FIRST_ROUND_OUTSTANDING_STUDENT("1차 우수 스터디원"), | ||
SECOND_ROUND_OUTSTANDING_STUDENT("2차 우수 스터디원"); | ||
|
||
private final String value; | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyAchievement.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,57 @@ | ||
package com.gdschongik.gdsc.domain.study.domain; | ||
|
||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.UniqueConstraint; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"member_id", "study_id", "achievement_type"})}) | ||
public class StudyAchievement { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "study_achievement_id") | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id") | ||
private Member student; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "study_id") | ||
private Study study; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private AchievementType achievementType; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
private StudyAchievement(Member student, Study study, AchievementType achievementType) { | ||
this.student = student; | ||
this.study = study; | ||
this.achievementType = achievementType; | ||
} | ||
|
||
public static StudyAchievement create(Member student, Study study, AchievementType achievementType) { | ||
return StudyAchievement.builder() | ||
.student(student) | ||
.study(study) | ||
.achievementType(achievementType) | ||
.build(); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyHistoryStatus.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,13 @@ | ||
package com.gdschongik.gdsc.domain.study.domain; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum StudyHistoryStatus { | ||
NONE("미수료"), | ||
COMPLETED("수료"); | ||
|
||
private final String value; | ||
} |
62 changes: 62 additions & 0 deletions
62
src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyHistoryTest.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,62 @@ | ||
package com.gdschongik.gdsc.domain.study.domain; | ||
|
||
import static com.gdschongik.gdsc.domain.study.domain.StudyHistoryStatus.*; | ||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period; | ||
import com.gdschongik.gdsc.helper.FixtureHelper; | ||
import java.time.LocalDateTime; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class StudyHistoryTest { | ||
|
||
FixtureHelper fixtureHelper = new FixtureHelper(); | ||
|
||
@Nested | ||
class 스터디_히스토리_생성시 { | ||
|
||
@Test | ||
void 수료상태는_NONE이다() { | ||
// given | ||
Member student = fixtureHelper.createRegularMember(1L); | ||
Member mentor = fixtureHelper.createRegularMember(2L); | ||
LocalDateTime now = LocalDateTime.now(); | ||
Study study = fixtureHelper.createStudy( | ||
mentor, | ||
Period.createPeriod(now.plusDays(5), now.plusDays(10)), | ||
Period.createPeriod(now.minusDays(5), now)); | ||
|
||
// when | ||
StudyHistory studyHistory = StudyHistory.create(student, study); | ||
|
||
// then | ||
assertThat(studyHistory.getStudyHistoryStatus()).isEqualTo(NONE); | ||
} | ||
} | ||
|
||
@Nested | ||
class 스터디_수료시 { | ||
|
||
@Test | ||
void 수료상태는_COMPLETED이다() { | ||
// given | ||
Member student = fixtureHelper.createRegularMember(1L); | ||
Member mentor = fixtureHelper.createRegularMember(2L); | ||
LocalDateTime now = LocalDateTime.now(); | ||
Study study = fixtureHelper.createStudy( | ||
mentor, | ||
Period.createPeriod(now.plusDays(5), now.plusDays(10)), | ||
Period.createPeriod(now.minusDays(5), now)); | ||
|
||
StudyHistory studyHistory = StudyHistory.create(student, study); | ||
|
||
// when | ||
studyHistory.complete(); | ||
|
||
// then | ||
assertThat(studyHistory.getStudyHistoryStatus()).isEqualTo(COMPLETED); | ||
} | ||
} | ||
} |