Skip to content

Commit

Permalink
[fix] #138 merge conflict resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
khyojun committed Jan 19, 2025
2 parents 21c6b5a + 5727df9 commit 556c77e
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.ggang.be.api.group.everyGroup.strategy;

import com.ggang.be.api.common.ResponseError;
import com.ggang.be.api.exception.GongBaekException;
import com.ggang.be.api.group.dto.GroupRequest;
import com.ggang.be.api.group.everyGroup.service.EveryGroupService;
import com.ggang.be.api.group.registry.CancelGroupStrategy;
import com.ggang.be.api.userEveryGroup.service.UserEveryGroupService;
import com.ggang.be.domain.constant.GroupType;
import com.ggang.be.domain.group.everyGroup.EveryGroupEntity;
import com.ggang.be.domain.user.UserEntity;
import com.ggang.be.global.annotation.Strategy;
import lombok.RequiredArgsConstructor;

@Strategy
@RequiredArgsConstructor
public class CancelEveryGroupStrategy implements CancelGroupStrategy {
private final EveryGroupService everyGroupService;
private final UserEveryGroupService userEveryGroupService;

@Override
public boolean support(GroupType groupType) {
return groupType.equals(GroupType.WEEKLY);
}

@Override
public void cancelGroup(UserEntity userEntity, GroupRequest request) {
EveryGroupEntity everyGroupEntity = everyGroupService.findEveryGroupEntityByGroupId(request.groupId());
if (everyGroupService.validateCancelEveryGroup(userEntity, everyGroupEntity))
userEveryGroupService.cancelEveryGroup(userEntity, everyGroupEntity);
else throw new GongBaekException(ResponseError.GROUP_CANCEL_NOT_FOUND);
}
}
81 changes: 14 additions & 67 deletions src/main/java/com/ggang/be/api/group/facade/GroupFacade.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
package com.ggang.be.api.group.facade;

