Skip to content

Commit

Permalink
[refactor] #110 handler는 의미상 맞지 않아 strategy로 변경 진행!
Browse files Browse the repository at this point in the history
  • Loading branch information
khyojun committed Jan 18, 2025
1 parent 8f18b94 commit 32da0c9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
16 changes: 9 additions & 7 deletions src/main/java/com/ggang/be/api/comment/facade/CommentFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
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;
import com.ggang.be.domain.common.SameSchoolValidator;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
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;
import com.ggang.be.domain.common.SameSchoolValidator;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

@Registry
@RequiredArgsConstructor
public class CommentRegistry {
public class CommentStrategyRegistry {

private final List<CommentFacadeHandler> groupHandlers;
private final List<CommentStrategy> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Component
public @interface Handler {
public @interface Strategy {

}

0 comments on commit 32da0c9

Please sign in to comment.