Skip to content
This repository was archived by the owner on Jan 11, 2026. It is now read-only.
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
@@ -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<Study> searchByTitle(String keyword, StudySortBy sortBy, Pageable pageable);
Expand All @@ -39,7 +34,7 @@ List<Study> findStudyByConditionsAndRegionStudiesAndNotInIds(Map<String, Object>

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

List<Study> findByMemberStudy(List<MemberStudy> memberStudy, Pageable pageable);
List<Study> findByMemberStudiesAndStatus(List<MemberStudy> memberStudy, Pageable pageable, Status status);
List<Study> findRecruitingStudiesByMemberStudy(List<MemberStudy> memberStudy, Pageable pageable);

long countStudyByConditionsAndThemeTypesAndNotInIds(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,22 @@
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;
import java.util.List;
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;
Expand Down Expand Up @@ -262,13 +256,14 @@ public List<Study> findByStudyTheme(List<StudyTheme> studyThemes, StudySortBy so
}

@Override
public List<Study> findByMemberStudy(List<MemberStudy> memberStudy, Pageable pageable) {
public List<Study> findByMemberStudiesAndStatus(List<MemberStudy> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ public StudyPreviewDTO findOngoingStudiesByMemberId(Pageable pageable, Long memb
throw new StudyHandler(ErrorStatus._STUDY_NOT_PARTICIPATED);

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

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

// 회원이 신청한 스터디 조회
List<Study> studies = studyRepository.findByMemberStudy(memberStudies, pageable);

studies.stream().filter(study -> study.getStatus().equals(Status.ON)).toList();
List<Study> studies = studyRepository.findByMemberStudiesAndStatus(memberStudies, pageable, Status.ON);

// 조회된 스터디가 없을 경우
if (studies.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

}

Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);

}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down