diff --git a/src/main/java/page/clab/api/domain/community/comment/application/service/CommentLikeToggleService.java b/src/main/java/page/clab/api/domain/community/comment/application/service/CommentLikeToggleService.java index 16a5b84fd..8dcb74d04 100644 --- a/src/main/java/page/clab/api/domain/community/comment/application/service/CommentLikeToggleService.java +++ b/src/main/java/page/clab/api/domain/community/comment/application/service/CommentLikeToggleService.java @@ -9,6 +9,7 @@ import page.clab.api.domain.community.comment.application.port.out.RetrieveCommentLikePort; import page.clab.api.domain.community.comment.domain.Comment; import page.clab.api.domain.community.comment.domain.CommentLike; +import page.clab.api.external.community.comment.application.port.ExternalRegisterCommentUseCase; import page.clab.api.external.community.comment.application.port.ExternalRetrieveCommentUseCase; import page.clab.api.external.memberManagement.member.application.port.ExternalRetrieveMemberUseCase; @@ -20,6 +21,7 @@ public class CommentLikeToggleService implements ToggleCommentLikeUseCase { private final RegisterCommentLikePort registerCommentLikePort; private final RemoveCommentLikePort removeCommentLikePort; private final ExternalRetrieveCommentUseCase externalRetrieveCommentUseCase; + private final ExternalRegisterCommentUseCase externalRegisterCommentUseCase; private final ExternalRetrieveMemberUseCase externalRetrieveMemberUseCase; @Transactional @@ -31,13 +33,13 @@ public Long toggleLikeStatus(Long commentId) { .map(commentLike -> { removeCommentLikePort.delete(commentLike); comment.decrementLikes(); - return comment.getLikes(); + return externalRegisterCommentUseCase.save(comment).getLikes(); }) .orElseGet(() -> { CommentLike newLike = CommentLike.create(currentMemberId, comment.getId()); registerCommentLikePort.save(newLike); comment.incrementLikes(); - return comment.getLikes(); + return externalRegisterCommentUseCase.save(comment).getLikes(); }); } diff --git a/src/main/java/page/clab/api/external/community/comment/application/port/ExternalRegisterCommentUseCase.java b/src/main/java/page/clab/api/external/community/comment/application/port/ExternalRegisterCommentUseCase.java new file mode 100644 index 000000000..55f9b75e3 --- /dev/null +++ b/src/main/java/page/clab/api/external/community/comment/application/port/ExternalRegisterCommentUseCase.java @@ -0,0 +1,7 @@ +package page.clab.api.external.community.comment.application.port; + +import page.clab.api.domain.community.comment.domain.Comment; + +public interface ExternalRegisterCommentUseCase { + Comment save(Comment comment); +} diff --git a/src/main/java/page/clab/api/external/community/comment/application/service/ExternalCommentRegisterService.java b/src/main/java/page/clab/api/external/community/comment/application/service/ExternalCommentRegisterService.java new file mode 100644 index 000000000..152b24200 --- /dev/null +++ b/src/main/java/page/clab/api/external/community/comment/application/service/ExternalCommentRegisterService.java @@ -0,0 +1,21 @@ +package page.clab.api.external.community.comment.application.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import page.clab.api.domain.community.comment.application.port.out.RegisterCommentPort; +import page.clab.api.domain.community.comment.domain.Comment; +import page.clab.api.external.community.comment.application.port.ExternalRegisterCommentUseCase; + +@Service +@RequiredArgsConstructor +public class ExternalCommentRegisterService implements ExternalRegisterCommentUseCase { + + private final RegisterCommentPort registerCommentPort; + + @Transactional + @Override + public Comment save(Comment comment) { + return registerCommentPort.save(comment); + } +}