Skip to content

Commit

Permalink
일정 조회가 되지 않는 현상 해결 (#373)
Browse files Browse the repository at this point in the history
* fix: 스케줄에 자신이 등록한 일정이나 자신이 포함된 활동 관련 일정도 포함되도록 수정 #371

* refactor: groupList와 groupMembers 생성 방식 변경 #371

* refactor: 사용하지 않는 import문 제거 #371

* refactor: MyGroups 생성 과정 중 distinct() 부분 제거 #371

* refactor: myGroupList에서 myGroups로 이름 변경 #371
  • Loading branch information
SongJaeHoonn authored Jun 11, 2024
1 parent dd815b1 commit 7ac4c49
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,7 +54,9 @@ public Long createSchedule(ScheduleRequestDto requestDto) throws PermissionDenie
@Transactional(readOnly = true)
public PagedResponseDto<ScheduleResponseDto> getSchedulesWithinDateRange(LocalDate startDate, LocalDate endDate, Pageable pageable) {
Member currentMember = memberService.getCurrentMember();
Page<Schedule> schedules = scheduleRepository.findByDateRangeAndMember(startDate, endDate, currentMember, pageable);
List<GroupMember> groupMembers = activityGroupMemberService.getGroupMemberByMember(currentMember);
List<ActivityGroup> myGroups = getMyActivityGroups(groupMembers);
Page<Schedule> schedules = scheduleRepository.findByDateRangeAndMember(startDate, endDate, myGroups, pageable);
return new PagedResponseDto<>(schedules.map(ScheduleResponseDto::toDto));
}

Expand Down Expand Up @@ -110,4 +114,10 @@ public Schedule getScheduleById(Long scheduleId) {
.orElseThrow(() -> new NotFoundException("일정이 존재하지 않습니다."));
}

public List<ActivityGroup> getMyActivityGroups(List<GroupMember> groupMembers) {
return groupMembers.stream()
.map(GroupMember::getActivityGroup)
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Schedule> findByDateRangeAndMember(LocalDate startDate, LocalDate endDate, Member member, Pageable pageable);
Page<Schedule> findByDateRangeAndMember(LocalDate startDate, LocalDate endDate, List<ActivityGroup> myGroups, Pageable pageable);

Page<Schedule> findByConditions(Integer year, Integer month, SchedulePriority priority, Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,16 +27,22 @@ public class ScheduleRepositoryImpl implements ScheduleRepositoryCustom {
private final JPAQueryFactory queryFactory;

@Override
public Page<Schedule> findByDateRangeAndMember(LocalDate startDate, LocalDate endDate, Member member, Pageable pageable) {
public Page<Schedule> findByDateRangeAndMember(LocalDate startDate, LocalDate endDate, List<ActivityGroup> myGroups, Pageable pageable) {
QSchedule schedule = QSchedule.schedule;
BooleanBuilder builder = new BooleanBuilder();

LocalDateTime startDateTime = startDate.atStartOfDay();
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<Schedule> results = queryFactory.selectFrom(schedule)
.where(builder)
Expand Down

0 comments on commit 7ac4c49

Please sign in to comment.