Skip to content

Commit

Permalink
fix[be] : #4 - 코멘트 리스트 수정 및 fe 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
G1Huh committed Jan 7, 2025
1 parent a83705f commit 1250151
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public class BookCommentReadService {
private final BookCommentLikeRepository bookCommentLikeRepository;

// 리뷰 리스트
// public Slice<BookCommentResponseDto> getPagedBookComments(BookId bookId, Pageable pageable) {
// Slice<BookCommentResponseDto> bookCommentPage = bookCommentRepository.findByBookId(bookId, pageable);
//
// return bookCommentPage;
// }
public Slice<BookCommentResponseDto> getPagedBookComments(BookId bookId, Pageable pageable) {
Slice<BookCommentResponseDto> bookCommentPage = bookCommentRepository.findByBookId(bookId, pageable);

return bookCommentPage;
}

// 내가 작성한 도서 리뷰 찾기
public BookComment findByMemberAndBook(Member member, Book book) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public interface BookCommentRepository {
void deleteById(BookCommentId bookCommentId);


// Slice<BookCommentResponseDto> findByBookId(BookId bookId, Pageable pageable);
Slice<BookCommentResponseDto> findByBookId(BookId bookId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public BookComment findByMemberAndBook(Member member, Book book) {
}


// @Override
// public Slice<BookCommentResponseDto> findByBookId(BookId bookId, Pageable pageable) {
// Slice<BookCommentResponseDto> bookCommentEntity = bookCommentJpaRepository.findByBookEntity(bookId, pageable);
//
// return bookCommentEntity;
// }
@Override
public Slice<BookCommentResponseDto> findByBookId(BookId bookId, Pageable pageable) {
Slice<BookCommentResponseDto> bookCommentEntity = bookCommentJpaRepository.findByBookEntity(bookId, pageable);

return bookCommentEntity;
}

@Override
public BookComment save(BookComment bookComment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,20 @@
public interface BookCommentJpaRepository extends JpaRepository<BookCommentEntity, BookCommentId> {


// @Query("SELECT NEW movlit.be.book.domain.dto.BookCommentResponseDto("
// + " bc.bookCommentId,"
// + " bc.score,"
// + " bc.comment,"
// + " mb.nickname,"
// + " mb.profileImgUrl,"
// + " false,"
// + " lc.count,"
// + " (SELECT COUNT(bcc) FROM BookCommentEntity bcc WHERE bcc.bookEntity.bookId = :bookId)"
// + ")"
// + "FROM BookCommentEntity bc"
// + "LEFT JOIN BookCommentLikeCountEntity lc ON lc.bookCommentEntity.bookCommentId = bc.bookCommentId"
// + "LEFT JOIN MemberEntity mb ON mb.memberId = bc.memberEntity.memberId"
// + "WHERE bc.bookEntity = :bookId"
// + "ORDER BY bc.regDt DESC ")
// Slice<BookCommentResponseDto> findByBookEntity(@Param("bookId") BookId bookId,
// @Param("pageable") Pageable pageable);
@Query("SELECT NEW movlit.be.book.domain.dto.BookCommentResponseDto( "
+ "bc.bookCommentId, bc.score, bc.comment, "
+ "m.nickname, m.profileImgUrl , false, "
+ "IFNULL(bclc.count, 0) AS likeCount , bc.regDt, bc.updDt, "
+ "(SELECT COUNT(bcc) FROM BookCommentEntity bcc WHERE bcc.bookEntity.bookId = :bookId ) AS allCommentsCount"
+ ") "
+ "FROM BookCommentEntity bc "
+ "LEFT JOIN BookCommentLikeCountEntity bclc ON bclc.bookCommentEntity.bookCommentId = bc.bookCommentId "
+ "LEFT JOIN MemberEntity m ON m.memberId = bc.memberEntity.memberId "
+ "WHERE bc.bookEntity.bookId = :bookId "
+ "order by bc.regDt DESC "
)
Slice<BookCommentResponseDto> findByBookEntity(@Param("bookId") BookId bookId,
@Param("pageable") Pageable pageable);


Optional<BookCommentEntity> findByMemberEntityAndBookEntity(MemberEntity memberEntity, BookEntity bookEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,16 @@ public class BookCommentController {
private final MemberReadService memberReadService;

// 리뷰 리스트
// @GetMapping("{bookId}/comments")
// public ResponseEntity<Slice<BookCommentResponseDto>> bookCommentReadService(@PathVariable BookId bookId,
// @AuthenticationPrincipal MyMemberDetails details,
// @PageableDefault(size = 4, sort = "regDt", direction = Direction.DESC)
// Pageable pageable){
// //Book book = bookDetailReadService.findByBookId(bookId);
// Slice<BookCommentResponseDto> pagedResult = bookCommentReadService.getPagedBookComments(bookId, pageable);
//
//
// return ResponseEntity.ok(pagedResult);
// }
@GetMapping("{bookId}/comments")
public ResponseEntity<Slice<BookCommentResponseDto>> bookCommentReadService(@PathVariable BookId bookId,
@PageableDefault(size = 4, sort = "regDt", direction = Direction.DESC)
Pageable pageable){

Slice<BookCommentResponseDto> pagedResult = bookCommentReadService.getPagedBookComments(bookId, pageable);


return ResponseEntity.ok(pagedResult);
}

@GetMapping("{bookId}/myComment")
public ResponseEntity myComment(@PathVariable BookId bookId, @AuthenticationPrincipal MyMemberDetails details) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ public class BookDetailController {
@GetMapping("{bookId}/detail")
public BookDetailResponseDto getBookDetail(@PathVariable BookId bookId, @AuthenticationPrincipal MyMemberDetails details) {
BookDetailResponseDto bookDetailResponse = bookDetailReadService.getBookDetail(bookId);
System.out.println("&&detail 있니? : " + details);
System.out.println("&&detail의 mem정보" + details.getMemberId());
System.out.println("&&detail의 mem이름" + details.getUsername());
if(details != null){
System.out.println("&&detail 있니? : " + details);
System.out.println("&&detail의 mem정보" + details.getMemberId());
System.out.println("&&detail의 mem이름" + details.getUsername());
}


return bookDetailResponse;
}
Expand Down

0 comments on commit 1250151

Please sign in to comment.