From e383106d34ce74ca0c7a39e6d39a7f1051464d4e Mon Sep 17 00:00:00 2001 From: msk226 Date: Mon, 28 Apr 2025 14:22:48 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[SPOT-275][MODIFY]=20=EC=B0=B8=EC=97=AC?= =?UTF-8?q?=EC=A4=91=EC=9D=B8=20=EC=8A=A4=ED=84=B0=EB=94=94=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=9C,=20=EC=A1=B0=ED=9A=8C=ED=95=A0=20?= =?UTF-8?q?=EB=95=8C=20=EB=B6=80=ED=84=B0=20=ED=99=9C=EC=84=B1=ED=99=94=20?= =?UTF-8?q?=EB=90=9C=20=EC=8A=A4=ED=84=B0=EB=94=94=EB=A7=8C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../querydsl/StudyRepositoryCustom.java | 9 ++------- .../impl/StudyRepositoryCustomImpl.java | 19 +++++++------------ .../service/study/StudyQueryServiceImpl.java | 6 ++---- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/example/spot/repository/querydsl/StudyRepositoryCustom.java b/src/main/java/com/example/spot/repository/querydsl/StudyRepositoryCustom.java index 0dfcd95b..e822a9ce 100644 --- a/src/main/java/com/example/spot/repository/querydsl/StudyRepositoryCustom.java +++ b/src/main/java/com/example/spot/repository/querydsl/StudyRepositoryCustom.java @@ -1,20 +1,15 @@ package com.example.spot.repository.querydsl; -import com.example.spot.domain.Theme; import com.example.spot.domain.enums.Status; import com.example.spot.domain.enums.StudySortBy; -import com.example.spot.domain.enums.StudyState; -import com.example.spot.domain.enums.ThemeType; import com.example.spot.domain.mapping.MemberStudy; import com.example.spot.domain.mapping.RegionStudy; import com.example.spot.domain.mapping.StudyTheme; import com.example.spot.domain.study.Study; import java.util.List; import java.util.Map; -import org.springframework.data.domain.Page; + import org.springframework.data.domain.Pageable; -import org.springframework.data.jdbc.repository.query.Query; -import org.springframework.data.repository.query.Param; public interface StudyRepositoryCustom { List searchByTitle(String keyword, StudySortBy sortBy, Pageable pageable); @@ -39,7 +34,7 @@ List findStudyByConditionsAndRegionStudiesAndNotInIds(Map List findByStudyTheme(List studyTheme, StudySortBy sortBy, Pageable pageable); - List findByMemberStudy(List memberStudy, Pageable pageable); + List findByMemberStudiesAndStatus(List memberStudy, Pageable pageable, Status status); List findRecruitingStudiesByMemberStudy(List memberStudy, Pageable pageable); long countStudyByConditionsAndThemeTypesAndNotInIds( diff --git a/src/main/java/com/example/spot/repository/querydsl/impl/StudyRepositoryCustomImpl.java b/src/main/java/com/example/spot/repository/querydsl/impl/StudyRepositoryCustomImpl.java index 1766a367..f30e8720 100644 --- a/src/main/java/com/example/spot/repository/querydsl/impl/StudyRepositoryCustomImpl.java +++ b/src/main/java/com/example/spot/repository/querydsl/impl/StudyRepositoryCustomImpl.java @@ -5,20 +5,14 @@ import com.example.spot.domain.enums.Status; import com.example.spot.domain.enums.StudySortBy; import com.example.spot.domain.enums.StudyState; -import com.example.spot.domain.enums.Theme; import com.example.spot.domain.enums.ThemeType; import com.example.spot.domain.mapping.MemberStudy; -import com.example.spot.domain.mapping.QMemberStudy; -import com.example.spot.domain.mapping.QRegionStudy; -import com.example.spot.domain.mapping.QStudyTheme; import com.example.spot.domain.mapping.RegionStudy; import com.example.spot.domain.mapping.StudyTheme; import com.example.spot.domain.study.QStudy; import com.example.spot.domain.study.Study; import com.example.spot.repository.querydsl.StudyRepositoryCustom; import com.querydsl.core.BooleanBuilder; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.jpa.JPAExpressions; import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; import jakarta.persistence.EntityManager; @@ -26,7 +20,7 @@ import java.util.Map; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.data.domain.Page; + import org.springframework.data.domain.Pageable; import static com.example.spot.domain.study.QStudy.study; @@ -262,13 +256,14 @@ public List findByStudyTheme(List studyThemes, StudySortBy so } @Override - public List findByMemberStudy(List memberStudy, Pageable pageable) { + public List findByMemberStudiesAndStatus(List memberStudy, Pageable pageable, Status status) { QStudy study = QStudy.study; return queryFactory.selectFrom(study) - .where(study.memberStudies.any().in(memberStudy)) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - .fetch(); + .where(study.memberStudies.any().in(memberStudy)) + .where(study.status.eq(Status.ON)) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); } @Override diff --git a/src/main/java/com/example/spot/service/study/StudyQueryServiceImpl.java b/src/main/java/com/example/spot/service/study/StudyQueryServiceImpl.java index ab48d423..2c498cfb 100644 --- a/src/main/java/com/example/spot/service/study/StudyQueryServiceImpl.java +++ b/src/main/java/com/example/spot/service/study/StudyQueryServiceImpl.java @@ -745,7 +745,7 @@ public StudyPreviewDTO findOngoingStudiesByMemberId(Pageable pageable, Long memb throw new StudyHandler(ErrorStatus._STUDY_NOT_PARTICIPATED); // 회원이 참가하고 있는 스터디 조회 - List studies = studyRepository.findByMemberStudy(memberStudies, pageable); + List studies = studyRepository.findByMemberStudiesAndStatus(memberStudies, pageable, Status.ON); // 스터디가 끝났으면 제외 studies = studies.stream() @@ -784,9 +784,7 @@ public StudyPreviewDTO findAppliedStudies(Pageable pageable, Long memberId) { throw new StudyHandler(ErrorStatus._STUDY_NOT_APPLIED); // 회원이 신청한 스터디 조회 - List studies = studyRepository.findByMemberStudy(memberStudies, pageable); - - studies.stream().filter(study -> study.getStatus().equals(Status.ON)).toList(); + List studies = studyRepository.findByMemberStudiesAndStatus(memberStudies, pageable, Status.ON); // 조회된 스터디가 없을 경우 if (studies.isEmpty()) From 3ae7b52e2ce9a3bca2229872c2fa3088bbc66b86 Mon Sep 17 00:00:00 2001 From: msk226 Date: Mon, 28 Apr 2025 14:23:09 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[SPOT-275][MODIFY]=20=EC=BF=BC=EB=A6=AC=20?= =?UTF-8?q?=EB=B0=8F=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=8B=9C=EA=B7=B8?= =?UTF-8?q?=EB=8B=88=EC=B2=98=20=EB=B3=80=EA=B2=BD=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spot/service/study/StudyQueryServiceTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/example/spot/service/study/StudyQueryServiceTest.java b/src/test/java/com/example/spot/service/study/StudyQueryServiceTest.java index 96f1e239..b7a029c3 100644 --- a/src/test/java/com/example/spot/service/study/StudyQueryServiceTest.java +++ b/src/test/java/com/example/spot/service/study/StudyQueryServiceTest.java @@ -1679,7 +1679,7 @@ void findOngoingStudiesByMemberId() { when(memberStudyRepository.findAllByMemberIdAndStatus(member.getId(), ApplicationStatus.APPROVED)) .thenReturn(List.of(memberStudy1, memberStudy2)); - when(studyRepository.findByMemberStudy(List.of(memberStudy1, memberStudy2), pageable)) + when(studyRepository.findByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), pageable, Status.ON)) .thenReturn(List.of(study1, study2)); when(studyRepository.countByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), Status.ON)) .thenReturn(2L); @@ -1691,7 +1691,7 @@ void findOngoingStudiesByMemberId() { assertNotNull(result); assertEquals(2, result.getTotalElements()); verify(memberStudyRepository).findAllByMemberIdAndStatus(member.getId(), ApplicationStatus.APPROVED); - verify(studyRepository).findByMemberStudy(List.of(memberStudy1, memberStudy2), pageable); + verify(studyRepository).findByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), pageable, Status.ON); } @@ -1717,7 +1717,7 @@ void findOngoingStudiesByMemberId() { when(memberStudyRepository.findAllByMemberIdAndStatus(member.getId(), ApplicationStatus.APPROVED)) .thenReturn(List.of(memberStudy1, memberStudy2)); - when(studyRepository.findByMemberStudy(List.of(memberStudy1, memberStudy2), pageable)) + when(studyRepository.findByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), pageable, Status.ON)) .thenReturn(List.of()); // when & then @@ -1737,7 +1737,7 @@ void findAppliedStudies() { when(memberStudyRepository.findAllByMemberIdAndStatus(member.getId(), ApplicationStatus.APPLIED)) .thenReturn(List.of(memberStudy1, memberStudy2)); - when(studyRepository.findByMemberStudy(List.of(memberStudy1, memberStudy2), pageable)) + when(studyRepository.findByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), pageable, Status.ON)) .thenReturn(List.of(study1, study2)); when(studyRepository.countByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), Status.ON)) .thenReturn(2L); @@ -1749,7 +1749,7 @@ void findAppliedStudies() { assertNotNull(result); assertEquals(2, result.getTotalElements()); verify(memberStudyRepository).findAllByMemberIdAndStatus(member.getId(), ApplicationStatus.APPLIED); - verify(studyRepository).findByMemberStudy(List.of(memberStudy1, memberStudy2), pageable); + verify(studyRepository).findByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), pageable, Status.ON); } @@ -1774,7 +1774,7 @@ void findAppliedStudies() { // given when(memberStudyRepository.findAllByMemberIdAndStatus(member.getId(), ApplicationStatus.APPLIED)) .thenReturn(List.of(memberStudy1, memberStudy2)); - when(studyRepository.findByMemberStudy(List.of(memberStudy1, memberStudy2), pageable)) + when(studyRepository.findByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), pageable, Status.ON)) .thenReturn(List.of()); // when & then @@ -1833,7 +1833,7 @@ void findMyRecruitingStudies() { when(memberStudyRepository.findAllByMemberIdAndIsOwned(member.getId(), true)) .thenReturn(List.of(memberStudy1, memberStudy2)); - when(studyRepository.findByMemberStudy(List.of(memberStudy1, memberStudy2), pageable)) + when(studyRepository.findByMemberStudiesAndStatus(List.of(memberStudy1, memberStudy2), pageable, Status.ON)) .thenReturn(List.of()); // when & then