Skip to content
This repository was archived by the owner on Jan 11, 2026. It is now read-only.

Commit ef6c53b

Browse files
authored
[MERGE] Merge pull request #420 from SPOTeam/SPOT-275/modify
[MODIFY] 참여중인 스터디 조회 쿼리 수정
2 parents 4bd74b5 + 3ae7b52 commit ef6c53b

4 files changed

Lines changed: 18 additions & 30 deletions

File tree

src/main/java/com/example/spot/repository/querydsl/StudyRepositoryCustom.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
package com.example.spot.repository.querydsl;
22

3-
import com.example.spot.domain.Theme;
43
import com.example.spot.domain.enums.Status;
54
import com.example.spot.domain.enums.StudySortBy;
6-
import com.example.spot.domain.enums.StudyState;
7-
import com.example.spot.domain.enums.ThemeType;
85
import com.example.spot.domain.mapping.MemberStudy;
96
import com.example.spot.domain.mapping.RegionStudy;
107
import com.example.spot.domain.mapping.StudyTheme;
118
import com.example.spot.domain.study.Study;
129
import java.util.List;
1310
import java.util.Map;
14-
import org.springframework.data.domain.Page;
11+
1512
import org.springframework.data.domain.Pageable;
16-
import org.springframework.data.jdbc.repository.query.Query;
17-
import org.springframework.data.repository.query.Param;
1813

1914
public interface StudyRepositoryCustom {
2015
List<Study> searchByTitle(String keyword, StudySortBy sortBy, Pageable pageable);
@@ -39,7 +34,7 @@ List<Study> findStudyByConditionsAndRegionStudiesAndNotInIds(Map<String, Object>
3934

4035
List<Study> findByStudyTheme(List<StudyTheme> studyTheme, StudySortBy sortBy, Pageable pageable);
4136

42-
List<Study> findByMemberStudy(List<MemberStudy> memberStudy, Pageable pageable);
37+
List<Study> findByMemberStudiesAndStatus(List<MemberStudy> memberStudy, Pageable pageable, Status status);
4338
List<Study> findRecruitingStudiesByMemberStudy(List<MemberStudy> memberStudy, Pageable pageable);
4439

4540
long countStudyByConditionsAndThemeTypesAndNotInIds(

src/main/java/com/example/spot/repository/querydsl/impl/StudyRepositoryCustomImpl.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,22 @@
55
import com.example.spot.domain.enums.Status;
66
import com.example.spot.domain.enums.StudySortBy;
77
import com.example.spot.domain.enums.StudyState;
8-
import com.example.spot.domain.enums.Theme;
98
import com.example.spot.domain.enums.ThemeType;
109
import com.example.spot.domain.mapping.MemberStudy;
11-
import com.example.spot.domain.mapping.QMemberStudy;
12-
import com.example.spot.domain.mapping.QRegionStudy;
13-
import com.example.spot.domain.mapping.QStudyTheme;
1410
import com.example.spot.domain.mapping.RegionStudy;
1511
import com.example.spot.domain.mapping.StudyTheme;
1612
import com.example.spot.domain.study.QStudy;
1713
import com.example.spot.domain.study.Study;
1814
import com.example.spot.repository.querydsl.StudyRepositoryCustom;
1915
import com.querydsl.core.BooleanBuilder;
20-
import com.querydsl.core.types.dsl.Expressions;
21-
import com.querydsl.jpa.JPAExpressions;
2216
import com.querydsl.jpa.impl.JPAQuery;
2317
import com.querydsl.jpa.impl.JPAQueryFactory;
2418
import jakarta.persistence.EntityManager;
2519
import java.util.List;
2620
import java.util.Map;
2721
import lombok.RequiredArgsConstructor;
2822
import lombok.extern.slf4j.Slf4j;
29-
import org.springframework.data.domain.Page;
23+
3024
import org.springframework.data.domain.Pageable;
3125

3226
import static com.example.spot.domain.study.QStudy.study;
@@ -262,13 +256,14 @@ public List<Study> findByStudyTheme(List<StudyTheme> studyThemes, StudySortBy so
262256
}
263257

264258
@Override
265-
public List<Study> findByMemberStudy(List<MemberStudy> memberStudy, Pageable pageable) {
259+
public List<Study> findByMemberStudiesAndStatus(List<MemberStudy> memberStudy, Pageable pageable, Status status) {
266260
QStudy study = QStudy.study;
267261
return queryFactory.selectFrom(study)
268-
.where(study.memberStudies.any().in(memberStudy))
269-
.offset(pageable.getOffset())
270-
.limit(pageable.getPageSize())
271-
.fetch();
262+
.where(study.memberStudies.any().in(memberStudy))
263+
.where(study.status.eq(Status.ON))
264+
.offset(pageable.getOffset())
265+
.limit(pageable.getPageSize())
266+
.fetch();
272267
}
273268

274269
@Override

src/main/java/com/example/spot/service/study/StudyQueryServiceImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ public StudyPreviewDTO findOngoingStudiesByMemberId(Pageable pageable, Long memb
745745
throw new StudyHandler(ErrorStatus._STUDY_NOT_PARTICIPATED);
746746

747747
// 회원이 참가하고 있는 스터디 조회
748-
List<Study> studies = studyRepository.findByMemberStudy(memberStudies, pageable);
748+
List<Study> studies = studyRepository.findByMemberStudiesAndStatus(memberStudies, pageable, Status.ON);
749749

750750
// 스터디가 끝났으면 제외
751751
studies = studies.stream()
@@ -784,9 +784,7 @@ public StudyPreviewDTO findAppliedStudies(Pageable pageable, Long memberId) {
784784
throw new StudyHandler(ErrorStatus._STUDY_NOT_APPLIED);
785785

786786
// 회원이 신청한 스터디 조회
787-
List<Study> studies = studyRepository.findByMemberStudy(memberStudies, pageable);
788-
789-
studies.stream().filter(study -> study.getStatus().equals(Status.ON)).toList();
787+
List<Study> studies = studyRepository.findByMemberStudiesAndStatus(memberStudies, pageable, Status.ON);
790788

791789
// 조회된 스터디가 없을 경우
792790
if (studies.isEmpty())

src/test/java/com/example/spot/service/study/StudyQueryServiceTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,7 @@ void findOngoingStudiesByMemberId() {
16791679

16801680
when(memberStudyRepository.findAllByMemberIdAndStatus(member.getId(), ApplicationStatus.APPROVED))
16811681
.thenReturn(List.of(memberStudy1, memberStudy2));
1682-
when(studyRepository.findByMemberStudy(List.of(memberStudy1, memberStudy2), pageable))
1682+
when(studyRepository.findByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), pageable, Status.ON))
16831683
.thenReturn(List.of(study1, study2));
16841684
when(studyRepository.countByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), Status.ON))
16851685
.thenReturn(2L);
@@ -1691,7 +1691,7 @@ void findOngoingStudiesByMemberId() {
16911691
assertNotNull(result);
16921692
assertEquals(2, result.getTotalElements());
16931693
verify(memberStudyRepository).findAllByMemberIdAndStatus(member.getId(), ApplicationStatus.APPROVED);
1694-
verify(studyRepository).findByMemberStudy(List.of(memberStudy1, memberStudy2), pageable);
1694+
verify(studyRepository).findByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), pageable, Status.ON);
16951695

16961696
}
16971697

@@ -1717,7 +1717,7 @@ void findOngoingStudiesByMemberId() {
17171717

17181718
when(memberStudyRepository.findAllByMemberIdAndStatus(member.getId(), ApplicationStatus.APPROVED))
17191719
.thenReturn(List.of(memberStudy1, memberStudy2));
1720-
when(studyRepository.findByMemberStudy(List.of(memberStudy1, memberStudy2), pageable))
1720+
when(studyRepository.findByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), pageable, Status.ON))
17211721
.thenReturn(List.of());
17221722

