From 389b2b2853970e0f9fdb90221c049f6e0cf62f42 Mon Sep 17 00:00:00 2001 From: Khyojun Date: Mon, 20 Jan 2025 15:50:47 +0900 Subject: [PATCH] =?UTF-8?q?[refactor]=20#142=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B0=8F=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95,=20=EA=B8=B0=EC=A1=B4=EC=97=90?= =?UTF-8?q?=20=EC=A1=B4=EC=9E=AC=ED=95=98=EB=8D=98=20aggregator=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...va => ActivceCombinedGroupVoPreparer.java} | 38 +++++++++---------- .../be/api/group/dto/CombinedGroupVos.java | 16 ++++++++ .../be/api/group/dto/GroupResponsesDto.java | 16 -------- .../be/api/group/facade/GroupFacade.java | 17 ++++----- .../facade/PrepareGroupResponsesFacade.java | 28 -------------- 5 files changed, 41 insertions(+), 74 deletions(-) rename src/main/java/com/ggang/be/api/group/{ActiveGroupResponseAggregator.java => ActivceCombinedGroupVoPreparer.java} (61%) create mode 100644 src/main/java/com/ggang/be/api/group/dto/CombinedGroupVos.java delete mode 100644 src/main/java/com/ggang/be/api/group/dto/GroupResponsesDto.java delete mode 100644 src/main/java/com/ggang/be/api/group/facade/PrepareGroupResponsesFacade.java diff --git a/src/main/java/com/ggang/be/api/group/ActiveGroupResponseAggregator.java b/src/main/java/com/ggang/be/api/group/ActivceCombinedGroupVoPreparer.java similarity index 61% rename from src/main/java/com/ggang/be/api/group/ActiveGroupResponseAggregator.java rename to src/main/java/com/ggang/be/api/group/ActivceCombinedGroupVoPreparer.java index 302551d..6a80ea9 100644 --- a/src/main/java/com/ggang/be/api/group/ActiveGroupResponseAggregator.java +++ b/src/main/java/com/ggang/be/api/group/ActivceCombinedGroupVoPreparer.java @@ -1,43 +1,39 @@ package com.ggang.be.api.group; - -import com.ggang.be.api.group.dto.GroupResponsesDto; +import com.ggang.be.api.group.dto.CombinedGroupVos; import com.ggang.be.api.group.everyGroup.service.EveryGroupService; import com.ggang.be.api.group.onceGroup.service.OnceGroupService; -import com.ggang.be.domain.group.dto.GroupVo; +import com.ggang.be.domain.constant.Category; import com.ggang.be.domain.group.everyGroup.EveryGroupEntity; import com.ggang.be.domain.group.everyGroup.dto.EveryGroupVo; import com.ggang.be.domain.group.onceGroup.OnceGroupEntity; import com.ggang.be.domain.group.onceGroup.dto.OnceGroupVo; import com.ggang.be.domain.user.UserEntity; +import com.ggang.be.global.annotation.Facade; import java.util.List; -import java.util.stream.Stream; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; -@Component +@Facade @RequiredArgsConstructor -public class ActiveGroupResponseAggregator { +public class ActivceCombinedGroupVoPreparer { private final EveryGroupService everyGroupService; private final OnceGroupService onceGroupService; + public CombinedGroupVos prepareGroupVos(UserEntity currentUser, Category category) { + List everyGroupResponses = everyGroupService.getActiveEveryGroups(currentUser, + category).groups(). + stream().filter(groupVo -> isSameSchoolEveryGroup(currentUser, groupVo)).toList(); + + List onceGroupResponses = onceGroupService.getActiveOnceGroups(currentUser, + category).groups().stream() + .filter(groupVo -> isSameSchoolOnceGroup(currentUser, groupVo)).toList(); - public List aggregateActiveGroupResponses( - GroupResponsesDto groupResponsesDto, - UserEntity currentUser) { - List everyGroupResponses = groupResponsesDto.everyGroupResponses(); - List onceGroupResponses = groupResponsesDto.onceGroupResponses(); - return Stream.concat( - everyGroupResponses.stream().map(GroupVo::fromEveryGroup) - .filter(groupVo -> isSameSchoolEveryGroup(currentUser, groupVo)), - onceGroupResponses.stream().map(GroupVo::fromOnceGroup)) - .filter(groupVo -> isSameSchoolOnceGroup(currentUser, groupVo)) - .sorted((group1, group2) -> group2.createdAt().compareTo(group1.createdAt())) - .toList(); + return CombinedGroupVos.of(everyGroupResponses, onceGroupResponses); } - private boolean isSameSchoolOnceGroup(UserEntity currentUser, GroupVo groupVo) { + + private boolean isSameSchoolOnceGroup(UserEntity currentUser, OnceGroupVo groupVo) { String userSchool = currentUser.getSchool().getSchoolName(); OnceGroupEntity onceGroupEntity = onceGroupService.findOnceGroupEntityByGroupId( groupVo.groupId()); @@ -46,7 +42,7 @@ private boolean isSameSchoolOnceGroup(UserEntity currentUser, GroupVo groupVo) { return userSchool.equals(groupCreatorSchool); } - private boolean isSameSchoolEveryGroup(UserEntity currentUser, GroupVo groupVo) { + private boolean isSameSchoolEveryGroup(UserEntity currentUser, EveryGroupVo groupVo) { String userSchool = currentUser.getSchool().getSchoolName(); EveryGroupEntity everyGroupEntity = everyGroupService.findEveryGroupEntityByGroupId( groupVo.groupId()); diff --git a/src/main/java/com/ggang/be/api/group/dto/CombinedGroupVos.java b/src/main/java/com/ggang/be/api/group/dto/CombinedGroupVos.java new file mode 100644 index 0000000..f4a5117 --- /dev/null +++ b/src/main/java/com/ggang/be/api/group/dto/CombinedGroupVos.java @@ -0,0 +1,16 @@ +package com.ggang.be.api.group.dto; + +import com.ggang.be.domain.group.everyGroup.dto.EveryGroupVo; +import com.ggang.be.domain.group.onceGroup.dto.OnceGroupVo; +import java.util.List; + +public record CombinedGroupVos( + List everyGroupVos, + List onceGroupVos +) { + + public static CombinedGroupVos of(List everyGroupResponses, List onceGroupResponses) { + return new CombinedGroupVos(everyGroupResponses, onceGroupResponses); + } + +} diff --git a/src/main/java/com/ggang/be/api/group/dto/GroupResponsesDto.java b/src/main/java/com/ggang/be/api/group/dto/GroupResponsesDto.java deleted file mode 100644 index 5fe7539..0000000 --- a/src/main/java/com/ggang/be/api/group/dto/GroupResponsesDto.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.ggang.be.api.group.dto; - -import com.ggang.be.domain.group.everyGroup.dto.EveryGroupVo; -import com.ggang.be.domain.group.onceGroup.dto.OnceGroupVo; -import java.util.List; - -public record GroupResponsesDto( - List everyGroupResponses, - List onceGroupResponses -) { - - public static GroupResponsesDto of(List everyGroupResponses, List onceGroupResponses) { - return new GroupResponsesDto(everyGroupResponses, onceGroupResponses); - } - -} diff --git a/src/main/java/com/ggang/be/api/group/facade/GroupFacade.java b/src/main/java/com/ggang/be/api/group/facade/GroupFacade.java index 41dd2c5..623a8d0 100644 --- a/src/main/java/com/ggang/be/api/group/facade/GroupFacade.java +++ b/src/main/java/com/ggang/be/api/group/facade/GroupFacade.java @@ -1,9 +1,8 @@ package com.ggang.be.api.group.facade; -import com.ggang.be.api.group.ActiveGroupResponseAggregator; +import com.ggang.be.api.group.ActivceCombinedGroupVoPreparer; +import com.ggang.be.api.group.GroupVoAggregator; import com.ggang.be.api.group.dto.*; -import com.ggang.be.api.group.everyGroup.service.EveryGroupService; -import com.ggang.be.api.group.onceGroup.service.OnceGroupService; import com.ggang.be.api.group.registry.*; import com.ggang.be.api.lectureTimeSlot.service.LectureTimeSlotService; import com.ggang.be.api.mapper.GroupResponseMapper; @@ -43,8 +42,7 @@ public class GroupFacade { private final PrepareRegisterGongbaekFacade prepareRegisterGongbaekFacade; private final CancelGroupStrategyRegistry cancelGroupStrategyRegistry; private final GroupUserInfoStrategyRegistry groupUserInfoStrategyRegistry; - private final PrepareGroupResponsesFacade prepareGroupResponsesFacade; - private final ActiveGroupResponseAggregator activeGroupResponseAggregator; + private final ActivceCombinedGroupVoPreparer activceCombinedGroupVoPreparer; private final MyGroupStrategyRegistry myGroupStrategyRegistry; public GroupResponse getGroupInfo(GroupType groupType, Long groupId, long userId) { @@ -130,12 +128,13 @@ public List getMyGroups(long userId, FillGroupFilterRequest fil public List getFillGroups(long userId, Category category) { UserEntity currentUser = userService.getUserById(userId); - GroupResponsesDto groupResponsesDto = prepareGroupResponsesFacade.prepareGroupResponses( + CombinedGroupVos preparedGroupVo = activceCombinedGroupVoPreparer.prepareGroupVos( currentUser, category); - - List groupVos = activeGroupResponseAggregator.aggregateActiveGroupResponses( - groupResponsesDto, currentUser); + List groupVos = GroupVoAggregator.aggregateAndSort( + preparedGroupVo.everyGroupVos(), + preparedGroupVo.onceGroupVos() + ); return groupVos.stream() .filter(groupVo -> lectureTimeSlotService.isActiveGroupsInLectureTimeSlot(currentUser, diff --git a/src/main/java/com/ggang/be/api/group/facade/PrepareGroupResponsesFacade.java b/src/main/java/com/ggang/be/api/group/facade/PrepareGroupResponsesFacade.java deleted file mode 100644 index dfa73ea..0000000 --- a/src/main/java/com/ggang/be/api/group/facade/PrepareGroupResponsesFacade.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.ggang.be.api.group.facade; - -import com.ggang.be.api.group.dto.GroupResponsesDto; -import com.ggang.be.api.group.everyGroup.service.EveryGroupService; -import com.ggang.be.api.group.onceGroup.service.OnceGroupService; -import com.ggang.be.domain.constant.Category; -import com.ggang.be.domain.group.everyGroup.dto.EveryGroupVo; -import com.ggang.be.domain.group.onceGroup.dto.OnceGroupVo; -import com.ggang.be.domain.user.UserEntity; -import com.ggang.be.global.annotation.Facade; -import java.util.List; -import lombok.RequiredArgsConstructor; - -@Facade -@RequiredArgsConstructor -public class PrepareGroupResponsesFacade { - - private final EveryGroupService everyGroupService; - private final OnceGroupService onceGroupService; - - public GroupResponsesDto prepareGroupResponses(UserEntity currentUser, Category category){ - List everyGroupResponses = everyGroupService.getActiveEveryGroups(currentUser, category).groups(); - List onceGroupResponses = onceGroupService.getActiveOnceGroups(currentUser, category).groups(); - - return GroupResponsesDto.of(everyGroupResponses, onceGroupResponses); - } - -}