Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat/CK-242] 로드맵 관련 부분 의존성 리팩토링을 한다 #206

Merged
merged 23 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d72b469
refactor: roadmap 관련 코드 패키지 분리
Ohjintaek Dec 19, 2023
2ea6239
refactor: RoadmapCreateService에서 goalRoom 의존성 제거
Ohjintaek Dec 19, 2023
91f128b
refactor: RoadmapReadService에서 goalRoom 의존성 제거
Ohjintaek Dec 19, 2023
7085619
refactor: RoadmapScheduler에서 goalRoom 의존성 제거 및 테스트코드 패키지 분리
Ohjintaek Dec 19, 2023
3c0ba17
refactor: Roadmap에서 발생한 예외는 RoaadmapException을 던지도록 수정
Ohjintaek Dec 22, 2023
354f9b6
refactor: RoadmapSaveArgumentResolver 의존성 역전
Ohjintaek Dec 22, 2023
c8fc8f4
test: 테스트 코드 수정
Ohjintaek Dec 22, 2023
a307525
chore: build.gradle 수정 (jacoco 테스트 커버리지)
Ohjintaek Dec 22, 2023
7ce0184
refactor: roadmap과 roadmapReview에서 member 직접 참조를 삭제
Ohjintaek Jan 12, 2024
b63f1b7
chore: ScrollResponseMapper common으로 이관
Ohjintaek Jan 13, 2024
a0f588b
refactor: 로드맵 삭제 시 하위 골룸 삭제 방식 변경 (OnDelete 옵션 사용)
Ohjintaek Jan 13, 2024
3d6cd17
chore: 패키지 경로 수정
Ohjintaek Jan 13, 2024
df672b0
refactor: dto 패키지 분리
Ohjintaek Jan 13, 2024
7a1b1f3
refactor: Event 객체에서 도메인 직접 전달 제거
Ohjintaek Jan 14, 2024
3c5fc04
refactor: RoadmapNode에서 RoadmapContent 의존 제거
Ohjintaek Jan 14, 2024
9cf3c2a
refactor: Roadmap과 RoadmapContent, RoadmapReview간 의존 관계 제거
Ohjintaek Jan 14, 2024
bdccbbc
refactor: Roadmap 생성 시 태그, RoadmapContent 생성 시 노드들을 필수로 넣도록 수정
Ohjintaek Jan 21, 2024
5cf8113
test: RoadmapNodes 테스트코드 추가
Ohjintaek Jan 21, 2024
a0472bc
refactor: 불필요한 클래스 삭제
Ohjintaek Feb 15, 2024
732673f
fix: 데이터베이스 무결성 오류 수정
Ohjintaek Feb 15, 2024
fc761d5
refactor: 로드맵 삭제 시 연관된 리뷰 삭제를 이벤트로 발행
Ohjintaek Feb 16, 2024
ac71f6e
chore: merge conflict 해결
Ohjintaek Mar 27, 2024
3a7e610
refactor: 불필요한 이벤트 호출 제거
Ohjintaek Mar 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Optional<GoalRoomMember> findByRoadmapIdAndMemberIdentifierAndGoalRoomSta
.innerJoin(goalRoomMember.member, member)
.fetchJoin()
.where(
goalRoom.roadmapContent.roadmap.id.eq(roadmapId),
goalRoom.roadmapContent.roadmapId.eq(roadmapId),
member.identifier.eq(identifier),
goalRoom.status.eq(status))
.fetchOne());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import co.kirikiri.domain.goalroom.GoalRoomStatus;
import co.kirikiri.domain.member.Member;
import co.kirikiri.persistence.goalroom.dto.RoadmapGoalRoomsOrderType;
import co.kirikiri.roadmap.domain.Roadmap;

