-
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.
- Loading branch information
Showing
5 changed files
with
114 additions
and
67 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/java/com/ggang/be/api/group/everyGroup/strategy/CancelEveryGroupStrategy.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,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); | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
src/main/java/com/ggang/be/api/group/onceGroup/strategy/CancelOnceGroupStrategy.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,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); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/ggang/be/api/group/registry/CancelGroupStrategy.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,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); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/ggang/be/api/group/registry/CancelGroupStrategyRegistry.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.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)); | ||
} | ||
|
||
} |