diff --git a/src/main/java/page/clab/api/domain/schedule/application/ScheduleService.java b/src/main/java/page/clab/api/domain/schedule/application/ScheduleService.java index 2263bf238..87353be65 100644 --- a/src/main/java/page/clab/api/domain/schedule/application/ScheduleService.java +++ b/src/main/java/page/clab/api/domain/schedule/application/ScheduleService.java @@ -25,7 +25,9 @@ import page.clab.api.global.exception.PermissionDeniedException; import java.time.LocalDate; +import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor @@ -52,7 +54,9 @@ public Long createSchedule(ScheduleRequestDto requestDto) throws PermissionDenie @Transactional(readOnly = true) public PagedResponseDto getSchedulesWithinDateRange(LocalDate startDate, LocalDate endDate, Pageable pageable) { Member currentMember = memberService.getCurrentMember(); - Page schedules = scheduleRepository.findByDateRangeAndMember(startDate, endDate, currentMember, pageable); + List groupMembers = activityGroupMemberService.getGroupMemberByMember(currentMember); + List myGroups = getMyActivityGroups(groupMembers); + Page schedules = scheduleRepository.findByDateRangeAndMember(startDate, endDate, myGroups, pageable); return new PagedResponseDto<>(schedules.map(ScheduleResponseDto::toDto)); } @@ -110,4 +114,10 @@ public Schedule getScheduleById(Long scheduleId) { .orElseThrow(() -> new NotFoundException("일정이 존재하지 않습니다.")); } + public List getMyActivityGroups(List groupMembers) { + return groupMembers.stream() + .map(GroupMember::getActivityGroup) + .collect(Collectors.toList()); + } + } diff --git a/src/main/java/page/clab/api/domain/schedule/dao/ScheduleRepositoryCustom.java b/src/main/java/page/clab/api/domain/schedule/dao/ScheduleRepositoryCustom.java index 2f1a564a4..889331265 100644 --- a/src/main/java/page/clab/api/domain/schedule/dao/ScheduleRepositoryCustom.java +++ b/src/main/java/page/clab/api/domain/schedule/dao/ScheduleRepositoryCustom.java @@ -2,16 +2,18 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import page.clab.api.domain.activityGroup.domain.ActivityGroup; import page.clab.api.domain.member.domain.Member; import page.clab.api.domain.schedule.domain.Schedule; import page.clab.api.domain.schedule.domain.SchedulePriority; import page.clab.api.domain.schedule.dto.response.ScheduleCollectResponseDto; import java.time.LocalDate; +import java.util.List; public interface ScheduleRepositoryCustom { - Page findByDateRangeAndMember(LocalDate startDate, LocalDate endDate, Member member, Pageable pageable); + Page findByDateRangeAndMember(LocalDate startDate, LocalDate endDate, List myGroups, Pageable pageable); Page findByConditions(Integer year, Integer month, SchedulePriority priority, Pageable pageable); diff --git a/src/main/java/page/clab/api/domain/schedule/dao/ScheduleRepositoryImpl.java b/src/main/java/page/clab/api/domain/schedule/dao/ScheduleRepositoryImpl.java index 1f25c4c70..dba084bc5 100644 --- a/src/main/java/page/clab/api/domain/schedule/dao/ScheduleRepositoryImpl.java +++ b/src/main/java/page/clab/api/domain/schedule/dao/ScheduleRepositoryImpl.java @@ -2,12 +2,12 @@ import com.querydsl.core.BooleanBuilder; import com.querydsl.jpa.impl.JPAQueryFactory; -import java.util.ArrayList; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; +import page.clab.api.domain.activityGroup.domain.ActivityGroup; import page.clab.api.domain.member.domain.Member; import page.clab.api.domain.schedule.domain.QSchedule; import page.clab.api.domain.schedule.domain.Schedule; @@ -27,7 +27,7 @@ public class ScheduleRepositoryImpl implements ScheduleRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public Page findByDateRangeAndMember(LocalDate startDate, LocalDate endDate, Member member, Pageable pageable) { + public Page findByDateRangeAndMember(LocalDate startDate, LocalDate endDate, List myGroups, Pageable pageable) { QSchedule schedule = QSchedule.schedule; BooleanBuilder builder = new BooleanBuilder(); @@ -35,8 +35,14 @@ public Page findByDateRangeAndMember(LocalDate startDate, LocalDate en LocalDateTime endDateTime = endDate.atTime(23, 59, 59); builder.and(schedule.endDateTime.goe(startDateTime)) - .and(schedule.startDateTime.loe(endDateTime)) - .and(schedule.scheduleWriter.eq(member)); + .and(schedule.startDateTime.loe(endDateTime)); + + if (myGroups != null && !myGroups.isEmpty()) { + builder.and(schedule.activityGroup.isNull() + .or(schedule.activityGroup.in(myGroups))); + } else { + builder.and(schedule.activityGroup.isNull()); + } List results = queryFactory.selectFrom(schedule) .where(builder)