Skip to content

Commit

Permalink
fix(CommentLike): 댓글 좋아요가 눌리지 않는 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
limehee committed Jul 19, 2024
1 parent 918a2be commit 21793cc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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();
});

}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 21793cc

Please sign in to comment.