From 9ea0dfa9bf09b0836f4a2d2c84689b715ec2c14b Mon Sep 17 00:00:00 2001 From: Khyojun Date: Mon, 20 Jan 2025 06:43:03 +0900 Subject: [PATCH] =?UTF-8?q?[refactor]=20#142=20merge=20conflict=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0=20=EB=B0=8F=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=EC=B1=84?= =?UTF-8?q?=EC=9A=B0=EA=B8=B0=20=EC=A0=84=EC=B2=B4=20=EB=AA=A8=EC=9E=84=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20?= =?UTF-8?q?=EC=A7=84=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../be/api/group/facade/GroupFacade.java | 123 ++++++++---------- 1 file changed, 54 insertions(+), 69 deletions(-) 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 8a77af2..94589e4 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,34 @@ package com.ggang.be.api.group.facade; -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.group.GroupVoAggregator; +import com.ggang.be.api.group.dto.ActiveGroupsResponse; +import com.ggang.be.api.group.dto.FillGroupFilterRequest; +import com.ggang.be.api.group.dto.GroupRequest; +import com.ggang.be.api.group.dto.GroupResponse; +import com.ggang.be.api.group.dto.GroupResponsesDto; +import com.ggang.be.api.group.dto.MyGroupResponse; +import com.ggang.be.api.group.dto.NearestGroupResponse; +import com.ggang.be.api.group.dto.PrepareRegisterInfo; +import com.ggang.be.api.group.dto.ReadFillMembersRequest; +import com.ggang.be.api.group.dto.ReadFillMembersResponse; +import com.ggang.be.api.group.dto.RegisterGongbaekRequest; +import com.ggang.be.api.group.dto.RegisterGongbaekResponse; +import com.ggang.be.api.group.registry.ApplyGroupStrategy; +import com.ggang.be.api.group.registry.ApplyGroupStrategyRegistry; +import com.ggang.be.api.group.registry.CancelGroupStrategy; +import com.ggang.be.api.group.registry.CancelGroupStrategyRegistry; +import com.ggang.be.api.group.registry.GroupInfoStrategy; +import com.ggang.be.api.group.registry.GroupInfoStrategyRegistry; +import com.ggang.be.api.group.registry.GroupUserInfoStrategy; +import com.ggang.be.api.group.registry.GroupUserInfoStrategyRegistry; +import com.ggang.be.api.group.registry.LatestGroupStrategy; +import com.ggang.be.api.group.registry.LatestGroupStrategyRegistry; +import com.ggang.be.api.group.registry.MyGroupStrategy; +import com.ggang.be.api.group.registry.MyGroupStrategyRegistry; +import com.ggang.be.api.group.registry.ReadFillMemberStrategy; +import com.ggang.be.api.group.registry.ReadFillMemberStrategyRegistry; +import com.ggang.be.api.group.registry.RegisterGroupStrategy; +import com.ggang.be.api.group.registry.RegisterGroupStrategyRegistry; import com.ggang.be.api.lectureTimeSlot.service.LectureTimeSlotService; import com.ggang.be.api.mapper.GroupResponseMapper; import com.ggang.be.api.user.service.UserService; @@ -12,23 +37,17 @@ import com.ggang.be.domain.constant.Category; import com.ggang.be.domain.constant.GroupType; import com.ggang.be.domain.group.dto.GroupVo; -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.domain.user.dto.UserInfo; import com.ggang.be.domain.userEveryGroup.dto.NearestEveryGroup; import com.ggang.be.domain.userOnceGroup.dto.NearestOnceGroup; import com.ggang.be.global.annotation.Facade; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.transaction.annotation.Transactional; - import java.time.LocalDate; import java.util.List; import java.util.stream.Collectors; -import java.util.stream.Stream; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.transaction.annotation.Transactional; @Facade @@ -36,8 +55,6 @@ @Slf4j public class GroupFacade { - private final EveryGroupService everyGroupService; - private final OnceGroupService onceGroupService; private final UserEveryGroupService userEveryGroupService; private final UserOnceGroupService userOnceGroupService; private final UserService userService; @@ -50,6 +67,7 @@ public class GroupFacade { private final PrepareRegisterGongbaekFacade prepareRegisterGongbaekFacade; private final CancelGroupStrategyRegistry cancelGroupStrategyRegistry; private final GroupUserInfoStrategyRegistry groupUserInfoStrategyRegistry; + private final PrepareGroupResponsesFacade prepareGroupResponsesFacade; private final MyGroupStrategyRegistry myGroupStrategyRegistry; public GroupResponse getGroupInfo(GroupType groupType, Long groupId, long userId) { @@ -80,9 +98,11 @@ public NearestGroupResponse getNearestGroupInfo(long userId) { } public UserInfo getGroupUserInfo(GroupType groupType, Long groupId) { - GroupUserInfoStrategy groupUserInfoStrategy = groupUserInfoStrategyRegistry.getGroupUserInfo(groupType); + GroupUserInfoStrategy groupUserInfoStrategy = groupUserInfoStrategyRegistry.getGroupUserInfo( + groupType); - return UserInfo.of(userService.getUserById(groupUserInfoStrategy.getGroupUserInfo(groupId))); + return UserInfo.of( + userService.getUserById(groupUserInfoStrategy.getGroupUserInfo(groupId))); } @Transactional @@ -113,7 +133,7 @@ public void cancelMyApplication(Long userId, GroupRequest requestDto) { UserEntity findUserEntity = userService.getUserById(userId); CancelGroupStrategy cancelGroupStrategy = cancelGroupStrategyRegistry.getCancelGroupStrategy( - requestDto.groupType() + requestDto.groupType() ); cancelGroupStrategy.cancelGroup(findUserEntity, requestDto); @@ -122,32 +142,30 @@ public void cancelMyApplication(Long userId, GroupRequest requestDto) { public List getMyGroups(long userId, FillGroupFilterRequest filterRequestDto) { UserEntity currentUser = userService.getUserById(userId); - MyGroupStrategy groupStrategy = myGroupStrategyRegistry.getGroupStrategy(filterRequestDto.getFillGroupCategory()); + MyGroupStrategy groupStrategy = myGroupStrategyRegistry.getGroupStrategy( + filterRequestDto.getFillGroupCategory()); - List groupResponses = groupStrategy.getGroups(currentUser, filterRequestDto.status()); + List groupResponses = groupStrategy.getGroups(currentUser, + filterRequestDto.status()); return groupResponses.stream() - .map(MyGroupResponse::fromGroupVo) - .collect(Collectors.toList()); + .map(MyGroupResponse::fromGroupVo) + .collect(Collectors.toList()); } public List getFillGroups(long userId, Category category) { UserEntity currentUser = userService.getUserById(userId); - List everyGroupResponses = getActiveEveryGroups(currentUser, category); - List onceGroupResponses = getActiveOnceGroups(currentUser, category); + GroupResponsesDto groupResponsesDto = prepareGroupResponsesFacade.prepareGroupResponses( + currentUser, category); - // TODO 분기처리 하기!!! - List allGroups = 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(); + List groupVos = GroupVoAggregator.aggregateAndSort( + groupResponsesDto.everyGroupResponses(), + groupResponsesDto.onceGroupResponses()); - return allGroups.stream() - .filter(groupVo -> checkGroupsLectureTimeSlot(currentUser, groupVo)) + return groupVos.stream() + .filter(groupVo -> lectureTimeSlotService.isActiveGroupsInLectureTimeSlot(currentUser, + groupVo)) .map(ActiveGroupsResponse::fromGroupVo) .collect(Collectors.toList()); } @@ -159,47 +177,14 @@ public List getLatestGroups(long userId, GroupType groupTy groupType); return latestGroupStrategy.getLatestGroups(currentUser).stream() - .filter(groupVo -> checkGroupsLectureTimeSlot(currentUser, groupVo)) + .filter(groupVo -> lectureTimeSlotService.isActiveGroupsInLectureTimeSlot(currentUser, + groupVo)) .sorted((group1, group2) -> group2.createdAt().compareTo(group1.createdAt())) .limit(5) .map(ActiveGroupsResponse::fromGroupVo) .collect(Collectors.toList()); } - private boolean isSameSchoolOnceGroup(UserEntity currentUser, GroupVo groupVo) { - String userSchool = currentUser.getSchool().getSchoolName(); - OnceGroupEntity onceGroupEntity = onceGroupService.findOnceGroupEntityByGroupId( - groupVo.groupId()); - String groupCreatorSchool = onceGroupEntity.getUserEntity().getSchool().getSchoolName(); - - return userSchool.equals(groupCreatorSchool); - } - - private boolean isSameSchoolEveryGroup(UserEntity currentUser, GroupVo groupVo) { - String userSchool = currentUser.getSchool().getSchoolName(); - EveryGroupEntity everyGroupEntity = everyGroupService.findEveryGroupEntityByGroupId( - groupVo.groupId()); - String groupCreatorSchool = everyGroupEntity.getUserEntity().getSchool().getSchoolName(); - - return userSchool.equals(groupCreatorSchool); - } - - private List getActiveEveryGroups(UserEntity currentUser, Category category) { - return everyGroupService.getActiveEveryGroups(currentUser, category).groups(); - } - - private List getActiveOnceGroups(UserEntity currentUser, Category category) { - return onceGroupService.getActiveOnceGroups(currentUser, category).groups(); - } - - private boolean checkGroupsLectureTimeSlot(UserEntity findUserEntity, GroupVo groupVo) { - return lectureTimeSlotService.isActiveGroupsInLectureTimeSlot( - findUserEntity, - groupVo.startTime(), - groupVo.endTime(), - groupVo.weekDate() - ); - } private NearestGroupResponse getNearestGroupFromDates(NearestEveryGroup nearestEveryGroup, NearestOnceGroup nearestOnceGroup) {