Skip to content

Commit

Permalink
feat: 스터디 수료 필드와 우수 스터디원 테이블 추가 (#782)
Browse files Browse the repository at this point in the history
* feat: 스터디 수료 필드와 우수 스터디원 테이블 추가

* feat: @Enumerated 어노테이션 추가

* feat: unique constraint 추가

* test: 스터디 히스토리 테스트 추가

* feat: 수료 여부 타입을 enum으로 변경
  • Loading branch information
Sangwook02 authored Sep 30, 2024
1 parent add30b8 commit efa9a65
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 0 deletions.
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;
}
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();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.gdschongik.gdsc.domain.study.domain;

import static com.gdschongik.gdsc.domain.study.domain.StudyHistoryStatus.*;

import com.gdschongik.gdsc.domain.common.model.BaseEntity;
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;
Expand All @@ -17,6 +21,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;

@Getter
@Entity
Expand All @@ -39,10 +44,15 @@ public class StudyHistory extends BaseEntity {

private String repositoryLink;

@Comment("수료 상태")
@Enumerated(EnumType.STRING)
private StudyHistoryStatus studyHistoryStatus;

@Builder(access = AccessLevel.PRIVATE)
private StudyHistory(Member student, Study study) {
this.student = student;
this.study = study;
this.studyHistoryStatus = NONE;
}

public static StudyHistory create(Member student, Study study) {
Expand All @@ -61,6 +71,13 @@ public void updateRepositoryLink(String repositoryLink) {
this.repositoryLink = repositoryLink;
}

/**
* 스터디 수료
*/
public void complete() {
studyHistoryStatus = COMPLETED;
}

// 데이터 전달 로직
public boolean isWithinApplicationAndCourse() {
return study.isWithinApplicationAndCourse();
Expand Down
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;
}
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);
}
}
}

0 comments on commit efa9a65

Please sign in to comment.