diff --git a/src/main/java/com/ggang/be/api/comment/facade/CommentFacade.java b/src/main/java/com/ggang/be/api/comment/facade/CommentFacade.java index 022fe1b..9fce774 100644 --- a/src/main/java/com/ggang/be/api/comment/facade/CommentFacade.java +++ b/src/main/java/com/ggang/be/api/comment/facade/CommentFacade.java @@ -6,8 +6,8 @@ import com.ggang.be.api.comment.dto.WriteCommentRequest; import com.ggang.be.api.comment.dto.WriteCommentResponse; import com.ggang.be.api.comment.service.CommentService; -import com.ggang.be.api.comment.registry.CommentFacadeHandler; -import com.ggang.be.api.comment.registry.CommentRegistry; +import com.ggang.be.api.comment.registry.CommentStrategy; +import com.ggang.be.api.comment.registry.CommentStrategyRegistry; import com.ggang.be.api.user.service.UserService; import com.ggang.be.domain.comment.CommentEntity; import com.ggang.be.domain.user.UserEntity; @@ -19,30 +19,32 @@ @RequiredArgsConstructor public class CommentFacade { - private final CommentRegistry commentRegistry; + private final CommentStrategyRegistry commentStrategyRegistry; private final UserService userService; private final CommentService commentService; @Transactional public WriteCommentResponse writeComment(final long userId, WriteCommentRequest dto) { - CommentFacadeHandler commentGroupHandler = commentRegistry.getCommentGroupHandler(dto.groupType()); + CommentStrategy commentStrategy = commentStrategyRegistry.getCommentGroupStrategy(dto.groupType()); UserEntity findUserEntity = userService.getUserById(userId); CommentEntity commentEntity = commentService.writeComment(findUserEntity, dto); - return commentGroupHandler.writeComment(userId, dto, WriteCommentEntityDto.from(commentEntity, findUserEntity)); + return commentStrategy.writeComment(userId, dto, WriteCommentEntityDto.from(commentEntity, findUserEntity)); } public ReadCommentResponse readComment(Long userId, final boolean isPublic, ReadCommentRequest dto) { + CommentStrategy commentStrategy = commentStrategyRegistry.getCommentGroupStrategy(dto.groupType()); + + UserEntity findUserEntity = userService.getUserById(userId); - CommentFacadeHandler commentGroupHandler = commentRegistry.getCommentGroupHandler(dto.groupType()); - return commentGroupHandler.readComment(findUserEntity, isPublic, dto); + return commentStrategy.readComment(findUserEntity, isPublic, dto); } } diff --git a/src/main/java/com/ggang/be/api/comment/facade/EveryGroupCommentFacadeHandler.java b/src/main/java/com/ggang/be/api/comment/facade/EveryGroupCommentStrategyFacade.java similarity index 92% rename from src/main/java/com/ggang/be/api/comment/facade/EveryGroupCommentFacadeHandler.java rename to src/main/java/com/ggang/be/api/comment/facade/EveryGroupCommentStrategyFacade.java index e267532..92fce14 100644 --- a/src/main/java/com/ggang/be/api/comment/facade/EveryGroupCommentFacadeHandler.java +++ b/src/main/java/com/ggang/be/api/comment/facade/EveryGroupCommentStrategyFacade.java @@ -5,7 +5,7 @@ import com.ggang.be.api.comment.dto.WriteCommentEntityDto; import com.ggang.be.api.comment.dto.WriteCommentRequest; import com.ggang.be.api.comment.dto.WriteCommentResponse; -import com.ggang.be.api.comment.registry.CommentFacadeHandler; +import com.ggang.be.api.comment.registry.CommentStrategy; import com.ggang.be.api.group.everyGroup.service.EveryGroupService; import com.ggang.be.api.userEveryGroup.service.UserEveryGroupService; import com.ggang.be.domain.comment.CommentEntity; @@ -13,12 +13,12 @@ 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.Handler; +import com.ggang.be.global.annotation.Strategy; import lombok.RequiredArgsConstructor; -@Handler +@Strategy @RequiredArgsConstructor -public class EveryGroupCommentFacadeHandler implements CommentFacadeHandler { +public class EveryGroupCommentStrategyFacade implements CommentStrategy { private final EveryGroupService everyGroupService; private final SameSchoolValidator sameSchoolValidator; diff --git a/src/main/java/com/ggang/be/api/comment/facade/OnceGroupCommentFacadeHandler.java b/src/main/java/com/ggang/be/api/comment/facade/OnceGroupCommentStrategyFacade.java similarity index 92% rename from src/main/java/com/ggang/be/api/comment/facade/OnceGroupCommentFacadeHandler.java rename to src/main/java/com/ggang/be/api/comment/facade/OnceGroupCommentStrategyFacade.java index d7c2f56..d0df649 100644 --- a/src/main/java/com/ggang/be/api/comment/facade/OnceGroupCommentFacadeHandler.java +++ b/src/main/java/com/ggang/be/api/comment/facade/OnceGroupCommentStrategyFacade.java @@ -5,7 +5,7 @@ import com.ggang.be.api.comment.dto.WriteCommentEntityDto; import com.ggang.be.api.comment.dto.WriteCommentRequest; import com.ggang.be.api.comment.dto.WriteCommentResponse; -import com.ggang.be.api.comment.registry.CommentFacadeHandler; +import com.ggang.be.api.comment.registry.CommentStrategy; import com.ggang.be.api.group.onceGroup.service.OnceGroupService; import com.ggang.be.api.userOnceGroup.service.UserOnceGroupService; import com.ggang.be.domain.comment.CommentEntity; @@ -13,12 +13,12 @@ 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.Handler; +import com.ggang.be.global.annotation.Strategy; import lombok.RequiredArgsConstructor; -@Handler +@Strategy @RequiredArgsConstructor -public class OnceGroupCommentFacadeHandler implements CommentFacadeHandler { +public class OnceGroupCommentStrategyFacade implements CommentStrategy { private final OnceGroupService onceGroupService; private final SameSchoolValidator sameSchoolValidator; diff --git a/src/main/java/com/ggang/be/api/comment/registry/CommentFacadeHandler.java b/src/main/java/com/ggang/be/api/comment/registry/CommentStrategy.java similarity index 94% rename from src/main/java/com/ggang/be/api/comment/registry/CommentFacadeHandler.java rename to src/main/java/com/ggang/be/api/comment/registry/CommentStrategy.java index 84ddd93..32b2424 100644 --- a/src/main/java/com/ggang/be/api/comment/registry/CommentFacadeHandler.java +++ b/src/main/java/com/ggang/be/api/comment/registry/CommentStrategy.java @@ -8,7 +8,7 @@ import com.ggang.be.domain.constant.GroupType; import com.ggang.be.domain.user.UserEntity; -public interface CommentFacadeHandler { +public interface CommentStrategy { ReadCommentResponse readComment(UserEntity findUserEntity, boolean isPublic, ReadCommentRequest dto); diff --git a/src/main/java/com/ggang/be/api/comment/registry/CommentRegistry.java b/src/main/java/com/ggang/be/api/comment/registry/CommentStrategyRegistry.java similarity index 62% rename from src/main/java/com/ggang/be/api/comment/registry/CommentRegistry.java rename to src/main/java/com/ggang/be/api/comment/registry/CommentStrategyRegistry.java index 5041b11..6dd6b4c 100644 --- a/src/main/java/com/ggang/be/api/comment/registry/CommentRegistry.java +++ b/src/main/java/com/ggang/be/api/comment/registry/CommentStrategyRegistry.java @@ -9,13 +9,13 @@ @Registry @RequiredArgsConstructor -public class CommentRegistry { +public class CommentStrategyRegistry { - private final List groupHandlers; + private final List commentStrategies; - public CommentFacadeHandler getCommentGroupHandler(GroupType groupType) { - return groupHandlers.stream() - .filter(groupHandler -> groupHandler.supports(groupType)) + public CommentStrategy getCommentGroupStrategy(GroupType groupType) { + return commentStrategies.stream() + .filter(strategy -> strategy.supports(groupType)) .findFirst() .orElseThrow(() -> new GongBaekException(ResponseError.BAD_REQUEST)); } diff --git a/src/main/java/com/ggang/be/global/annotation/Handler.java b/src/main/java/com/ggang/be/global/annotation/Strategy.java similarity index 91% rename from src/main/java/com/ggang/be/global/annotation/Handler.java rename to src/main/java/com/ggang/be/global/annotation/Strategy.java index 58ba4d9..10aab9b 100644 --- a/src/main/java/com/ggang/be/global/annotation/Handler.java +++ b/src/main/java/com/ggang/be/global/annotation/Strategy.java @@ -9,6 +9,6 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @Component -public @interface Handler { +public @interface Strategy { }