Skip to content

Commit

Permalink
[REFACTOR] Matching과 VolunteerCertification 양방향 연관관계 설정 (#342)
Browse files Browse the repository at this point in the history
refactor: 매칭과 봉사인증 폼 양방향 매칭 설정

- VolunteerCertification: 연관관계 주인 설정
- Matching: mappedBy 추가, 명시적 연결 함수 제거(순환 참조 오류)
- VolunteerCertificationRepositoryImpl: 양방향 관계 설정으로 isNotNull
  where 조건 제거, volunteerCertification 기준으로 조회
  • Loading branch information
injae-348 authored Jan 20, 2025
1 parent f65f5ef commit 591f071
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
Expand All @@ -26,6 +29,10 @@ public class VolunteerCertification extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "matching_id")
private Matching matching;

@Embedded
private VolunteerTime volunteerTime;

Expand All @@ -36,20 +43,20 @@ public class VolunteerCertification extends BaseEntity {
private boolean isCertified;

@Builder
private VolunteerCertification(VolunteerTime volunteerTime, String content, boolean isCertified) {
private VolunteerCertification(Matching matching, VolunteerTime volunteerTime, String content, boolean isCertified) {
this.matching = matching;
this.volunteerTime = volunteerTime;
this.content = content;
this.isCertified = isCertified;
}

public static VolunteerCertification of(Matching matching, VolunteerTime volunteerTime, String content) {
VolunteerCertification certification = VolunteerCertification.builder()
return VolunteerCertification.builder()
.matching(matching)
.volunteerTime(volunteerTime)
.content(content)
.isCertified(false)
.build();
matching.addVolunteerCertification(certification);
return certification;
}

public void updateVolunteerCertification(VolunteerTime volunteerTime, String content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,16 @@ public VolunteerCertificationCustomPage findAdminVolunteerCertifications(Integer
.where(blackList.reportedMember.eq(matching.giver))
.exists()
))
.from(matching)
.leftJoin(matching.volunteerCertification, volunteerCertification)
.where(matching.volunteerCertification.isNotNull())
.from(volunteerCertification)
.leftJoin(volunteerCertification.matching, matching)
.offset((long) page * size)
.limit(size)
.orderBy(volunteerCertification.createdAt.desc())
.fetch();

Long totalElements = queryFactory
.select(matching.volunteerCertification.count())
.from(matching)
.where(matching.volunteerCertification.isNotNull())
.select(volunteerCertification.count())
.from(volunteerCertification)
.fetchOne();

long totalPage = (totalElements + size - 1) / size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class Matching extends SoftDeletableEntity {
@OneToMany(mappedBy = "matching", cascade = CascadeType.ALL, orphanRemoval = true)
private final List<MessageReadStatus> messageReadStatuses = new ArrayList<>();

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
@OneToOne(mappedBy = "matching", cascade = CascadeType.ALL, orphanRemoval = true)
private VolunteerCertification volunteerCertification;

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
Expand All @@ -100,10 +100,6 @@ public void validateCreateVolunteerCertification() {
}
}

public void addVolunteerCertification(VolunteerCertification volunteerCertification) {
this.volunteerCertification = volunteerCertification;
}

public boolean canVerificationRequest() {
return certificationTracking.isRequestedWithinOneDay();
}
Expand Down

0 comments on commit 591f071

Please sign in to comment.