-
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] 모임 신청 API registry, strategy 기반으로 클래스 분리 진행 (#137)
- Loading branch information
Showing
5 changed files
with
158 additions
and
22 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/main/java/com/ggang/be/api/group/everyGroup/strategy/ApplyEveryGroupStrategy.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,54 @@ | ||
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.ApplyGroupStrategy; | ||
import com.ggang.be.api.lectureTimeSlot.service.LectureTimeSlotService; | ||
import com.ggang.be.api.userEveryGroup.service.UserEveryGroupService; | ||
import com.ggang.be.domain.common.SameSchoolValidator; | ||
import com.ggang.be.domain.constant.GroupType; | ||
import com.ggang.be.domain.group.dto.GroupVo; | ||
import com.ggang.be.domain.group.everyGroup.EveryGroupEntity; | ||
import com.ggang.be.domain.group.everyGroup.dto.EveryGroupVo; | ||
import com.ggang.be.domain.user.UserEntity; | ||
import com.ggang.be.global.annotation.Strategy; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Strategy | ||
@RequiredArgsConstructor | ||
public class ApplyEveryGroupStrategy implements ApplyGroupStrategy { | ||
|
||
private final EveryGroupService everyGroupService; | ||
private final SameSchoolValidator sameSchoolValidator; | ||
private final UserEveryGroupService userEveryGroupService; | ||
private final LectureTimeSlotService lectureTimeSlotService; | ||
|
||
@Override | ||
public boolean support(GroupType groupType) { | ||
return groupType.equals(GroupType.WEEKLY); | ||
} | ||
|
||
@Override | ||
public void applyGroup(UserEntity findUserEntity, GroupRequest request) { | ||
EveryGroupEntity everyGroupEntity = everyGroupService.findEveryGroupEntityByGroupId(request.groupId()); | ||
sameSchoolValidator.isUserReadMySchoolEveryGroup(findUserEntity, everyGroupEntity); | ||
everyGroupService.validateApplyEveryGroup(findUserEntity, everyGroupEntity); | ||
GroupVo groupVo = GroupVo.fromEveryGroup(EveryGroupVo.of(everyGroupEntity)); | ||
|
||
if(checkGroupsLectureTimeSlot(findUserEntity, groupVo)) | ||
userEveryGroupService.applyEveryGroup(findUserEntity, everyGroupEntity); | ||
else throw new GongBaekException(ResponseError.TIME_SLOT_ALREADY_EXIST); | ||
} | ||
|
||
private boolean checkGroupsLectureTimeSlot(UserEntity findUserEntity, GroupVo groupVo) { | ||
return lectureTimeSlotService.isActiveGroupsInLectureTimeSlot( | ||
findUserEntity, | ||
groupVo.startTime(), | ||
groupVo.endTime(), | ||
groupVo.weekDate() | ||
); | ||
} | ||
|
||
} |
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
54 changes: 54 additions & 0 deletions
54
src/main/java/com/ggang/be/api/group/onceGroup/strategy/ApplyOnceGroupStrategy.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,54 @@ | ||
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.ApplyGroupStrategy; | ||
import com.ggang.be.api.lectureTimeSlot.service.LectureTimeSlotService; | ||
import com.ggang.be.api.userOnceGroup.service.UserOnceGroupService; | ||
import com.ggang.be.domain.common.SameSchoolValidator; | ||
import com.ggang.be.domain.constant.GroupType; | ||
import com.ggang.be.domain.group.dto.GroupVo; | ||
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.Strategy; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Strategy | ||
@RequiredArgsConstructor | ||
public class ApplyOnceGroupStrategy implements ApplyGroupStrategy { | ||
|
||
private final OnceGroupService onceGroupService; | ||
private final SameSchoolValidator sameSchoolValidator; | ||
private final UserOnceGroupService userOnceGroupService; | ||
private final LectureTimeSlotService lectureTimeSlotService; | ||
|
||
@Override | ||
public boolean support(GroupType groupType) { | ||
return groupType.equals(GroupType.ONCE); | ||
} | ||
|
||
@Override | ||
public void applyGroup(UserEntity findUserEntity, GroupRequest request) { | ||
OnceGroupEntity onceGroupEntity = onceGroupService.findOnceGroupEntityByGroupId(request.groupId()); | ||
sameSchoolValidator.isUserReadMySchoolOnceGroup(findUserEntity, onceGroupEntity); | ||
onceGroupService.validateApplyOnceGroup(findUserEntity, onceGroupEntity); | ||
GroupVo groupVo = GroupVo.fromOnceGroup(OnceGroupVo.of(onceGroupEntity)); | ||
|
||
if(checkGroupsLectureTimeSlot(findUserEntity, groupVo)) | ||
userOnceGroupService.applyOnceGroup(findUserEntity, onceGroupEntity); | ||
else throw new GongBaekException(ResponseError.TIME_SLOT_ALREADY_EXIST); | ||
} | ||
|
||
private boolean checkGroupsLectureTimeSlot(UserEntity findUserEntity, GroupVo groupVo) { | ||
return lectureTimeSlotService.isActiveGroupsInLectureTimeSlot( | ||
findUserEntity, | ||
groupVo.startTime(), | ||
groupVo.endTime(), | ||
groupVo.weekDate() | ||
); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/ggang/be/api/group/registry/ApplyGroupStrategy.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.api.group.dto.GroupRequest; | ||
import com.ggang.be.domain.constant.GroupType; | ||
import com.ggang.be.domain.user.UserEntity; | ||
|
||
public interface ApplyGroupStrategy { | ||
|
||
boolean support(GroupType groupType); | ||
|
||
void applyGroup(UserEntity userEntity, GroupRequest request); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/ggang/be/api/group/registry/ApplyGroupStrategyRegistry.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,27 @@ | ||
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 java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Registry | ||
@RequiredArgsConstructor | ||
public class ApplyGroupStrategyRegistry { | ||
|
||
private final List<ApplyGroupStrategy> applyGroupStrategies; | ||
|
||
|
||
public ApplyGroupStrategy getApplyGroupStrategy(GroupType groupType){ | ||
return applyGroupStrategies.stream() | ||
.filter(applyGroupStrategy -> applyGroupStrategy.support(groupType)) | ||
.findFirst() | ||
.orElseThrow(() -> new GongBaekException(ResponseError.BAD_REQUEST)); | ||
} | ||
|
||
|
||
|
||
|
||
} |