Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -12,11 +12,13 @@ public class StudyDTOMapper {
public static GetStudyOverviewResponse toDTO(
List<Study> studies,
Set<Long> likedStudyIds,
Set<Long> ownedStudyIds,
boolean hasNext,
Long nextCursor,
Long totalElements
) {
Set<Long> safelikedIds = likedStudyIds != null ? likedStudyIds : Collections.emptySet();
Set<Long> safeOwnedStudyIds = ownedStudyIds != null ? ownedStudyIds : Collections.emptySet();

List<StudyOverview> list = studies.stream().map(
study -> StudyOverview.of(
Expand All @@ -27,20 +29,12 @@ public static GetStudyOverviewResponse toDTO(
study.getCurrentMembers(),
0,
safelikedIds.contains(study.getId()),
safeOwnedStudyIds.contains(study.getId()),
0,
study.getImageUrl()
)
).toList();

return GetStudyOverviewResponse.of(list, hasNext, nextCursor, totalElements);
}

public static GetStudyOverviewResponse toDTO(
List<Study> studies,
boolean hasNext,
Long nextCursor,
Long totalElements
) {
return toDTO(studies, Collections.emptySet(), hasNext, nextCursor, totalElements);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import kr.spot.study.domain.enums.SortBy;
import kr.spot.study.domain.enums.StudyMemberStatus;
import kr.spot.study.infrastructure.jpa.associations.StudyLikeRepository;
import kr.spot.study.infrastructure.jpa.associations.StudyMemberRepository;
import kr.spot.study.infrastructure.jpa.querydsl.StudyQueryRepository;
import kr.spot.study.presentation.query.dto.response.GetStudyOverviewResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -31,6 +32,7 @@ public class GetMyStudyInfoService {
private final GetPreferredCategoryPort getPreferredCategoryPort;
private final StudyQueryRepository studyQueryRepository;
private final StudyLikeRepository studyLikeRepository;
private final StudyMemberRepository studyMemberRepository;

public GetStudyOverviewResponse getMyStudyOverview(
long viewerId,
Expand Down Expand Up @@ -196,7 +198,10 @@ public GetStudyOverviewResponse getRecommendedStudies(long viewerId) {
fillWithPopularStudies(result, recommendCount);

Set<Long> likedStudyIds = studyLikeRepository.findStudyIdsByMemberId(viewerId);
return StudyDTOMapper.toDTO(result, likedStudyIds, false, null, (long) result.size());
Set<Long> ownedStudyIds = studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(
viewerId, StudyMemberStatus.OWNER);
return StudyDTOMapper.toDTO(result, likedStudyIds, ownedStudyIds, false, null,
(long) result.size());
}

private List<Category> getPreferredCategories(long memberId) {
Expand Down Expand Up @@ -240,7 +245,10 @@ private GetStudyOverviewResponse toCursorPage(List<Study> rows, long viewerId, i
List<Study> pageContent = hasNext ? rows.subList(0, pageSize) : rows;
Long nextCursor = hasNext ? pageContent.getLast().getId() : null;
Set<Long> likedStudyIds = studyLikeRepository.findStudyIdsByMemberId(viewerId);
return StudyDTOMapper.toDTO(pageContent, likedStudyIds, hasNext, nextCursor, totalElements);
Set<Long> ownedStudyIds = studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(
viewerId, StudyMemberStatus.OWNER);
return StudyDTOMapper.toDTO(pageContent, likedStudyIds, ownedStudyIds, hasNext, nextCursor,
totalElements);
}

private List<String> filterPreferredRegionCodes(List<String> regionCodes,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kr.spot.study.infrastructure.jpa.associations;

import java.util.List;
import java.util.Set;
import kr.spot.code.status.ErrorStatus;
import kr.spot.exception.GeneralException;
import kr.spot.study.domain.associations.StudyMember;
Expand All @@ -26,4 +27,7 @@ long countByMemberIdAndStudyMemberStatusIn(long memberId,
long countByMemberIdAndStudyMemberStatus(long memberId, StudyMemberStatus studyMemberStatus);

void deleteByMemberId(long memberId);

Set<Long> findStudyIdsByMemberIdAndStudyMemberStatus(long memberId,
StudyMemberStatus studyMemberStatus);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public record StudyOverview(
int currentMembers,
long likeCount,
boolean isLiked,
boolean isOwner,
long hitCount,
String profileImageUrl
) {
Expand All @@ -38,6 +39,7 @@ public static StudyOverview of(
int currentMembers,
long likeCount,
boolean isLiked,
boolean isOwner,
long hitCount,
String profileImageUrl
) {
Expand All @@ -49,6 +51,7 @@ public static StudyOverview of(
currentMembers,
likeCount,
isLiked,
isOwner,
hitCount,
profileImageUrl
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import kr.spot.study.domain.enums.SortBy;
import kr.spot.study.domain.enums.StudyMemberStatus;
import kr.spot.study.infrastructure.jpa.associations.StudyLikeRepository;
import kr.spot.study.infrastructure.jpa.associations.StudyMemberRepository;
import kr.spot.study.infrastructure.jpa.querydsl.StudyQueryRepository;
import kr.spot.study.presentation.query.dto.response.GetStudyOverviewResponse;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -45,6 +46,8 @@ class GetMyStudyInfoServiceTest {
private StudyQueryRepository studyQueryRepository;
@Mock
private StudyLikeRepository studyLikeRepository;
@Mock
private StudyMemberRepository studyMemberRepository;

@Nested
@DisplayName("내 스터디 목록 조회 (getMyStudyOverview)")
Expand All @@ -67,6 +70,9 @@ void should_return_first_page_with_next_page() {
(long) studies.size());
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of());

given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getMyStudyOverview(viewerId,
List.of(status),
Expand All @@ -92,7 +98,8 @@ void should_return_last_page() {
given(studyQueryRepository.countMyStudies(viewerId, List.of(status))).willReturn(
(long) studies.size());
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of());

given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());
// when
GetStudyOverviewResponse response = getMyStudyInfoService.getMyStudyOverview(viewerId,
List.of(status),
Expand Down Expand Up @@ -120,6 +127,8 @@ void should_return_next_page_with_cursor() {
given(studyQueryRepository.countMyStudies(viewerId, List.of(status))).willReturn(
(long) studies.size());
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getMyStudyOverview(viewerId,
Expand Down Expand Up @@ -147,6 +156,8 @@ void should_cap_page_size_at_max_page_size() {
given(studyQueryRepository.countMyStudies(viewerId, List.of(status))).willReturn(
(long) studies.size());
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getMyStudyOverview(viewerId,
Expand Down Expand Up @@ -184,6 +195,8 @@ void should_find_studies_in_all_preferred_regions_when_no_filter() {
eq(preferredRegions)))
.willReturn((long) studies.size());
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getMyPreferredRegionStudies(
Expand Down Expand Up @@ -219,6 +232,8 @@ void should_find_studies_in_filtered_preferred_regions() {
eq(expectedRegions)))
.willReturn((long) studies.size());
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getMyPreferredRegionStudies(
Expand Down Expand Up @@ -247,6 +262,8 @@ void should_return_empty_when_no_preferred_regions() {
eq(Collections.emptyList())))
.willReturn(0L);
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getMyPreferredRegionStudies(
Expand Down Expand Up @@ -289,6 +306,8 @@ void should_find_studies_in_all_preferred_regions_when_no_filter() {
eq(preferredCategory)))
.willReturn((long) studies.size());
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getMyPreferredCategoryStudies(
Expand Down Expand Up @@ -320,6 +339,8 @@ void should_return_empty_when_no_preferred_regions() {
eq(Collections.emptyList())))
.willReturn(0L);
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getMyPreferredCategoryStudies(
Expand Down Expand Up @@ -356,6 +377,8 @@ void should_not_fetch_popular_when_enough_preferred_studies() {
given(studyQueryRepository.findRecruitingStudiesByCategories(preferredCategories, 20))
.willReturn(candidates);
given(studyLikeRepository.findStudyIdsByMemberId(memberId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(memberId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getRecommendedStudies(memberId);
Expand Down Expand Up @@ -384,6 +407,8 @@ void should_fill_with_popular_studies_when_not_enough_preferred() {
List.of(preferredStudies.getFirst().getId()), 2))
.willReturn(popularStudies);
given(studyLikeRepository.findStudyIdsByMemberId(memberId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(memberId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getRecommendedStudies(memberId);
Expand All @@ -406,6 +431,8 @@ void should_return_popular_studies_when_no_preferred_categories() {
given(studyQueryRepository.findPopularRecruitingStudies(Collections.emptyList(), 3))
.willReturn(popularStudies);
given(studyLikeRepository.findStudyIdsByMemberId(memberId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(memberId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getRecommendedStudies(memberId);
Expand All @@ -430,6 +457,8 @@ void should_return_empty_when_no_studies_at_all() {
given(studyQueryRepository.findPopularRecruitingStudies(Collections.emptyList(), 3))
.willReturn(Collections.emptyList());
given(studyLikeRepository.findStudyIdsByMemberId(memberId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(memberId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getRecommendedStudies(memberId);
Expand Down Expand Up @@ -464,6 +493,8 @@ void should_find_recruiting_studies_with_filters() {
eq(FeeCategory.NONE), eq(List.of(Category.LANGUAGE)), eq(true)))
.willReturn((long) studies.size());
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getRecruitingStudies(
Expand Down Expand Up @@ -491,6 +522,8 @@ void should_find_recruiting_studies_without_filters() {
given(studyQueryRepository.countRecruitingStudies(eq(null), eq(null), eq(null)))
.willReturn((long) studies.size());
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getRecruitingStudies(
Expand All @@ -515,6 +548,8 @@ void should_mark_liked_studies() {
given(studyQueryRepository.countRecruitingStudies(any(), any(), any()))
.willReturn((long) studies.size());
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of(likedStudyId));
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getRecruitingStudies(
Expand Down Expand Up @@ -550,6 +585,8 @@ void should_find_studies_by_category() {
eq(RecruitingStatus.RECRUITING), eq(FeeCategory.NONE), eq(Category.LANGUAGE), eq(false)))
.willReturn((long) studies.size());
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getStudiesByCategory(
Expand All @@ -576,6 +613,8 @@ void should_return_empty_when_no_studies() {
given(studyQueryRepository.countStudiesByCategory(any(), any(), any(), any()))
.willReturn(0L);
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getStudiesByCategory(
Expand Down Expand Up @@ -612,6 +651,8 @@ void should_find_liked_studies() {
given(studyQueryRepository.countLikedStudies(viewerId))
.willReturn((long) studies.size());
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(likedStudyIds);
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getLikedStudies(viewerId, null,
Expand All @@ -634,6 +675,8 @@ void should_return_empty_when_no_liked_studies() {
given(studyQueryRepository.countLikedStudies(viewerId))
.willReturn(0L);
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getLikedStudies(viewerId, null,
Expand All @@ -658,6 +701,8 @@ void should_find_next_page_with_cursor() {
given(studyQueryRepository.countLikedStudies(viewerId))
.willReturn(15L);
given(studyLikeRepository.findStudyIdsByMemberId(viewerId)).willReturn(Set.of());
given(studyMemberRepository.findStudyIdsByMemberIdAndStudyMemberStatus(viewerId,
StudyMemberStatus.OWNER)).willReturn(Set.of());

// when
GetStudyOverviewResponse response = getMyStudyInfoService.getLikedStudies(viewerId, cursor,
Expand Down