import com.ggang.be.api.common.ResponseError;
import com.ggang.be.api.exception.GongBaekException;
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.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.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.ApplyGroupStrategy;
import com.ggang.be.api.group.registry.ApplyGroupStrategyRegistry;
import com.ggang.be.api.group.registry.GroupInfoStrategy;
import com.ggang.be.api.group.registry.GroupInfoStrategyRegistry;
import com.ggang.be.api.group.registry.LatestGroupStrategy;
import com.ggang.be.api.group.registry.LatestGroupStrategyRegistry;
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.group.registry.*;
import com.ggang.be.api.lectureTimeSlot.service.LectureTimeSlotService;
import com.ggang.be.api.mapper.GroupResponseMapper;
import com.ggang.be.api.user.service.UserService;
import com.ggang.be.api.userEveryGroup.service.UserEveryGroupService;
import com.ggang.be.api.userOnceGroup.service.UserOnceGroupService;
import com.ggang.be.domain.common.SameSchoolValidator;
import com.ggang.be.domain.constant.Category;
import com.ggang.be.domain.constant.GroupType;
import com.ggang.be.domain.group.dto.GroupVo;
Expand All @@ -43,14 +21,15 @@
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.Comparator;
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
Expand All @@ -64,13 +43,13 @@ public class GroupFacade {
private final UserOnceGroupService userOnceGroupService;
private final UserService userService;
private final LectureTimeSlotService lectureTimeSlotService;
private final SameSchoolValidator sameSchoolValidator;
private final LatestGroupStrategyRegistry latestGroupStrategyRegistry;
private final ReadFillMemberStrategyRegistry readFillMemberStrategyRegistry;
private final GroupInfoStrategyRegistry groupInfoStrategyRegistry;
private final ApplyGroupStrategyRegistry applyGroupStrategyRegistry;
private final RegisterGroupStrategyRegistry registerGroupStrategyRegistry;
private final PrepareRegisterGongbaekFacade prepareRegisterGongbaekFacade;
private final CancelGroupStrategyRegistry cancelGroupStrategyRegistry;

public GroupResponse getGroupInfo(GroupType groupType, Long groupId, long userId) {
UserEntity currentUser = userService.getUserById(userId);
Expand Down Expand Up @@ -125,7 +104,8 @@ public void applyGroup(Long userId, GroupRequest requestDto) {
UserEntity findUserEntity = userService.getUserById(userId);

ApplyGroupStrategy applyGroupStrategy = applyGroupStrategyRegistry.getApplyGroupStrategy(
requestDto.groupType());
requestDto.groupType()
);

applyGroupStrategy.applyGroup(findUserEntity, requestDto);
}
Expand All @@ -134,26 +114,11 @@ public void applyGroup(Long userId, GroupRequest requestDto) {
public void cancelMyApplication(Long userId, GroupRequest requestDto) {
UserEntity findUserEntity = userService.getUserById(userId);

switch (requestDto.groupType()) {
case WEEKLY -> {
EveryGroupEntity everyGroupEntity = everyGroupService.findEveryGroupEntityByGroupId(
requestDto.groupId());
if (everyGroupService.validateCancelEveryGroup(findUserEntity, everyGroupEntity)) {
userEveryGroupService.cancelEveryGroup(findUserEntity, everyGroupEntity);
} else {
throw new GongBaekException(ResponseError.GROUP_CANCEL_NOT_FOUND);
}
}
case ONCE -> {
OnceGroupEntity onceGroupEntity = onceGroupService.findOnceGroupEntityByGroupId(
requestDto.groupId());
if (onceGroupService.validateCancelOnceGroup(findUserEntity, onceGroupEntity)) {
userOnceGroupService.cancelOnceGroup(findUserEntity, onceGroupEntity);
} else {
throw new GongBaekException(ResponseError.GROUP_CANCEL_NOT_FOUND);
}
}
}
CancelGroupStrategy cancelGroupStrategy = cancelGroupStrategyRegistry.getCancelGroupStrategy(
requestDto.groupType()
);

cancelGroupStrategy.cancelGroup(findUserEntity, requestDto);
}

public List<MyGroupResponse> getMyGroups(long userId, FillGroupFilterRequest filterRequestDto) {
Expand Down Expand Up @@ -282,24 +247,6 @@ private List<GroupVo> getGroupsApply(UserEntity currentUser, boolean status) {
);
}

private void sameSchoolValidateByEveryList(UserEntity userEntity,
List<EveryGroupVo> everyGroupResponses) {
for (EveryGroupVo everyGroupVo : everyGroupResponses) {
EveryGroupEntity everyGroupEntity = everyGroupService.findEveryGroupEntityByGroupId(
everyGroupVo.groupId());
sameSchoolValidator.isUserReadMySchoolEveryGroup(userEntity, everyGroupEntity);
}
}

private void sameSchoolValidateByOnceList(UserEntity userEntity,
List<OnceGroupVo> onceGroupResponses) {
for (OnceGroupVo onceGroupVo : onceGroupResponses) {
OnceGroupEntity onceGroupEntity = onceGroupService.findOnceGroupEntityByGroupId(
onceGroupVo.groupId());
sameSchoolValidator.isUserReadMySchoolOnceGroup(userEntity, onceGroupEntity);
}
}

public ReadFillMembersResponse getGroupUsersInfo(Long userId, ReadFillMembersRequest dto) {
UserEntity findUserEntity = userService.getUserById(userId);

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

import com.ggang.be.api.common.ResponseError;
import com.ggang.be.api.exception.GongBaekException;
import com.ggang.be.api.group.dto.GroupRequest;
import com.ggang.be.api.group.onceGroup.service.OnceGroupService;
import com.ggang.be.api.group.registry.CancelGroupStrategy;
import com.ggang.be.api.userOnceGroup.service.UserOnceGroupService;
import com.ggang.be.domain.constant.GroupType;
import com.ggang.be.domain.group.onceGroup.OnceGroupEntity;
import com.ggang.be.domain.user.UserEntity;
import com.ggang.be.global.annotation.Strategy;
import lombok.RequiredArgsConstructor;

@Strategy
@RequiredArgsConstructor
public class CancelOnceGroupStrategy implements CancelGroupStrategy {
private final OnceGroupService onceGroupService;
private final UserOnceGroupService userOnceGroupService;

@Override
public boolean support(GroupType groupType) {
return groupType.equals(GroupType.ONCE);
}

@Override
public void cancelGroup(UserEntity userEntity, GroupRequest request) {
OnceGroupEntity onceGroupEntity = onceGroupService.findOnceGroupEntityByGroupId(request.groupId());
if (onceGroupService.validateCancelOnceGroup(userEntity, onceGroupEntity))
userOnceGroupService.cancelOnceGroup(userEntity, onceGroupEntity);
else throw new GongBaekException(ResponseError.GROUP_CANCEL_NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ggang.be.api.group.registry;

import com.ggang.be.api.group.dto.GroupRequest;
import com.ggang.be.domain.constant.GroupType;
import com.ggang.be.domain.user.UserEntity;

public interface CancelGroupStrategy {
boolean support(GroupType groupType);

void cancelGroup(UserEntity userEntity, GroupRequest request);
}
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 CancelGroupStrategyRegistry {
private final List<CancelGroupStrategy> cancelGroupStrategies;

public CancelGroupStrategy getCancelGroupStrategy(GroupType groupType){
return cancelGroupStrategies.stream()
.filter(applyGroupStrategy -> applyGroupStrategy.support(groupType))
.findFirst()
.orElseThrow(() -> new GongBaekException(ResponseError.BAD_REQUEST));
}

}

0 comments on commit 556c77e

Please sign in to comment.