-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] #144 나의 모임 전체 조회 API 클래스 분리
- Loading branch information
Showing
7 changed files
with
135 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/ggang/be/api/group/registry/MyGroupStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.ggang.be.api.group.registry; | ||
|
||
import com.ggang.be.domain.constant.FillGroupType; | ||
import com.ggang.be.domain.group.dto.GroupVo; | ||
import com.ggang.be.domain.user.UserEntity; | ||
|
||
import java.util.List; | ||
|
||
public interface MyGroupStrategy { | ||
boolean supports(FillGroupType category); | ||
|
||
List<GroupVo> getGroups(UserEntity userEntity, boolean status); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/ggang/be/api/group/registry/MyGroupStrategyRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.ggang.be.api.group.registry; | ||
|
||
import com.ggang.be.api.common.ResponseError; | ||
import com.ggang.be.api.exception.GongBaekException; | ||
import com.ggang.be.domain.constant.FillGroupType; | ||
import com.ggang.be.global.annotation.Registry; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Registry | ||
@RequiredArgsConstructor | ||
public class MyGroupStrategyRegistry { | ||
|
||
private final List<MyGroupStrategy> groupStrategies; | ||
|
||
public MyGroupStrategy getGroupStrategy(FillGroupType category) { | ||
return groupStrategies.stream() | ||
.filter(strategy -> strategy.supports(category)) | ||
.findFirst() | ||
.orElseThrow(() -> new GongBaekException(ResponseError.BAD_REQUEST)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/ggang/be/api/group/strategy/MyApplyGroupStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.ggang.be.api.group.strategy; | ||
|
||
import com.ggang.be.api.group.registry.MyGroupStrategy; | ||
import com.ggang.be.api.userEveryGroup.service.UserEveryGroupService; | ||
import com.ggang.be.api.userOnceGroup.service.UserOnceGroupService; | ||
import com.ggang.be.domain.constant.FillGroupType; | ||
import com.ggang.be.domain.group.dto.GroupVo; | ||
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.util.GroupVoAggregator; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class MyApplyGroupStrategy implements MyGroupStrategy { | ||
|
||
private final UserEveryGroupService userEveryGroupService; | ||
private final UserOnceGroupService userOnceGroupService; | ||
|
||
@Override | ||
public boolean supports(FillGroupType category) { | ||
return category == FillGroupType.APPLY; | ||
} | ||
|
||
@Override | ||
public List<GroupVo> getGroups(UserEntity userEntity, boolean status) { | ||
List<EveryGroupVo> everyGroupResponses = userEveryGroupService.getMyAppliedGroups(userEntity, status).groups(); | ||
List<OnceGroupVo> onceGroupResponses = userOnceGroupService.getMyAppliedGroups(userEntity, status).groups(); | ||
|
||
return GroupVoAggregator.aggregateAndSort(everyGroupResponses, onceGroupResponses); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/ggang/be/api/group/strategy/MyRegisterGroupStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.ggang.be.api.group.strategy; | ||
|
||
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.MyGroupStrategy; | ||
import com.ggang.be.domain.constant.FillGroupType; | ||
import com.ggang.be.domain.group.dto.GroupVo; | ||
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.util.GroupVoAggregator; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class MyRegisterGroupStrategy implements MyGroupStrategy { | ||
|
||
private final EveryGroupService everyGroupService; | ||
private final OnceGroupService onceGroupService; | ||
|
||
@Override | ||
public boolean supports(FillGroupType category) { | ||
return category == FillGroupType.REGISTER; | ||
} | ||
|
||
@Override | ||
public List<GroupVo> getGroups(UserEntity userEntity, boolean status) { | ||
List<EveryGroupVo> everyGroupResponses = everyGroupService.getMyRegisteredGroups(userEntity, status).groups(); | ||
List<OnceGroupVo> onceGroupResponses = onceGroupService.getMyRegisteredGroups(userEntity, status).groups(); | ||
|
||
return GroupVoAggregator.aggregateAndSort(everyGroupResponses, onceGroupResponses); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/ggang/be/global/util/GroupVoAggregator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.ggang.be.global.util; | ||
|
||
import com.ggang.be.domain.group.dto.GroupVo; | ||
import com.ggang.be.domain.group.everyGroup.dto.EveryGroupVo; | ||
import com.ggang.be.domain.group.onceGroup.dto.OnceGroupVo; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class GroupVoAggregator { | ||
|
||
public static List<GroupVo> aggregateAndSort(List<EveryGroupVo> everyGroupResponses, List<OnceGroupVo> onceGroupResponses) { | ||
return Stream.concat( | ||
everyGroupResponses.stream().map(GroupVo::fromEveryGroup), | ||
onceGroupResponses.stream().map(GroupVo::fromOnceGroup) | ||
) | ||
.sorted((group1, group2) -> group2.createdAt().compareTo(group1.createdAt())) | ||
.collect(Collectors.toList()); | ||
} | ||
} |