Skip to content

Commit

Permalink
feat : 좋아요한 댓글 불러오기 구현 완료 (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen-ing committed Jan 22, 2025
1 parent 011cbb0 commit a082ed8
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 8 deletions.
18 changes: 18 additions & 0 deletions src/main/java/com/ripple/BE/post/dto/LikeCommentDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.ripple.BE.post.dto;

import com.ripple.BE.post.domain.Comment;
import com.ripple.BE.post.domain.type.PostType;
import java.time.LocalDateTime;

public record LikeCommentDTO(
Long id, String content, String postName, PostType type, LocalDateTime createdDate) {

public static LikeCommentDTO toLikeCommentDTO(Comment comment) {
return new LikeCommentDTO(
comment.getId(),
comment.getContent(),
comment.getPost().getTitle(),
comment.getPost().getType(),
comment.getCreatedDate());
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/ripple/BE/post/dto/LikeCommentListDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ripple.BE.post.dto;

import com.ripple.BE.post.domain.Comment;
import java.util.List;

public record LikeCommentListDTO(List<LikeCommentDTO> likeCommentDTOList) {
public static LikeCommentListDTO toLikeCommentListDTO(List<Comment> commentList) {
return new LikeCommentListDTO(
commentList.stream().map(LikeCommentDTO::toLikeCommentDTO).toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.ripple.BE.post.dto.response;

import com.ripple.BE.post.dto.LikeCommentListDTO;
import java.util.List;

public record LikeCommentListResponse(List<LikeCommentResponse> likeCommentResponses) {
public static LikeCommentListResponse toLikeCommentListResponse(
LikeCommentListDTO likeCommentListDTO) {
return new LikeCommentListResponse(
likeCommentListDTO.likeCommentDTOList().stream()
.map(LikeCommentResponse::toLikeCommentResponse)
.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ripple.BE.post.dto.response;

import com.ripple.BE.post.domain.type.PostType;
import com.ripple.BE.post.dto.LikeCommentDTO;
import java.time.LocalDateTime;

public record LikeCommentResponse(
Long id, String content, String postName, PostType type, LocalDateTime createdDate) {
public static LikeCommentResponse toLikeCommentResponse(LikeCommentDTO likeCommentDTO) {
return new LikeCommentResponse(
likeCommentDTO.id(),
likeCommentDTO.content(),
likeCommentDTO.postName(),
likeCommentDTO.type(),
likeCommentDTO.createdDate());
}
}
10 changes: 5 additions & 5 deletions src/main/java/com/ripple/BE/user/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.ripple.BE.global.dto.response.ApiResponse;
import com.ripple.BE.learning.dto.FailQuizListDTO;
import com.ripple.BE.learning.dto.response.FailQuizListResponse;
import com.ripple.BE.post.dto.CommentListDTO;
import com.ripple.BE.post.dto.LikeCommentListDTO;
import com.ripple.BE.post.dto.PostListDTO;
import com.ripple.BE.post.dto.response.CommentListResponse;
import com.ripple.BE.post.dto.response.LikeCommentListResponse;
import com.ripple.BE.post.dto.response.PostListResponse;
import com.ripple.BE.user.domain.CustomUserDetails;
import com.ripple.BE.user.domain.type.Level;
Expand Down Expand Up @@ -120,14 +120,14 @@ public ResponseEntity<ApiResponse<Object>> getWrongQuizzes(
.body(ApiResponse.from(FailQuizListResponse.toFailQuizListResponse(failQuizListDTO)));
}

@Operation(summary = "좋아요한 댓글 조회", description = "로그인한 유저가 좋아요한 댓글을 조회합니다.")
@Operation(summary = "내가 좋아요한 댓글 조회", description = "로그인한 유저가 좋아요한 댓글을 조회합니다.")
@GetMapping("/like-comments")
public ResponseEntity<ApiResponse<Object>> getMyLikeComments(
@AuthenticationPrincipal CustomUserDetails customUserDetails) {

CommentListDTO myLikeComments = myPageService.getMyLikeComments(customUserDetails.getId());
LikeCommentListDTO myLikeComments = myPageService.getMyLikeComments(customUserDetails.getId());

return ResponseEntity.status(HttpStatus.OK)
.body(ApiResponse.from(CommentListResponse.toCommentListResponse(myLikeComments)));
.body(ApiResponse.from(LikeCommentListResponse.toLikeCommentListResponse(myLikeComments)));
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/ripple/BE/user/service/MyPageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.ripple.BE.learning.repository.QuizRepository;
import com.ripple.BE.post.domain.Comment;
import com.ripple.BE.post.domain.Post;
import com.ripple.BE.post.dto.CommentListDTO;
import com.ripple.BE.post.dto.LikeCommentListDTO;
import com.ripple.BE.post.dto.PostListDTO;
import com.ripple.BE.post.repository.comment.CommentRepository;
import com.ripple.BE.post.repository.commentlike.CommentLikeRepository;
Expand Down Expand Up @@ -74,10 +74,10 @@ public FailQuizListDTO getMyFailQuizzes(final long userId, Level level) {
}

@Transactional(readOnly = true)
public CommentListDTO getMyLikeComments(final long userId) {
public LikeCommentListDTO getMyLikeComments(final long userId) {

List<Comment> commentsLikedByUser = commentLikeRepository.findCommentsLikedByUser(userId);

return CommentListDTO.toCommentListDTO(commentsLikedByUser);
return LikeCommentListDTO.toLikeCommentListDTO(commentsLikedByUser);
}
}

0 comments on commit a082ed8

Please sign in to comment.