-
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] #138 registry, strategy 분리 진행 및 dto 준비 facade 분리해서 진행
- Loading branch information
Showing
7 changed files
with
279 additions
and
94 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/main/java/com/ggang/be/api/group/dto/PrepareRegisterInfo.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,15 @@ | ||
package com.ggang.be.api.group.dto; | ||
|
||
import com.ggang.be.domain.group.dto.RegisterGroupServiceRequest; | ||
import com.ggang.be.domain.timslot.gongbaekTimeSlot.GongbaekTimeSlotEntity; | ||
import com.ggang.be.domain.user.UserEntity; | ||
|
||
public record PrepareRegisterInfo(UserEntity findUserEntity, | ||
GongbaekTimeSlotEntity gongbaekTimeSlotEntity, | ||
RegisterGroupServiceRequest request) { | ||
|
||
public static PrepareRegisterInfo of(UserEntity findUserEntity, GongbaekTimeSlotEntity gongbaekTimeSlotEntity, | ||
RegisterGroupServiceRequest serviceRequest) { | ||
return new PrepareRegisterInfo(findUserEntity, gongbaekTimeSlotEntity, serviceRequest); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/ggang/be/api/group/everyGroup/strategy/RegisterEveryGroupStrategy.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,44 @@ | ||
package com.ggang.be.api.group.everyGroup.strategy; | ||
|
||
import com.ggang.be.api.group.dto.PrepareRegisterInfo; | ||
import com.ggang.be.api.group.dto.RegisterGongbaekResponse; | ||
import com.ggang.be.api.group.everyGroup.service.EveryGroupService; | ||
import com.ggang.be.api.group.registry.RegisterGroupStrategy; | ||
import com.ggang.be.api.userEveryGroup.service.UserEveryGroupService; | ||
import com.ggang.be.domain.constant.GroupType; | ||
import com.ggang.be.domain.group.dto.RegisterGroupServiceRequest; | ||
import com.ggang.be.domain.group.everyGroup.EveryGroupEntity; | ||
import com.ggang.be.domain.timslot.gongbaekTimeSlot.GongbaekTimeSlotEntity; | ||
import com.ggang.be.domain.user.UserEntity; | ||
import com.ggang.be.global.annotation.Strategy; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Strategy | ||
@RequiredArgsConstructor | ||
public class RegisterEveryGroupStrategy implements RegisterGroupStrategy { | ||
|
||
private final EveryGroupService everyGroupService; | ||
private final UserEveryGroupService userEveryGroupService; | ||
|
||
|
||
@Override | ||
public boolean support(GroupType groupType) { | ||
return groupType.equals(GroupType.WEEKLY); | ||
} | ||
|
||
@Override | ||
public RegisterGongbaekResponse registerGroup(PrepareRegisterInfo prepareRegisterInfo) { | ||
UserEntity findUserEntity = prepareRegisterInfo.findUserEntity(); | ||
RegisterGroupServiceRequest serviceRequest = prepareRegisterInfo.request(); | ||
GongbaekTimeSlotEntity gongbaekTimeSlotEntity = prepareRegisterInfo.gongbaekTimeSlotEntity(); | ||
|
||
|
||
EveryGroupEntity everyGroupEntity = everyGroupService.registerEveryGroup(serviceRequest, | ||
gongbaekTimeSlotEntity); | ||
userEveryGroupService.applyEveryGroup(findUserEntity, everyGroupEntity); | ||
return RegisterGongbaekResponse.of( | ||
everyGroupEntity.getId()); | ||
} | ||
|
||
|
||
} |
191 changes: 97 additions & 94 deletions
191
src/main/java/com/ggang/be/api/group/facade/GroupFacade.java
Large diffs are not rendered by default.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
src/main/java/com/ggang/be/api/group/facade/PrepareRegisterGongbaekFacade.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,46 @@ | ||
package com.ggang.be.api.group.facade; | ||
|
||
import com.ggang.be.api.gongbaekTimeSlot.service.GongbaekTimeSlotService; | ||
import com.ggang.be.api.group.dto.PrepareRegisterInfo; | ||
import com.ggang.be.api.group.dto.RegisterGongbaekRequest; | ||
import com.ggang.be.api.user.service.UserService; | ||
import com.ggang.be.domain.group.dto.RegisterGroupServiceRequest; | ||
import com.ggang.be.domain.timslot.gongbaekTimeSlot.GongbaekTimeSlotEntity; | ||
import com.ggang.be.domain.timslot.gongbaekTimeSlot.dto.GongbaekTimeSlotRequest; | ||
import com.ggang.be.domain.user.UserEntity; | ||
import com.ggang.be.global.annotation.Facade; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Facade | ||
@RequiredArgsConstructor | ||
public class PrepareRegisterGongbaekFacade { | ||
|
||
private final UserService userService; | ||
private final GongbaekTimeSlotService gongbaekTimeSlotService; | ||
|
||
public PrepareRegisterInfo prepareInfo(Long userId, RegisterGongbaekRequest dto){ | ||
UserEntity findUserEntity = userService.getUserById(userId); | ||
|
||
GongbaekTimeSlotRequest gongbaekDto = convertDtoToGongbaekDto(dto, findUserEntity); | ||
RegisterGroupServiceRequest serviceRequest = convertDtoToServiceDto(dto, findUserEntity); | ||
|
||
GongbaekTimeSlotEntity gongbaekTimeSlotEntity = gongbaekTimeSlotService.registerGongbaekTimeSlot( | ||
findUserEntity, gongbaekDto); | ||
|
||
return PrepareRegisterInfo.of(findUserEntity, gongbaekTimeSlotEntity, serviceRequest); | ||
} | ||
|
||
private RegisterGroupServiceRequest convertDtoToServiceDto( | ||
RegisterGongbaekRequest dto, UserEntity findUserEntity | ||
) { | ||
return RegisterGongbaekRequest.toServiceRequest(findUserEntity, dto); | ||
} | ||
|
||
private GongbaekTimeSlotRequest convertDtoToGongbaekDto( | ||
RegisterGongbaekRequest dto, UserEntity findUserEntity | ||
) { | ||
return RegisterGongbaekRequest.toGongbaekTimeSlotRequest(findUserEntity, dto); | ||
} | ||
|
||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/ggang/be/api/group/onceGroup/strategy/RegisterOnceGroupStrategy.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,41 @@ | ||
package com.ggang.be.api.group.onceGroup.strategy; | ||
|
||
import com.ggang.be.api.group.dto.PrepareRegisterInfo; | ||
import com.ggang.be.api.group.dto.RegisterGongbaekResponse; | ||
import com.ggang.be.api.group.onceGroup.service.OnceGroupService; | ||
import com.ggang.be.api.group.registry.RegisterGroupStrategy; | ||
import com.ggang.be.api.userOnceGroup.service.UserOnceGroupService; | ||
import com.ggang.be.domain.constant.GroupType; | ||
import com.ggang.be.domain.group.dto.RegisterGroupServiceRequest; | ||
import com.ggang.be.domain.group.onceGroup.OnceGroupEntity; | ||
import com.ggang.be.domain.timslot.gongbaekTimeSlot.GongbaekTimeSlotEntity; | ||
import com.ggang.be.domain.user.UserEntity; | ||
import com.ggang.be.global.annotation.Strategy; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Strategy | ||
@RequiredArgsConstructor | ||
public class RegisterOnceGroupStrategy implements RegisterGroupStrategy { | ||
|
||
private final OnceGroupService onceGroupService; | ||
private final UserOnceGroupService userOnceGroupService; | ||
|
||
@Override | ||
public boolean support(GroupType groupType) { | ||
return groupType.equals(GroupType.ONCE); | ||
} | ||
|
||
@Override | ||
public RegisterGongbaekResponse registerGroup(PrepareRegisterInfo prepareRegisterInfo) { | ||
UserEntity findUserEntity = prepareRegisterInfo.findUserEntity(); | ||
RegisterGroupServiceRequest serviceRequest = prepareRegisterInfo.request(); | ||
GongbaekTimeSlotEntity gongbaekTimeSlotEntity = prepareRegisterInfo.gongbaekTimeSlotEntity(); | ||
|
||
OnceGroupEntity onceGroupEntity = onceGroupService.registerOnceGroup(serviceRequest, | ||
gongbaekTimeSlotEntity); | ||
userOnceGroupService.applyOnceGroup(findUserEntity, onceGroupEntity); | ||
return RegisterGongbaekResponse.of(onceGroupEntity.getId()); | ||
} | ||
|
||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/ggang/be/api/group/registry/RegisterGroupStrategy.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.PrepareRegisterInfo; | ||
import com.ggang.be.api.group.dto.RegisterGongbaekResponse; | ||
import com.ggang.be.domain.constant.GroupType; | ||
|
||
public interface RegisterGroupStrategy { | ||
|
||
boolean support(GroupType groupType); | ||
|
||
|
||
RegisterGongbaekResponse registerGroup(PrepareRegisterInfo prepareRegisterInfo); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/ggang/be/api/group/registry/RegisterGroupStrategyRegistry.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 java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Registry | ||
@RequiredArgsConstructor | ||
public class RegisterGroupStrategyRegistry { | ||
|
||
private final List<RegisterGroupStrategy> registerGroupStrategies; | ||
|
||
public RegisterGroupStrategy getRegisterGroupStrategy(GroupType groupType) { | ||
return registerGroupStrategies.stream() | ||
.filter(strategy -> strategy.support(groupType)) | ||
.findFirst() | ||
.orElseThrow(() -> new GongBaekException(ResponseError.BAD_REQUEST)); | ||
} | ||
|
||
} |