Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
7bdfd23
[remove] 더미파일 삭제(#97)
hd0rable Jul 23, 2025
18fdd7f
[feat] Comment 도메인 생성 책임 코드 추가 (#97)
hd0rable Jul 23, 2025
e07ccf6
[feat] CommentCommandController.createComment 작성 (#97)
hd0rable Jul 23, 2025
e832743
[feat] CommentCommandPersistenceAdapter.save / findById 작성 (#97)
hd0rable Jul 23, 2025
5e482df
[feat] CommentCommandPort 관련 함수 추가 작성 (#97)
hd0rable Jul 23, 2025
3b9b5d5
[feat] CommentCountUpdatable작성 (#97)
hd0rable Jul 23, 2025
a264cda
[feat] 댓글 생성 Command dto 작성 (#97)
hd0rable Jul 23, 2025
3a55c36
[feat] 댓글 생성 request dto 작성 (#97)
hd0rable Jul 23, 2025
81ff6ca
[feat] 댓글 생성 유즈케이스 구현체 CommentCreateService 작성 (#97)
hd0rable Jul 23, 2025
7c40758
[feat] 댓글 생성 유즈케이스 CommentCreateUseCase 작성 (#97)
hd0rable Jul 23, 2025
c189a0f
[feat] CommentIdResponse dto 작성 (#97)
hd0rable Jul 23, 2025
2fa454a
[feat] CommentJpaEntity에 postType,likeCount 추가 (#97)
hd0rable Jul 23, 2025
03fee58
[feat] CommentMapper 에 likeCount,postType 매핑추가 (#97)
hd0rable Jul 23, 2025
567c537
[feat] 관련 에러코드 추가 (#97)
hd0rable Jul 23, 2025
d6cb099
[feat] vote,record, feed CommentCountUpdatableincreaseCommentCount공통 …
hd0rable Jul 23, 2025
954f9d7
[feat] RecordCommandPersistenceAdapter.findById / update 작성 (#97)
hd0rable Jul 23, 2025
376be34
[feat] VoteCommandPersistenceAdapter.findById / updateVote 작성 (#97)
hd0rable Jul 23, 2025
ee6addf
[feat] RecordCommandPort 관련 함수 추가 (#97)
hd0rable Jul 23, 2025
8351056
[feat] VoteCommandPort 관련 함수 정의 (#97)
hd0rable Jul 23, 2025
6b6293d
[feat] VoteJpaEntity.updateFrom 추가 (#97)
hd0rable Jul 23, 2025
1bde1e6
[feat] VoteJpaEntity.updateFrom 추가 (#97)
hd0rable Jul 23, 2025
be08e43
[feat] PostType enum 작성 (#97)
hd0rable Jul 23, 2025
c704fe8
[remove] 안쓰는 함수 삭제 (#97)
hd0rable Jul 23, 2025
b1d1387
[test] 댓글 생성 단위 테스트코드 작성 (#97)
hd0rable Jul 23, 2025
0f90c97
[test] 댓글 생성 통합 테스트코드 작성 (#97)
hd0rable Jul 23, 2025
5c5e2e9
[test] Comment 도메인 단위 테스트 코드 작성 (#97)
hd0rable Jul 23, 2025
f09f794
[test] 테스트펙토리 메서드 누락 값 추가 (#97)
hd0rable Jul 23, 2025
2c01377
[test] 메서드 명 수정 (#97)
hd0rable Jul 23, 2025
a0c62cb
[test] postId 하드 코딩 수정 (#97)
hd0rable Jul 23, 2025
9dfe2d0
[refactor] todo 주석 수정(#97)
hd0rable Jul 23, 2025
ce6a11a
[feat] Google Guava 의존성 추가(#99)
hd0rable Jul 24, 2025
1e03d25
[feat] Comment 좋아요 관련 도메인 책임 함수 추가 (#99)
hd0rable Jul 24, 2025
35732e7
[feat] 댓글 좋아요 상태변경 컨트롤러 작성 (#99)
hd0rable Jul 24, 2025
2d1534e
[feat] CommentCommandPort.update 정의 (#99)
hd0rable Jul 24, 2025
240bbb3
[feat] CommentCommandPersistenceAdapter.update 구현 (#99)
hd0rable Jul 24, 2025
c5bf4fe
[feat] 좋아요 상태변경 request dto 작성 (#99)
hd0rable Jul 24, 2025
57dac46
[feat] 좋아요 상태변경 command dto 작성 (#99)
hd0rable Jul 24, 2025
bbb9d10
[feat] 좋아요 상태변경 response dto 작성 (#99)
hd0rable Jul 24, 2025
1374d14
[feat] 좋아요 상태변경 result dto 작성 (#99)
hd0rable Jul 24, 2025
3a8f508
[feat] CommentJpaEntity.updateFrom 추가 및 테스트용 updateLikeCount작성 (#99)
hd0rable Jul 24, 2025
94d998f
[feat] CommentLikeCommandPort 작성 (#99)
hd0rable Jul 24, 2025
a8e2832
[feat] CommentLikeJpaRepository 관련 함수 작성 (#99)
hd0rable Jul 24, 2025
e82067a
[feat] CommentLikeCommandPersistenceAdapter 작성 (#99)
hd0rable Jul 24, 2025
eb4d6e7
[feat] CommentLikeQueryPersistenceAdapter 작성 (#99)
hd0rable Jul 24, 2025
42d4870
[feat] CommentLikeQueryPort 작성 (#99)
hd0rable Jul 24, 2025
aea45e0
[feat] LikedComments 사용자가 저장한 댓글 일급 컬렉션 (#99)
hd0rable Jul 24, 2025
00aaf95
[feat] 관련 에러코드 작성 (#99)
hd0rable Jul 24, 2025
3e2b490
[feat] 좋아요 상태변경 changeLikeStatusComment 유즈케이스 작성 (#99)
hd0rable Jul 24, 2025
332426f
[feat] changeLikeStatusComment 유즈케이스 구현체 CommentLikeService 서비스 작성 (#99)
hd0rable Jul 24, 2025
0016a7d
[remove] 더미 파일 삭제 (#99)
hd0rable Jul 24, 2025
8aa574f
[refactor] request boolean 타입 수정 (#99)
hd0rable Jul 24, 2025
bd1a31f
[test] createCommentLike 메서드 작성 (#99)
hd0rable Jul 24, 2025
91b34f2
[test] Comment 좋아요 업데이트 관련 단위 테스트 코드 추가 (#99)
hd0rable Jul 24, 2025
ec1c60c
[test] 댓글 좋아요 상태변경 테스트코드 추가 (#99)
hd0rable Jul 24, 2025
4e77647
[fix] 누락 어노테이션 추가 (#97)
hd0rable Jul 24, 2025
2944142
Merge branch 'feat/#97-comment-create' into feat/#99-comment-like
hd0rable Jul 24, 2025
39cb576
[refactor] 리뷰 반영 리펙토링 (#99)
hd0rable Jul 24, 2025
04e17d1
[refactor] 댓글 좋아요 CommentLike 도메인이 하도록 검증(#99)
hd0rable Jul 25, 2025
343b12c
[refactor] CommentLikeJpaRepository.existsByUserIdAndCommentId (#99)
hd0rable Jul 25, 2025
01a8f6b
[refactor] 일급컬렉션 조회 하지않고 단순 해당댓글에대해 좋아요여부만 조회한뒤 CommentLike가 검증하도록 리펙…
hd0rable Jul 25, 2025
7b824bf
[refactor] comment가 검증하도록 리펙 (#99)
hd0rable Jul 25, 2025
2eacfd8
[test] 테스트 코드 수정 (#97)
hd0rable Jul 26, 2025
7c1249f
[refactor]RoomParticipantService 도메인 서비스 (#97)
hd0rable Jul 26, 2025
3d680a5
[refactor]validateCreateComment 검증 추가 (#97)
hd0rable Jul 26, 2025
770b6f2
[refactor] 관련 에러코드 수정및 추가(#97)
hd0rable Jul 26, 2025
4f7b632
[refactor] 댓글 생성시 권한 검증 로직 추가(#97)
hd0rable Jul 26, 2025
f438ba6
[refactor] CommentCountUpdatable.getRoomId 추가 (#97)
hd0rable Jul 26, 2025
791fee4
[test] 테스트마다 독립성 보장 어노테이션 추가 (#97)
hd0rable Jul 26, 2025
2e18e20
Merge remote-tracking branch 'origin/feat/#97-comment-create' into fe…
hd0rable Jul 26, 2025
0ee568d
[refactor] 댓글 관련 접근 정책 인터페이스 도입 (#99)
hd0rable Jul 26, 2025
bf29556
[refactor] 게시물 별 댓글 접근 정책 인터페이스 구현 (#99)
hd0rable Jul 26, 2025
5860839
[refactor] 게시물 조회 서비스 작성 (#99)
hd0rable Jul 26, 2025
0208ed6
[refactor] 댓글 접근 관련 권한 댓글 도메인 서비스 작성 (#99)
hd0rable Jul 26, 2025
1dcead4
[refactor] 댓글 작성/좋아요 관련 로직 정책도입에 따른 로직 수정 (#99)
hd0rable Jul 26, 2025
b76b43f
[refactor] 관련헬퍼 어플리케이션으로 이동(#99)
hd0rable Jul 27, 2025
e0c0aac
[refactor] RoomPost 구현 (#99)
hd0rable Jul 27, 2025
a7a41bf
[refactor] 댓글접근관련 정책 Config (#99)
hd0rable Jul 27, 2025
e2fd0e8
[refactor] 댓글 생성/좋아요 로직 수정 (#99)
hd0rable Jul 27, 2025
a0b31f9
[refactor] RoomPost 구현 (#99)
hd0rable Jul 27, 2025
0638934
[refactor] RoomPost 구현 (#99)
hd0rable Jul 27, 2025
e5a2507
[refactor] RoomPostCommentAccessPolicy (#99)
hd0rable Jul 27, 2025
c1cc63f
[refactor] getRoomId()는 Roompost만 구현하도록 (#99)
hd0rable Jul 27, 2025
2e5c3aa
[refactor] 안쓰는 메서드 삭제 (#99)
hd0rable Jul 27, 2025
1931a1a
[rename] 파일위치 변경 (#99)
hd0rable Jul 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ dependencies {
// MapStruct
implementation 'org.mapstruct:mapstruct:1.5.5.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final'

//Google Guava
implementation 'com.google.guava:guava:33.2.0-jre'
}

def querydslDir = layout.buildDirectory.dir("generated/querydsl").get().asFile
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
package konkuk.thip.comment.adapter.in.web;

import jakarta.validation.Valid;
import konkuk.thip.comment.adapter.in.web.request.CommentCreateRequest;
import konkuk.thip.comment.adapter.in.web.request.CommentIsLikeRequest;
import konkuk.thip.comment.adapter.in.web.response.CommentIdResponse;
import konkuk.thip.comment.adapter.in.web.response.CommentIsLikeResponse;
import konkuk.thip.comment.application.port.in.CommentCreateUseCase;
import konkuk.thip.comment.application.port.in.CommentLikeUseCase;
import konkuk.thip.common.dto.BaseResponse;
import konkuk.thip.common.security.annotation.UserId;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
public class CommentCommandController {

private final CommentCreateUseCase commentCreateUseCase;
private final CommentLikeUseCase commentLikeUseCase;

/**
* 댓글/답글 작성
* parentId:{Long},isReplyRequest:true 답글
* parentId:null,isReplyRequest:false 댓글
*/
@PostMapping("/comments/{postId}")
public BaseResponse<CommentIdResponse> createComment(@RequestBody @Valid final CommentCreateRequest request,
@PathVariable("postId") final Long postId,
@UserId final Long userId) {
return BaseResponse.ok(CommentIdResponse.of(commentCreateUseCase.createComment(request.toCommand(userId,postId))));
}

//댓글 좋아요 상태 변경: true -> 좋아요, false -> 좋아요 취소
@PostMapping("/comments/{commentId}/likes")
public BaseResponse<CommentIsLikeResponse> likeComment(@RequestBody @Valid final CommentIsLikeRequest request,
@PathVariable("commentId") final Long commentId,
@UserId final Long userId) {
return BaseResponse.ok(CommentIsLikeResponse.of(commentLikeUseCase.changeLikeStatusComment(request.toCommand(userId, commentId))));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package konkuk.thip.comment.adapter.in.web.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import konkuk.thip.comment.application.port.in.dto.CommentCreateCommand;

public record CommentCreateRequest(

@NotBlank(message = "댓글 내용은 필수입니다.")
String content,

@NotNull(message = "답글 여부는 필수입니다.")
Boolean isReplyRequest,

Long parentId,

@NotBlank(message = "게시물 타입은 필수입니다.")
String postType

) {
public CommentCreateCommand toCommand(Long userId, Long postId) {
return new CommentCreateCommand(
content,
isReplyRequest,
parentId,
postType,
postId,
userId
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package konkuk.thip.comment.adapter.in.web.request;

import jakarta.validation.constraints.NotNull;
import konkuk.thip.comment.application.port.in.dto.CommentIsLikeCommand;

public record CommentIsLikeRequest(
@NotNull(message = "좋아요 여부는 필수입니다.")
Boolean type
) {
public CommentIsLikeCommand toCommand(Long userId, Long commentId) {
return new CommentIsLikeCommand(userId, commentId, type);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package konkuk.thip.comment.adapter.in.web.response;

public record CommentIdResponse(Long commentId) {
public static CommentIdResponse of(Long commentId) {
return new CommentIdResponse(commentId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package konkuk.thip.comment.adapter.in.web.response;

import konkuk.thip.comment.application.port.in.dto.CommentIsLikeResult;

public record CommentIsLikeResponse(
Long commentId,
boolean isLiked
) {
public static CommentIsLikeResponse of(CommentIsLikeResult commentIsLikeResult) {
return new CommentIsLikeResponse(commentIsLikeResult.commentId(), commentIsLikeResult.isLiked());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package konkuk.thip.comment.adapter.out.jpa;

import com.google.common.annotations.VisibleForTesting;
import jakarta.persistence.*;
import konkuk.thip.comment.domain.Comment;
import konkuk.thip.common.entity.BaseJpaEntity;
import konkuk.thip.common.post.PostType;
import konkuk.thip.post.adapter.out.jpa.PostJpaEntity;
import konkuk.thip.user.adapter.out.jpa.UserJpaEntity;
import lombok.*;
Expand All @@ -26,10 +29,19 @@ public class CommentJpaEntity extends BaseJpaEntity {
@Column(name = "report_count", nullable = false)
private int reportCount = 0;

@Builder.Default
@Column(name = "like_count", nullable = false)
private int likeCount = 0;

//TODO 상속구조 해지하면서 postType만 가질지, postId + postType가질지 논의 필요
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id", nullable = false)
private PostJpaEntity postJpaEntity;

@Enumerated(EnumType.STRING)
@Column(name = "post_type", nullable = false, length = 10)
private PostType postType;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private UserJpaEntity userJpaEntity;
Expand All @@ -38,4 +50,15 @@ public class CommentJpaEntity extends BaseJpaEntity {
@JoinColumn(name = "parent_id")
private CommentJpaEntity parent;

public CommentJpaEntity updateFrom(Comment comment) {
this.reportCount = comment.getReportCount();
this.likeCount = comment.getLikeCount();
return this;
}

@VisibleForTesting
public void updateLikeCount(int likeCount) {
this.likeCount = likeCount;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ public class CommentMapper {
public CommentJpaEntity toJpaEntity(Comment comment, PostJpaEntity postJpaEntity, UserJpaEntity userJpaEntity, CommentJpaEntity commentJpaEntity) {
return CommentJpaEntity.builder()
.content(comment.getContent())
.likeCount(comment.getLikeCount())
.reportCount(comment.getReportCount())
.postJpaEntity(postJpaEntity)
.postType(comment.getPostType())
.userJpaEntity(userJpaEntity)
.parent(commentJpaEntity)
.build();
Expand All @@ -24,7 +26,9 @@ public Comment toDomainEntity(CommentJpaEntity commentJpaEntity) {
.id(commentJpaEntity.getCommentId())
.content(commentJpaEntity.getContent())
.reportCount(commentJpaEntity.getReportCount())
.likeCount(commentJpaEntity.getLikeCount())
.targetPostId(commentJpaEntity.getPostJpaEntity().getPostId())
.postType(commentJpaEntity.getPostType())
.creatorId(commentJpaEntity.getUserJpaEntity().getUserId())
.parentCommentId(commentJpaEntity.getParent() != null ? commentJpaEntity.getParent().getCommentId() : null)
.createdAt(commentJpaEntity.getCreatedAt())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,84 @@
package konkuk.thip.comment.adapter.out.persistence;

import konkuk.thip.comment.adapter.out.jpa.CommentJpaEntity;
import konkuk.thip.comment.adapter.out.mapper.CommentMapper;
import konkuk.thip.comment.adapter.out.persistence.repository.CommentJpaRepository;
import konkuk.thip.comment.application.port.out.CommentCommandPort;
import konkuk.thip.comment.domain.Comment;
import konkuk.thip.common.exception.EntityNotFoundException;
import konkuk.thip.common.post.PostType;
import konkuk.thip.feed.adapter.out.persistence.repository.FeedJpaRepository;
import konkuk.thip.post.adapter.out.jpa.PostJpaEntity;
import konkuk.thip.record.adapter.out.persistence.repository.RecordJpaRepository;
import konkuk.thip.user.adapter.out.jpa.UserJpaEntity;
import konkuk.thip.user.adapter.out.persistence.repository.UserJpaRepository;
import konkuk.thip.vote.adapter.out.persistence.repository.VoteJpaRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.Optional;

import static konkuk.thip.common.exception.code.ErrorCode.*;

@Repository
@RequiredArgsConstructor
public class CommentCommandPersistenceAdapter implements CommentCommandPort {

private final CommentJpaRepository commentJpaRepository;
private final FeedJpaRepository feedJpaRepository;
private final RecordJpaRepository recordJpaRepository;
private final VoteJpaRepository voteJpaRepository;
private final UserJpaRepository userJpaRepository;
private final CommentMapper commentMapper;

@Override
public Long save(Comment comment) {

// 1. 작성자(User) 조회 및 존재 검증
UserJpaEntity userJpaEntity = userJpaRepository.findById(comment.getCreatorId()).orElseThrow(
() -> new EntityNotFoundException(USER_NOT_FOUND)
);

// 2. 게시물(Post) 조회 및 존재 검증
PostJpaEntity postJpaEntity = findPostJpaEntity(comment.getPostType(), comment.getTargetPostId());

// 3. 부모 댓글 조회 (있을 경우)
CommentJpaEntity parentCommentJpaEntity = null;
if (comment.getParentCommentId() != null) {
parentCommentJpaEntity = commentJpaRepository.findById(comment.getParentCommentId())
.orElseThrow(() -> new EntityNotFoundException(COMMENT_NOT_FOUND));
}

return commentJpaRepository.save(
commentMapper.toJpaEntity(comment, postJpaEntity, userJpaEntity,parentCommentJpaEntity)
).getCommentId();
}

private PostJpaEntity findPostJpaEntity(PostType postType, Long postId) {
return switch (postType) {
case FEED -> feedJpaRepository.findById(postId)
.orElseThrow(() -> new EntityNotFoundException(FEED_NOT_FOUND));
case RECORD -> recordJpaRepository.findById(postId)
.orElseThrow(() -> new EntityNotFoundException(RECORD_NOT_FOUND));
case VOTE -> voteJpaRepository.findById(postId)
.orElseThrow(() -> new EntityNotFoundException(VOTE_NOT_FOUND));
};
}

@Override
public Optional<Comment> findById(Long id) {
return commentJpaRepository.findById(id)
.map(commentMapper::toDomainEntity);
}

@Override
public void update(Comment comment) {

CommentJpaEntity commentJpaEntity = commentJpaRepository.findById(comment.getId()).orElseThrow(
() -> new EntityNotFoundException(COMMENT_NOT_FOUND)
);

commentJpaRepository.save(commentJpaEntity.updateFrom(comment));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package konkuk.thip.comment.adapter.out.persistence;

import konkuk.thip.comment.adapter.out.jpa.CommentJpaEntity;
import konkuk.thip.comment.adapter.out.jpa.CommentLikeJpaEntity;
import konkuk.thip.comment.adapter.out.persistence.repository.CommentJpaRepository;
import konkuk.thip.comment.adapter.out.persistence.repository.CommentLikeJpaRepository;
import konkuk.thip.comment.application.port.out.CommentLikeCommandPort;
import konkuk.thip.common.exception.EntityNotFoundException;
import konkuk.thip.user.adapter.out.jpa.UserJpaEntity;
import konkuk.thip.user.adapter.out.persistence.repository.UserJpaRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import static konkuk.thip.common.exception.code.ErrorCode.*;

@Repository
@RequiredArgsConstructor
public class CommentLikeCommandPersistenceAdapter implements CommentLikeCommandPort {

private final CommentLikeJpaRepository commentLikeJpaRepository;
private final CommentJpaRepository commentJpaRepository;
private final UserJpaRepository userJpaRepository;

@Override
public void save(Long userId, Long commentId) {

UserJpaEntity user = userJpaRepository.findById(userId)
.orElseThrow(() -> new EntityNotFoundException(USER_NOT_FOUND));
CommentJpaEntity comment = commentJpaRepository.findById(commentId)
.orElseThrow(() -> new EntityNotFoundException(COMMENT_NOT_FOUND));

CommentLikeJpaEntity commentLike = CommentLikeJpaEntity.builder()
.userJpaEntity(user)
.commentJpaEntity(comment)
.build();

commentLikeJpaRepository.save(commentLike);
}

@Override
public void delete(Long userId, Long commentId) {
commentLikeJpaRepository.deleteByUserIdAndCommentId(userId, commentId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package konkuk.thip.comment.adapter.out.persistence;

import konkuk.thip.comment.adapter.out.mapper.CommentLikeMapper;
import konkuk.thip.comment.adapter.out.mapper.CommentMapper;
import konkuk.thip.comment.adapter.out.persistence.repository.CommentLikeJpaRepository;
import konkuk.thip.comment.application.port.out.CommentLikeQueryPort;
import konkuk.thip.user.adapter.out.persistence.repository.UserJpaRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class CommentLikeQueryPersistenceAdapter implements CommentLikeQueryPort {

private final CommentLikeJpaRepository commentLikeJpaRepository;
private final UserJpaRepository userJpaRepository;
private final CommentMapper commentMapper;
private final CommentLikeMapper commentLikeMapper;

@Override
public boolean isLikedCommentByUser(Long userId, Long commentId) {
return commentLikeJpaRepository.existsByUserIdAndCommentId(userId, commentId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,4 @@ public class CommentQueryPersistenceAdapter implements CommentQueryPort {
private final CommentJpaRepository jpaRepository;
private final CommentMapper userMapper;

@Override
public int countByPostId(Long postId) {
return jpaRepository.countByPostJpaEntity_PostId(postId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package konkuk.thip.comment.adapter.out.persistence.repository;

import konkuk.thip.comment.adapter.out.jpa.CommentLikeJpaEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface CommentLikeJpaRepository extends JpaRepository<CommentLikeJpaEntity, Long> {
@Query(value = "SELECT * FROM comment_likes WHERE user_id = :userId", nativeQuery = true)
List<CommentLikeJpaEntity> findAllByUserId(Long userId);

@Modifying
@Query(value = "DELETE FROM comment_likes WHERE user_id = :userId AND comment_id = :commentId", nativeQuery = true)
void deleteByUserIdAndCommentId(@Param("userId") Long userId, @Param("commentId") Long commentId);

@Query(value = "SELECT EXISTS(SELECT 1 FROM comment_likes WHERE user_id = :userId AND comment_id = :commentId)", nativeQuery = true)
boolean existsByUserIdAndCommentId(@Param("userId") Long userId, @Param("commentId") Long commentId);
}
Loading