-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] 댓글 좋아요 상태변경 api 개발 #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
7bdfd23
[remove] 더미파일 삭제(#97)
hd0rable 18fdd7f
[feat] Comment 도메인 생성 책임 코드 추가 (#97)
hd0rable e07ccf6
[feat] CommentCommandController.createComment 작성 (#97)
hd0rable e832743
[feat] CommentCommandPersistenceAdapter.save / findById 작성 (#97)
hd0rable 5e482df
[feat] CommentCommandPort 관련 함수 추가 작성 (#97)
hd0rable 3b9b5d5
[feat] CommentCountUpdatable작성 (#97)
hd0rable a264cda
[feat] 댓글 생성 Command dto 작성 (#97)
hd0rable 3a55c36
[feat] 댓글 생성 request dto 작성 (#97)
hd0rable 81ff6ca
[feat] 댓글 생성 유즈케이스 구현체 CommentCreateService 작성 (#97)
hd0rable 7c40758
[feat] 댓글 생성 유즈케이스 CommentCreateUseCase 작성 (#97)
hd0rable c189a0f
[feat] CommentIdResponse dto 작성 (#97)
hd0rable 2fa454a
[feat] CommentJpaEntity에 postType,likeCount 추가 (#97)
hd0rable 03fee58
[feat] CommentMapper 에 likeCount,postType 매핑추가 (#97)
hd0rable 567c537
[feat] 관련 에러코드 추가 (#97)
hd0rable d6cb099
[feat] vote,record, feed CommentCountUpdatableincreaseCommentCount공통 …
hd0rable 954f9d7
[feat] RecordCommandPersistenceAdapter.findById / update 작성 (#97)
hd0rable 376be34
[feat] VoteCommandPersistenceAdapter.findById / updateVote 작성 (#97)
hd0rable ee6addf
[feat] RecordCommandPort 관련 함수 추가 (#97)
hd0rable 8351056
[feat] VoteCommandPort 관련 함수 정의 (#97)
hd0rable 6b6293d
[feat] VoteJpaEntity.updateFrom 추가 (#97)
hd0rable 1bde1e6
[feat] VoteJpaEntity.updateFrom 추가 (#97)
hd0rable be08e43
[feat] PostType enum 작성 (#97)
hd0rable c704fe8
[remove] 안쓰는 함수 삭제 (#97)
hd0rable b1d1387
[test] 댓글 생성 단위 테스트코드 작성 (#97)
hd0rable 0f90c97
[test] 댓글 생성 통합 테스트코드 작성 (#97)
hd0rable 5c5e2e9
[test] Comment 도메인 단위 테스트 코드 작성 (#97)
hd0rable f09f794
[test] 테스트펙토리 메서드 누락 값 추가 (#97)
hd0rable 2c01377
[test] 메서드 명 수정 (#97)
hd0rable a0c62cb
[test] postId 하드 코딩 수정 (#97)
hd0rable 9dfe2d0
[refactor] todo 주석 수정(#97)
hd0rable ce6a11a
[feat] Google Guava 의존성 추가(#99)
hd0rable 1e03d25
[feat] Comment 좋아요 관련 도메인 책임 함수 추가 (#99)
hd0rable 35732e7
[feat] 댓글 좋아요 상태변경 컨트롤러 작성 (#99)
hd0rable 2d1534e
[feat] CommentCommandPort.update 정의 (#99)
hd0rable 240bbb3
[feat] CommentCommandPersistenceAdapter.update 구현 (#99)
hd0rable c5bf4fe
[feat] 좋아요 상태변경 request dto 작성 (#99)
hd0rable 57dac46
[feat] 좋아요 상태변경 command dto 작성 (#99)
hd0rable bbb9d10
[feat] 좋아요 상태변경 response dto 작성 (#99)
hd0rable 1374d14
[feat] 좋아요 상태변경 result dto 작성 (#99)
hd0rable 3a8f508
[feat] CommentJpaEntity.updateFrom 추가 및 테스트용 updateLikeCount작성 (#99)
hd0rable 94d998f
[feat] CommentLikeCommandPort 작성 (#99)
hd0rable a8e2832
[feat] CommentLikeJpaRepository 관련 함수 작성 (#99)
hd0rable e82067a
[feat] CommentLikeCommandPersistenceAdapter 작성 (#99)
hd0rable eb4d6e7
[feat] CommentLikeQueryPersistenceAdapter 작성 (#99)
hd0rable 42d4870
[feat] CommentLikeQueryPort 작성 (#99)
hd0rable aea45e0
[feat] LikedComments 사용자가 저장한 댓글 일급 컬렉션 (#99)
hd0rable 00aaf95
[feat] 관련 에러코드 작성 (#99)
hd0rable 3e2b490
[feat] 좋아요 상태변경 changeLikeStatusComment 유즈케이스 작성 (#99)
hd0rable 332426f
[feat] changeLikeStatusComment 유즈케이스 구현체 CommentLikeService 서비스 작성 (#99)
hd0rable 0016a7d
[remove] 더미 파일 삭제 (#99)
hd0rable 8aa574f
[refactor] request boolean 타입 수정 (#99)
hd0rable bd1a31f
[test] createCommentLike 메서드 작성 (#99)
hd0rable 91b34f2
[test] Comment 좋아요 업데이트 관련 단위 테스트 코드 추가 (#99)
hd0rable ec1c60c
[test] 댓글 좋아요 상태변경 테스트코드 추가 (#99)
hd0rable 4e77647
[fix] 누락 어노테이션 추가 (#97)
hd0rable 2944142
Merge branch 'feat/#97-comment-create' into feat/#99-comment-like
hd0rable 39cb576
[refactor] 리뷰 반영 리펙토링 (#99)
hd0rable 04e17d1
[refactor] 댓글 좋아요 CommentLike 도메인이 하도록 검증(#99)
hd0rable 343b12c
[refactor] CommentLikeJpaRepository.existsByUserIdAndCommentId (#99)
hd0rable 01a8f6b
[refactor] 일급컬렉션 조회 하지않고 단순 해당댓글에대해 좋아요여부만 조회한뒤 CommentLike가 검증하도록 리펙…
hd0rable 7b824bf
[refactor] comment가 검증하도록 리펙 (#99)
hd0rable 2eacfd8
[test] 테스트 코드 수정 (#97)
hd0rable 7c1249f
[refactor]RoomParticipantService 도메인 서비스 (#97)
hd0rable 3d680a5
[refactor]validateCreateComment 검증 추가 (#97)
hd0rable 770b6f2
[refactor] 관련 에러코드 수정및 추가(#97)
hd0rable 4f7b632
[refactor] 댓글 생성시 권한 검증 로직 추가(#97)
hd0rable f438ba6
[refactor] CommentCountUpdatable.getRoomId 추가 (#97)
hd0rable 791fee4
[test] 테스트마다 독립성 보장 어노테이션 추가 (#97)
hd0rable 2e18e20
Merge remote-tracking branch 'origin/feat/#97-comment-create' into fe…
hd0rable 0ee568d
[refactor] 댓글 관련 접근 정책 인터페이스 도입 (#99)
hd0rable bf29556
[refactor] 게시물 별 댓글 접근 정책 인터페이스 구현 (#99)
hd0rable 5860839
[refactor] 게시물 조회 서비스 작성 (#99)
hd0rable 0208ed6
[refactor] 댓글 접근 관련 권한 댓글 도메인 서비스 작성 (#99)
hd0rable 1dcead4
[refactor] 댓글 작성/좋아요 관련 로직 정책도입에 따른 로직 수정 (#99)
hd0rable b76b43f
[refactor] 관련헬퍼 어플리케이션으로 이동(#99)
hd0rable e0c0aac
[refactor] RoomPost 구현 (#99)
hd0rable a7a41bf
[refactor] 댓글접근관련 정책 Config (#99)
hd0rable e2fd0e8
[refactor] 댓글 생성/좋아요 로직 수정 (#99)
hd0rable a0b31f9
[refactor] RoomPost 구현 (#99)
hd0rable 0638934
[refactor] RoomPost 구현 (#99)
hd0rable e5a2507
[refactor] RoomPostCommentAccessPolicy (#99)
hd0rable c1cc63f
[refactor] getRoomId()는 Roompost만 구현하도록 (#99)
hd0rable 2e5c3aa
[refactor] 안쓰는 메서드 삭제 (#99)
hd0rable 1931a1a
[rename] 파일위치 변경 (#99)
hd0rable File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 33 additions & 1 deletion
34
src/main/java/konkuk/thip/comment/adapter/in/web/CommentCommandController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)))); | ||
| } | ||
|
|
||
| } |
31 changes: 31 additions & 0 deletions
31
src/main/java/konkuk/thip/comment/adapter/in/web/request/CommentCreateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/main/java/konkuk/thip/comment/adapter/in/web/request/CommentIsLikeRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
7 changes: 0 additions & 7 deletions
7
src/main/java/konkuk/thip/comment/adapter/in/web/request/DummyRequest.java
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
src/main/java/konkuk/thip/comment/adapter/in/web/response/CommentIdResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/main/java/konkuk/thip/comment/adapter/in/web/response/CommentIsLikeResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | ||
| } | ||
| } |
7 changes: 0 additions & 7 deletions
7
src/main/java/konkuk/thip/comment/adapter/in/web/response/DummyResponse.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...in/java/konkuk/thip/comment/adapter/out/persistence/CommentCommandPersistenceAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | ||
| } | ||
|
|
||
| } |
44 changes: 44 additions & 0 deletions
44
...ava/konkuk/thip/comment/adapter/out/persistence/CommentLikeCommandPersistenceAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
.../java/konkuk/thip/comment/adapter/out/persistence/CommentLikeQueryPersistenceAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...java/konkuk/thip/comment/adapter/out/persistence/repository/CommentLikeJpaRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.