Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

일정 조회가 되지 않는 현상 해결 #373

Merged
merged 5 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -8,6 +8,7 @@
import org.springframework.transaction.annotation.Transactional;
import page.clab.api.domain.activityGroup.application.ActivityGroupAdminService;
import page.clab.api.domain.activityGroup.application.ActivityGroupMemberService;
import page.clab.api.domain.activityGroup.dao.GroupMemberRepository;
import page.clab.api.domain.activityGroup.domain.ActivityGroup;
import page.clab.api.domain.activityGroup.domain.ActivityGroupRole;
import page.clab.api.domain.activityGroup.domain.GroupMember;
Expand All @@ -25,6 +26,8 @@
import page.clab.api.global.exception.PermissionDeniedException;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
Expand All @@ -40,6 +43,8 @@ public class ScheduleService {

private final ScheduleRepository scheduleRepository;

private final GroupMemberRepository groupMemberRepository;

@Transactional
public Long createSchedule(ScheduleRequestDto requestDto) throws PermissionDeniedException {
Member currentMember = memberService.getCurrentMember();
Expand All @@ -52,7 +57,12 @@ 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 = groupMemberRepository.findAllByMember(currentMember);
List<ActivityGroup> myGroupList = new ArrayList<>();
limehee marked this conversation as resolved.
Show resolved Hide resolved
for (GroupMember groupMember : groupMembers) {
myGroupList.add(groupMember.getActivityGroup());
limehee marked this conversation as resolved.
Show resolved Hide resolved
}
Page<Schedule> schedules = scheduleRepository.findByDateRangeAndMember(startDate, endDate, myGroupList, pageable);
limehee marked this conversation as resolved.
Show resolved Hide resolved
return new PagedResponseDto<>(schedules.map(ScheduleResponseDto::toDto));
}

Expand Down
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> myGroupList, Pageable pageable);

limehee marked this conversation as resolved.
Show resolved Hide resolved
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> myGroupList, 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 (myGroupList != null && !myGroupList.isEmpty()) {
builder.and(schedule.activityGroup.isNull()
.or(schedule.activityGroup.in(myGroupList)));
} else {
builder.and(schedule.activityGroup.isNull());
}

List<Schedule> results = queryFactory.selectFrom(schedule)
.where(builder)
Expand Down