Skip to content

Commit

Permalink
[refactor] #142 클래스 네이밍 및 변수명 수정, 기존에 존재하던 aggregator 사용할 수 있도록 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
khyojun committed Jan 20, 2025
1 parent d8ea91a commit 389b2b2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -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<EveryGroupVo> everyGroupResponses = everyGroupService.getActiveEveryGroups(currentUser,
category).groups().
stream().filter(groupVo -> isSameSchoolEveryGroup(currentUser, groupVo)).toList();

List<OnceGroupVo> onceGroupResponses = onceGroupService.getActiveOnceGroups(currentUser,
category).groups().stream()
.filter(groupVo -> isSameSchoolOnceGroup(currentUser, groupVo)).toList();

public List<GroupVo> aggregateActiveGroupResponses(
GroupResponsesDto groupResponsesDto,
UserEntity currentUser) {
List<EveryGroupVo> everyGroupResponses = groupResponsesDto.everyGroupResponses();
List<OnceGroupVo> 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());
Expand All @@ -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());
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/ggang/be/api/group/dto/CombinedGroupVos.java
Original file line number Diff line number Diff line change
@@ -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<EveryGroupVo> everyGroupVos,
List<OnceGroupVo> onceGroupVos
) {

public static CombinedGroupVos of(List<EveryGroupVo> everyGroupResponses, List<OnceGroupVo> onceGroupResponses) {
return new CombinedGroupVos(everyGroupResponses, onceGroupResponses);
}

}
16 changes: 0 additions & 16 deletions src/main/java/com/ggang/be/api/group/dto/GroupResponsesDto.java

This file was deleted.

17 changes: 8 additions & 9 deletions src/main/java/com/ggang/be/api/group/facade/GroupFacade.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -130,12 +128,13 @@ public List<MyGroupResponse> getMyGroups(long userId, FillGroupFilterRequest fil

public List<ActiveGroupsResponse> getFillGroups(long userId, Category category) {
UserEntity currentUser = userService.getUserById(userId);
GroupResponsesDto groupResponsesDto = prepareGroupResponsesFacade.prepareGroupResponses(
CombinedGroupVos preparedGroupVo = activceCombinedGroupVoPreparer.prepareGroupVos(
currentUser, category);


List<GroupVo> groupVos = activeGroupResponseAggregator.aggregateActiveGroupResponses(
groupResponsesDto, currentUser);
List<GroupVo> groupVos = GroupVoAggregator.aggregateAndSort(
preparedGroupVo.everyGroupVos(),
preparedGroupVo.onceGroupVos()
);

return groupVos.stream()
.filter(groupVo -> lectureTimeSlotService.isActiveGroupsInLectureTimeSlot(currentUser,
Expand Down

This file was deleted.

0 comments on commit 389b2b2

Please sign in to comment.