-
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: 스터디 히스토리 v2 도메인 구현 * fix: 빌더에서 전달된 값 그대로 할당하도록 수정 * fix: 빌더에서 전달된 값 그대로 할당하도록 수정
- Loading branch information
1 parent
246d20d
commit b56893d
Showing
1 changed file
with
102 additions
and
0 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyHistoryV2.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,102 @@ | ||
package com.gdschongik.gdsc.domain.studyv2.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 com.gdschongik.gdsc.domain.study.domain.StudyApplyCanceledEvent; | ||
import com.gdschongik.gdsc.domain.study.domain.StudyHistoryCompletionWithdrawnEvent; | ||
import com.gdschongik.gdsc.domain.study.domain.StudyHistoryStatus; | ||
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.PreRemove; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.UniqueConstraint; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.Comment; | ||
|
||
@Getter | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table( | ||
name = "study_history_v2", | ||
uniqueConstraints = {@UniqueConstraint(columnNames = {"member_id", "study_v2_id"})}) | ||
public class StudyHistoryV2 extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "study_history_v2_id") | ||
private Long id; | ||
|
||
@Comment("수료 상태") | ||
@Enumerated(EnumType.STRING) | ||
private StudyHistoryStatus status; | ||
|
||
private String repositoryLink; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id") | ||
private Member student; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "study_v2_id") | ||
private StudyV2 study; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
private StudyHistoryV2(StudyHistoryStatus status, Member student, StudyV2 study) { | ||
this.status = status; | ||
this.student = student; | ||
this.study = study; | ||
} | ||
|
||
public static StudyHistoryV2 create(Member student, StudyV2 study) { | ||
return StudyHistoryV2.builder() | ||
.status(NONE) | ||
.student(student) | ||
.study(study) | ||
.build(); | ||
} | ||
|
||
@PreRemove | ||
private void preRemove() { | ||
registerEvent(new StudyApplyCanceledEvent(this.study.getId(), this.student.getId())); | ||
} | ||
|
||
/** | ||
* 레포지토리 링크를 업데이트합니다. | ||
*/ | ||
public void updateRepositoryLink(String repositoryLink) { | ||
this.repositoryLink = repositoryLink; | ||
} | ||
|
||
/** | ||
* 스터디 수료 | ||
*/ | ||
public void complete() { | ||
this.status = COMPLETED; | ||
} | ||
|
||
/** | ||
* 스터디 수료 철회 | ||
*/ | ||
public void withdrawCompletion() { | ||
this.status = NONE; | ||
registerEvent(new StudyHistoryCompletionWithdrawnEvent(this.id)); | ||
} | ||
|
||
// 데이터 전달 로직 | ||
public boolean isCompleted() { | ||
return this.status == COMPLETED; | ||
} | ||
} |