diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentController.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentController.java index 6aa2c0b..0e98d2a 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentController.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentController.java @@ -1,10 +1,14 @@ package com.umc.DongnaeFriend.domain.account.sharing.controller; import com.umc.DongnaeFriend.domain.account.sharing.dto.ReqSharingCommentDto; +import com.umc.DongnaeFriend.domain.account.sharing.dto.ResSharingCommentList; +import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment; import com.umc.DongnaeFriend.domain.account.sharing.service.SharingCommentService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; +import java.util.List; + @RequiredArgsConstructor @RestController @RequestMapping("/account-books/sharing/comments") @@ -32,4 +36,10 @@ public String deleteComment(@PathVariable("commentId") Long commentId) { return ""; } + // [가계부 공유] 댓글 목록 조회 + @GetMapping("") + public ResSharingCommentList getList(@RequestParam Long accountBookId) { + ResSharingCommentList resSharingCommentList = sharingCommentService.getCommentList(accountBookId); + return resSharingCommentList; + } } diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/ResSharingCommentList.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/ResSharingCommentList.java new file mode 100644 index 0000000..008f2eb --- /dev/null +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/ResSharingCommentList.java @@ -0,0 +1,20 @@ +package com.umc.DongnaeFriend.domain.account.sharing.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment; +import lombok.*; + +import java.util.List; +import java.util.Objects; + +@Getter +public class ResSharingCommentList { + int totalCount; + List commentList; + + @Builder + public ResSharingCommentList(int totalCount, List commentList) { + this.totalCount = totalCount; + this.commentList = commentList; + } +} diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingCommentRepository.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingCommentRepository.java index d815a35..2884fab 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingCommentRepository.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingCommentRepository.java @@ -7,9 +7,15 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import java.util.List; +import java.util.Objects; + public interface SharingCommentRepository extends JpaRepository { @Query("SELECT u FROM User u WHERE u.id = :user_id") User findByUserId(@Param("user_id") Long user_id); @Query("SELECT sb FROM SharingBoard sb WHERE sb.id = :sharing_board_id") SharingBoard findBySharingBoardId(@Param("sharing_board_id") Long sharing_board_id); + + @Query("SELECT sc FROM SharingComment sc WHERE sc.sharingBoard = :sharingBoard") + List findAllByBoard(@Param("sharingBoard") SharingBoard sharingBoard); } diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingCommentService.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingCommentService.java index b4264b7..6c5f6bb 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingCommentService.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingCommentService.java @@ -1,6 +1,7 @@ package com.umc.DongnaeFriend.domain.account.sharing.service; import com.umc.DongnaeFriend.domain.account.sharing.dto.ReqSharingCommentDto; +import com.umc.DongnaeFriend.domain.account.sharing.dto.ResSharingCommentList; import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingBoard; import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment; import com.umc.DongnaeFriend.domain.account.sharing.repository.SharingCommentRepository; @@ -9,6 +10,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.Objects; import java.util.Optional; @RequiredArgsConstructor @@ -81,4 +83,19 @@ public String deleteComment(Long commentId) { return "댓글 삭제 성공"; } + // [가계부 공유] 댓글 목록 조회 + public ResSharingCommentList getCommentList(Long accountBookId) { + // 게시판 가져오기 + SharingBoard sharingBoard = sharingCommentRepository.findBySharingBoardId(accountBookId); + + List commentList = sharingCommentRepository.findAllByBoard(sharingBoard); + + ResSharingCommentList resSharingCommentList = ResSharingCommentList.builder() + .totalCount(commentList.size()) + .commentList(sharingCommentRepository.findAllByBoard(sharingBoard)) + .build(); + + return resSharingCommentList; + } + }