Skip to content

Commit

Permalink
#256 refactor: 댓글 페이징 관련 처리 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-haeseung committed Nov 6, 2024
1 parent a031aea commit e95913d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -71,11 +69,10 @@ public ApiResponse<CommentResponseDTO.CommentDTO> updateComment(
@GetMapping("/posts/{post_id}/comments")
public ApiResponse<List<CommentResponseDTO.CommentDTO>> getComments(
@PathVariable("post_id") Long postId,
@AuthenticationPrincipal CustomMemberDetails memberDetails,
@PageableDefault(size = 10) Pageable pageable
@AuthenticationPrincipal CustomMemberDetails memberDetails
) {
Long memberId = memberDetails.getId();
List<Comment> comments = commentService.getComments(postId, memberId, pageable);
List<Comment> comments = commentService.getComments(postId, memberId);
return ApiResponse.onSuccess(SuccessStatus.COMMENT_OK, CommentConverter.toCommentResponseListDto(comments));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import com.codiary.backend.domain.comment.entity.Comment;
import java.util.List;
import org.springframework.data.domain.Pageable;

public interface CommentRepositoryCustom {

List<Comment> findByPostWithMemberInfoOrderByCreatedAtDesc(Long postId, Pageable pageable);
List<Comment> findByPostWithMemberInfoOrderByCreatedAtDesc(Long postId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;

@RequiredArgsConstructor
public class CommentRepositoryImpl implements CommentRepositoryCustom {

private final JPAQueryFactory queryFactory;

@Override
public List<Comment> findByPostWithMemberInfoOrderByCreatedAtDesc(Long postId, Pageable pageable) {
public List<Comment> findByPostWithMemberInfoOrderByCreatedAtDesc(Long postId) {
List<Comment> comments = queryFactory
.selectFrom(comment)
.leftJoin(comment.member, member)
.leftJoin(comment.post, post)
.where(comment.post.postId.eq(postId))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
// .offset(pageable.getOffset())
// .limit(pageable.getPageSize())
.fetch();

return comments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.codiary.backend.global.apiPayload.exception.handler.PostHandler;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -96,7 +95,7 @@ public Comment updateComment(Long commentId, Long memberId, CommentRequestDTO.Co
}

@Transactional(readOnly = true)
public List<Comment> getComments(Long postId, Long memberId, Pageable pageable) {
public List<Comment> getComments(Long postId, Long memberId) {
// validation: 사용자, post 유무 확인
Member requester = memberRepository.findById(memberId)
.orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND));
Expand All @@ -113,7 +112,7 @@ public List<Comment> getComments(Long postId, Long memberId, Pageable pageable)
}

// business logic: 댓글 조회
List<Comment> comments = commentRepository.findByPostWithMemberInfoOrderByCreatedAtDesc(postId, pageable);
List<Comment> comments = commentRepository.findByPostWithMemberInfoOrderByCreatedAtDesc(postId);

// response: comment list 반환
return comments;
Expand Down

0 comments on commit e95913d

Please sign in to comment.