17231723
// when & then
@@ -1737,7 +1737,7 @@ void findAppliedStudies() {
17371737

17381738
when(memberStudyRepository.findAllByMemberIdAndStatus(member.getId(), ApplicationStatus.APPLIED))
17391739
.thenReturn(List.of(memberStudy1, memberStudy2));
1740-
when(studyRepository.findByMemberStudy(List.of(memberStudy1, memberStudy2), pageable))
1740+
when(studyRepository.findByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), pageable, Status.ON))
17411741
.thenReturn(List.of(study1, study2));
17421742
when(studyRepository.countByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), Status.ON))
17431743
.thenReturn(2L);
@@ -1749,7 +1749,7 @@ void findAppliedStudies() {
17491749
assertNotNull(result);
17501750
assertEquals(2, result.getTotalElements());
17511751
verify(memberStudyRepository).findAllByMemberIdAndStatus(member.getId(), ApplicationStatus.APPLIED);
1752-
verify(studyRepository).findByMemberStudy(List.of(memberStudy1, memberStudy2), pageable);
1752+
verify(studyRepository).findByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), pageable, Status.ON);
17531753

17541754
}
17551755

@@ -1774,7 +1774,7 @@ void findAppliedStudies() {
17741774
// given
17751775
when(memberStudyRepository.findAllByMemberIdAndStatus(member.getId(), ApplicationStatus.APPLIED))
17761776
.thenReturn(List.of(memberStudy1, memberStudy2));
1777-
when(studyRepository.findByMemberStudy(List.of(memberStudy1, memberStudy2), pageable))
1777+
when(studyRepository.findByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), pageable, Status.ON))
17781778
.thenReturn(List.of());
17791779

17801780
// when & then
@@ -1833,7 +1833,7 @@ void findMyRecruitingStudies() {
18331833

18341834
when(memberStudyRepository.findAllByMemberIdAndIsOwned(member.getId(), true))
18351835
.thenReturn(List.of(memberStudy1, memberStudy2));
1836-
when(studyRepository.findByMemberStudy(List.of(memberStudy1, memberStudy2), pageable))
1836+
when(studyRepository.findByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), pageable, Status.ON))
18371837
.thenReturn(List.of());
18381838

18391839
// when & then

0 commit comments

Comments
 (0)