import java.time.LocalDate;
import java.util.List;
Expand All @@ -18,10 +17,10 @@ public interface GoalRoomQueryRepository {

Optional<GoalRoom> findByIdWithContentAndTodos(final Long goalRoomId);

List<GoalRoom> findGoalRoomsByRoadmapAndCond(final Roadmap roadmap,
final RoadmapGoalRoomsOrderType filterType,
final Long lastId,
final int pageSize);
List<GoalRoom> findGoalRoomsByRoadmapIdAndCond(final Long roadmapId,
final RoadmapGoalRoomsOrderType filterType,
final Long lastId,
final int pageSize);

Optional<GoalRoom> findByIdWithTodos(final Long goalRoomId);

Expand All @@ -31,7 +30,7 @@ List<GoalRoom> findGoalRoomsByRoadmapAndCond(final Roadmap roadmap,

Optional<GoalRoom> findByIdWithNodes(final Long goalRoomId);

List<GoalRoom> findByRoadmap(final Roadmap roadmap);
List<GoalRoom> findByRoadmapId(final Long roadmapId);

List<GoalRoom> findAllRecruitingGoalRoomsByStartDateEarlierThan(final LocalDate startDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import co.kirikiri.domain.member.Member;
import co.kirikiri.persistence.QuerydslRepositorySupporter;
import co.kirikiri.persistence.goalroom.dto.RoadmapGoalRoomsOrderType;
import co.kirikiri.roadmap.domain.Roadmap;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.dsl.BooleanExpression;
import jakarta.persistence.LockModeType;
Expand Down Expand Up @@ -60,17 +59,16 @@ public Optional<GoalRoom> findByIdWithContentAndTodos(final Long goalRoomId) {
}

@Override
public List<GoalRoom> findGoalRoomsByRoadmapAndCond(final Roadmap roadmap,
final RoadmapGoalRoomsOrderType orderType,
final Long lastId,
final int pageSize) {
public List<GoalRoom> findGoalRoomsByRoadmapIdAndCond(final Long roadmapId,
final RoadmapGoalRoomsOrderType orderType,
final Long lastId,
final int pageSize) {
return selectFrom(goalRoom)
.innerJoin(goalRoom.roadmapContent, roadmapContent)
.on(roadmapContent.roadmap.eq(roadmap))
.on(roadmapContent.roadmapId.eq(roadmapId))
.where(
statusCond(orderType),
lessThanLastId(lastId, orderType),
roadmapCond(roadmap))
lessThanLastId(lastId, orderType))
.limit(pageSize + LIMIT_OFFSET)
.orderBy(sortCond(orderType))
.fetch();
Expand Down Expand Up @@ -118,10 +116,10 @@ public Optional<GoalRoom> findByIdWithNodes(final Long goalRoomId) {
}

@Override
public List<GoalRoom> findByRoadmap(final Roadmap roadmap) {
public List<GoalRoom> findByRoadmapId(final Long roadmapId) {
return selectFrom(goalRoom)
.innerJoin(goalRoom.roadmapContent, roadmapContent)
.where(roadmapContent.roadmap.eq(roadmap))
.where(roadmapContent.roadmapId.eq(roadmapId))
.fetch();
}

Expand Down Expand Up @@ -174,10 +172,6 @@ private BooleanExpression lessThanLastId(final Long lastId, final RoadmapGoalRoo
);
}

private BooleanExpression roadmapCond(final Roadmap roadmap) {
return goalRoom.roadmapContent.roadmap.eq(roadmap);
}

private BooleanExpression equalOrEarlierStartDateThan(final LocalDate date) {
return goalRoom.startDate.loe(date);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import lombok.NoArgsConstructor;

import java.util.Objects;
import java.util.Optional;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down Expand Up @@ -52,15 +51,9 @@ public class Roadmap extends BaseCreatedTimeEntity {
@JoinColumn(name = "category_id", nullable = false)
private RoadmapCategory category;

@Embedded
private RoadmapContents contents = new RoadmapContents();

@Embedded
private RoadmapTags tags = new RoadmapTags();

@Embedded
private RoadmapReviews reviews = new RoadmapReviews();

public Roadmap(final String title, final String introduction, final int requiredPeriod,
final RoadmapDifficulty difficulty, final Long creatorId, final RoadmapCategory category) {
this(null, title, introduction, requiredPeriod, difficulty, RoadmapStatus.CREATED, creatorId, category);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roadmap 생성자 중에서 사용하지 않거나 테스트에서만 사용하는 생성자를 정리하면 좋을 것 같아요 😊

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생성자 몇 개 없애버리니 기분이 좋네요

Expand Down Expand Up @@ -123,13 +116,6 @@ private void validateRequiredPeriod(final int requiredPeriod) {
}
}

public void addContent(final RoadmapContent content) {
contents.add(content);
if (content.isNotSameRoadmap(this)) {
content.updateRoadmap(this);
}
}

public void addTags(final RoadmapTags tags) {
this.tags.addAll(tags);
}
Expand All @@ -138,21 +124,10 @@ public boolean isCreator(final Long memberId) {
return Objects.equals(creatorId, memberId);
}

public void addReview(final RoadmapReview review) {
reviews.add(review);
if (review.isNotSameRoadmap(this)) {
review.updateRoadmap(this);
}
}

public void delete() {
this.status = RoadmapStatus.DELETED;
}

public Optional<RoadmapContent> findLastRoadmapContent() {
return this.contents.findLastRoadmapContent();
}

public boolean isDeleted() {
return status == RoadmapStatus.DELETED;
}
Expand All @@ -169,10 +144,6 @@ public RoadmapCategory getCategory() {
return category;
}

public RoadmapContents getContents() {
return contents;
}

public String getIntroduction() {
return introduction;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -24,21 +21,20 @@ public class RoadmapContent extends BaseUpdatedTimeEntity {
@Column(length = 2200)
private String content;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "roadmap_id", nullable = false)
private Roadmap roadmap;
private Long roadmapId;

@Embedded
private final RoadmapNodes nodes = new RoadmapNodes();

public RoadmapContent(final String content) {
this(null, content);
public RoadmapContent(final String content, final Long roadmapId) {
this(null, content, roadmapId);
}

public RoadmapContent(final Long id, final String content) {
public RoadmapContent(final Long id, final String content, final Long roadmapId) {
validate(content);
this.id = id;
this.content = content;
this.roadmapId = roadmapId;
}

private void validate(final String content) {
Expand All @@ -58,16 +54,6 @@ public void addNodes(final RoadmapNodes nodes) {
this.nodes.addAll(nodes);
}

public boolean isNotSameRoadmap(final Roadmap roadmap) {
return this.roadmap == null || !this.roadmap.equals(roadmap);
}

public void updateRoadmap(final Roadmap roadmap) {
if (this.roadmap == null) {
this.roadmap = roadmap;
}
}

public int nodesSize() {
return nodes.size();
}
Expand All @@ -84,11 +70,11 @@ public String getContent() {
return content;
}

public RoadmapNodes getNodes() {
return nodes;
public Long getRoadmapId() {
return roadmapId;
}

public Roadmap getRoadmap() {
return roadmap;
public RoadmapNodes getNodes() {
return nodes;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 클래스는 이제 없어져도 되겠네요!

Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
package co.kirikiri.roadmap.domain;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.FetchType;
import jakarta.persistence.OneToMany;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Embeddable
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class RoadmapContents {

@OneToMany(fetch = FetchType.LAZY,
cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE},
mappedBy = "roadmap")
@Column(nullable = false)
private final List<RoadmapContent> values = new ArrayList<>();

public RoadmapContents(final List<RoadmapContent> contents) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import co.kirikiri.roadmap.domain.exception.RoadmapException;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

Expand All @@ -31,17 +28,16 @@ public class RoadmapReview extends BaseUpdatedTimeEntity {

private Long memberId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "roadmap_id")
private Roadmap roadmap;
private Long roadmapId;

public RoadmapReview(final String content, final Double rate, final Long memberId) {
public RoadmapReview(final String content, final Double rate, final Long memberId, final Long roadmapId) {
if (content != null) {
validate(content, rate);
}
this.content = content;
this.rate = rate;
this.memberId = memberId;
this.roadmapId = roadmapId;
}

private void validate(final String content, final Double rate) {
Expand All @@ -62,16 +58,6 @@ private void validateRate(final Double rate) {
}
}

public void updateRoadmap(final Roadmap roadmap) {
if (this.roadmap == null) {
this.roadmap = roadmap;
}
}

public boolean isNotSameRoadmap(final Roadmap roadmap) {
return this.roadmap == null || !this.roadmap.equals(roadmap);
}

public String getContent() {
return content;
}
Expand All @@ -83,4 +69,8 @@ public Double getRate() {
public Long getMemberId() {
return memberId;
}

public Long getRoadmapId() {
return roadmapId;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 클래스도 이제 없어져도 될것 같아요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

둘 다 없애버렸습니다 😀

Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package co.kirikiri.roadmap.domain;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Embeddable;
import jakarta.persistence.FetchType;
import jakarta.persistence.OneToMany;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

Expand All @@ -14,9 +11,9 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class RoadmapReviews {

@OneToMany(fetch = FetchType.LAZY,
cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE},
orphanRemoval = true, mappedBy = "roadmap")
// @OneToMany(fetch = FetchType.LAZY,
// cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE},
// orphanRemoval = true, mappedBy = "roadmap")
private List<RoadmapReview> values = new ArrayList<>();

public void add(final RoadmapReview review) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
package co.kirikiri.roadmap.persistence;

import co.kirikiri.roadmap.domain.Roadmap;
import co.kirikiri.roadmap.domain.RoadmapContent;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface RoadmapContentRepository extends JpaRepository<RoadmapContent, Long> {

Optional<RoadmapContent> findFirstByRoadmapIdOrderByCreatedAtDesc(final Long roadmapId);

Optional<RoadmapContent> findFirstByRoadmapOrderByCreatedAtDesc(final Roadmap roadmap);
List<RoadmapContent> findAllByRoadmapId(final Long roadmapId);

@Query("select rc from RoadmapContent rc "
+ "join fetch rc.roadmap r "
+ "where rc.id = :roadmapContentId")
Optional<RoadmapContent> findByIdWithRoadmap(@Param("roadmapContentId") final Long roadmapContentId);
void deleteAllByRoadmapId(final Long roadmapId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import co.kirikiri.roadmap.domain.Roadmap;
import co.kirikiri.roadmap.domain.RoadmapCategory;
import co.kirikiri.roadmap.domain.RoadmapStatus;
import co.kirikiri.roadmap.persistence.dto.RoadmapOrderType;
import co.kirikiri.roadmap.persistence.dto.RoadmapSearchDto;

Expand All @@ -28,6 +27,4 @@ List<Roadmap> findRoadmapsWithCategoryByMemberIdOrderByLatest(final Long memberI
final int pageSize);

Optional<Roadmap> findByIdAndMemberIdentifier(final Long roadmapId, final String identifier);

List<Roadmap> findWithRoadmapContentByStatus(final RoadmapStatus status);
}
Loading
Loading