From 447ba46d69868621d131b76cc0e6ca77dd2bff04 Mon Sep 17 00:00:00 2001 From: JaeHoonSong <128021502+SongJaeHoonn@users.noreply.github.com> Date: Tue, 11 Jun 2024 18:16:25 +0900 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=EC=8A=A4=EC=BC=80=EC=A4=84=EC=97=90?= =?UTF-8?q?=20=EC=9E=90=EC=8B=A0=EC=9D=B4=20=EB=93=B1=EB=A1=9D=ED=95=9C=20?= =?UTF-8?q?=EC=9D=BC=EC=A0=95=EC=9D=B4=EB=82=98=20=EC=9E=90=EC=8B=A0?= =?UTF-8?q?=EC=9D=B4=20=ED=8F=AC=ED=95=A8=EB=90=9C=20=ED=99=9C=EB=8F=99=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=9D=BC=EC=A0=95=EB=8F=84=20=ED=8F=AC?= =?UTF-8?q?=ED=95=A8=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=20#37?= =?UTF-8?q?1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../schedule/application/ScheduleService.java | 12 +++++++++++- .../schedule/dao/ScheduleRepositoryCustom.java | 4 +++- .../schedule/dao/ScheduleRepositoryImpl.java | 14 ++++++++++---- 3 files changed, 24 insertions(+), 6 deletions(-) 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..8cb3887f0 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 @@ -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; @@ -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 @@ -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(); @@ -52,7 +57,12 @@ 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 = groupMemberRepository.findAllByMember(currentMember); + List myGroupList = new ArrayList<>(); + for (GroupMember groupMember : groupMembers) { + myGroupList.add(groupMember.getActivityGroup()); + } + Page schedules = scheduleRepository.findByDateRangeAndMember(startDate, endDate, myGroupList, pageable); return new PagedResponseDto<>(schedules.map(ScheduleResponseDto::toDto)); } 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..3762938bf 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 myGroupList, 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..8a86d5cc8 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 myGroupList, 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 (myGroupList != null && !myGroupList.isEmpty()) { + builder.and(schedule.activityGroup.isNull() + .or(schedule.activityGroup.in(myGroupList))); + } else { + builder.and(schedule.activityGroup.isNull()); + } List results = queryFactory.selectFrom(schedule) .where(builder) From 3234696d24a33b32a113ad0725db308e34131d1e Mon Sep 17 00:00:00 2001 From: JaeHoonSong <128021502+SongJaeHoonn@users.noreply.github.com> Date: Tue, 11 Jun 2024 20:18:10 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20groupList=EC=99=80=20groupMembe?= =?UTF-8?q?rs=20=EC=83=9D=EC=84=B1=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20#371?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../schedule/application/ScheduleService.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) 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 8cb3887f0..7cb647010 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 @@ -2,13 +2,13 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; 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; @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor @@ -43,8 +44,6 @@ public class ScheduleService { private final ScheduleRepository scheduleRepository; - private final GroupMemberRepository groupMemberRepository; - @Transactional public Long createSchedule(ScheduleRequestDto requestDto) throws PermissionDeniedException { Member currentMember = memberService.getCurrentMember(); @@ -57,12 +56,9 @@ public Long createSchedule(ScheduleRequestDto requestDto) throws PermissionDenie @Transactional(readOnly = true) public PagedResponseDto getSchedulesWithinDateRange(LocalDate startDate, LocalDate endDate, Pageable pageable) { Member currentMember = memberService.getCurrentMember(); - List groupMembers = groupMemberRepository.findAllByMember(currentMember); - List myGroupList = new ArrayList<>(); - for (GroupMember groupMember : groupMembers) { - myGroupList.add(groupMember.getActivityGroup()); - } - Page schedules = scheduleRepository.findByDateRangeAndMember(startDate, endDate, myGroupList, 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)); } @@ -120,4 +116,11 @@ public Schedule getScheduleById(Long scheduleId) { .orElseThrow(() -> new NotFoundException("일정이 존재하지 않습니다.")); } + public List getMyActivityGroups(List groupMembers) { + return groupMembers.stream() + .map(GroupMember::getActivityGroup) + .distinct() + .collect(Collectors.toList()); + } + } From 4ac03c712c4ddf5258d36055a34eee0526ca5251 Mon Sep 17 00:00:00 2001 From: JaeHoonSong <128021502+SongJaeHoonn@users.noreply.github.com> Date: Tue, 11 Jun 2024 20:21:18 +0900 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20import=EB=AC=B8=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20#371?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../clab/api/domain/schedule/application/ScheduleService.java | 2 -- 1 file changed, 2 deletions(-) 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 7cb647010..a339af74d 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 @@ -2,7 +2,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.jetbrains.annotations.NotNull; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -26,7 +25,6 @@ import page.clab.api.global.exception.PermissionDeniedException; import java.time.LocalDate; -import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; From b1bdd496717bd98e235dd002b2c0e00166099123 Mon Sep 17 00:00:00 2001 From: JaeHoonSong <128021502+SongJaeHoonn@users.noreply.github.com> Date: Tue, 11 Jun 2024 20:58:32 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20MyGroups=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20=EA=B3=BC=EC=A0=95=20=EC=A4=91=20distinct()=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84=20=EC=A0=9C=EA=B1=B0=20#371?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../clab/api/domain/schedule/application/ScheduleService.java | 1 - 1 file changed, 1 deletion(-) 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 a339af74d..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 @@ -117,7 +117,6 @@ public Schedule getScheduleById(Long scheduleId) { public List getMyActivityGroups(List groupMembers) { return groupMembers.stream() .map(GroupMember::getActivityGroup) - .distinct() .collect(Collectors.toList()); } From 9e47f20dcc02aef12a1f102311950172c1a2b43e Mon Sep 17 00:00:00 2001 From: JaeHoonSong <128021502+SongJaeHoonn@users.noreply.github.com> Date: Tue, 11 Jun 2024 21:02:48 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20myGroupList=EC=97=90=EC=84=9C?= =?UTF-8?q?=20myGroups=EB=A1=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=20#371?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/domain/schedule/dao/ScheduleRepositoryCustom.java | 2 +- .../api/domain/schedule/dao/ScheduleRepositoryImpl.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) 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 3762938bf..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 @@ -13,7 +13,7 @@ public interface ScheduleRepositoryCustom { - Page findByDateRangeAndMember(LocalDate startDate, LocalDate endDate, List myGroupList, 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 8a86d5cc8..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 @@ -27,7 +27,7 @@ public class ScheduleRepositoryImpl implements ScheduleRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public Page findByDateRangeAndMember(LocalDate startDate, LocalDate endDate, List myGroupList, Pageable pageable) { + public Page findByDateRangeAndMember(LocalDate startDate, LocalDate endDate, List myGroups, Pageable pageable) { QSchedule schedule = QSchedule.schedule; BooleanBuilder builder = new BooleanBuilder(); @@ -37,9 +37,9 @@ public Page findByDateRangeAndMember(LocalDate startDate, LocalDate en builder.and(schedule.endDateTime.goe(startDateTime)) .and(schedule.startDateTime.loe(endDateTime)); - if (myGroupList != null && !myGroupList.isEmpty()) { + if (myGroups != null && !myGroups.isEmpty()) { builder.and(schedule.activityGroup.isNull() - .or(schedule.activityGroup.in(myGroupList))); + .or(schedule.activityGroup.in(myGroups))); } else { builder.and(schedule.activityGroup.isNull()); }