Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] 등록자 프로필 조회 API 클래스 분리 #143

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.ggang.be.api.group.everyGroup.strategy;

import com.ggang.be.api.group.everyGroup.service.EveryGroupService;
import com.ggang.be.api.group.registry.GroupUserInfoStrategy;
import com.ggang.be.domain.constant.GroupType;
import com.ggang.be.global.annotation.Strategy;
import lombok.RequiredArgsConstructor;

@Strategy
@RequiredArgsConstructor
public class EveryGroupUserInfoStrategy implements GroupUserInfoStrategy {

private final EveryGroupService everyGroupService;

@Override
public boolean supports(GroupType groupType) {
return groupType == GroupType.WEEKLY;
}

@Override
public long getGroupUserInfo(long groupId) {
return everyGroupService.getEveryGroupRegisterUserId(groupId);
}
}
8 changes: 3 additions & 5 deletions src/main/java/com/ggang/be/api/group/facade/GroupFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class GroupFacade {
private final GroupInfoStrategyRegistry groupInfoStrategyRegistry;
private final ApplyGroupStrategyRegistry applyGroupStrategyRegistry;
private final CancelGroupStrategyRegistry cancelGroupStrategyRegistry;
private final GroupUserInfoStrategyRegistry groupUserInfoStrategyRegistry;

public GroupResponse getGroupInfo(GroupType groupType, Long groupId, long userId) {
UserEntity currentUser = userService.getUserById(userId);
Expand Down Expand Up @@ -82,12 +83,9 @@ public NearestGroupResponse getNearestGroupInfo(long userId) {
}

public UserInfo getGroupUserInfo(GroupType groupType, Long groupId) {
long userId = switch (groupType) {
case WEEKLY -> everyGroupService.getEveryGroupRegisterUserId(groupId);
case ONCE -> onceGroupService.getOnceGroupRegisterUserId(groupId);
};
GroupUserInfoStrategy groupUserInfoStrategy = groupUserInfoStrategyRegistry.getGroupUserInfo(groupType);

return UserInfo.of(userService.getUserById(userId));
return UserInfo.of(userService.getUserById(groupUserInfoStrategy.getGroupUserInfo(groupId)));
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.ggang.be.api.group.onceGroup.strategy;

import com.ggang.be.api.group.onceGroup.service.OnceGroupService;
import com.ggang.be.api.group.registry.GroupUserInfoStrategy;
import com.ggang.be.domain.constant.GroupType;
import com.ggang.be.global.annotation.Strategy;
import lombok.RequiredArgsConstructor;

@Strategy
@RequiredArgsConstructor
public class OnceGroupUserInfoStrategy implements GroupUserInfoStrategy {

private final OnceGroupService onceGroupService;

@Override
public boolean supports(GroupType groupType) {
return groupType == GroupType.ONCE;
}

@Override
public long getGroupUserInfo(long groupId) {
return onceGroupService.getOnceGroupRegisterUserId(groupId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.ggang.be.api.group.registry;

import com.ggang.be.domain.constant.GroupType;

public interface GroupUserInfoStrategy {
boolean supports(GroupType groupType);

long getGroupUserInfo(long groupId);
}
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.GroupType;
import com.ggang.be.global.annotation.Registry;
import lombok.RequiredArgsConstructor;

import java.util.List;

@Registry
@RequiredArgsConstructor
public class GroupUserInfoStrategyRegistry {

private final List<GroupUserInfoStrategy> groupUserInfoStrategies;

public GroupUserInfoStrategy getGroupUserInfo(GroupType groupType) {
return groupUserInfoStrategies.stream()
.filter(strategy -> strategy.supports(groupType))
.findFirst()
.orElseThrow(() -> new GongBaekException(ResponseError.BAD_REQUEST));
}
}
Loading