Skip to content

Commit

Permalink
✨ Feat #18 : [가계부 공유] 댓글 목록 조회 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Suanna01 committed Jul 29, 2023
1 parent 3f2dde8 commit 62dd9a9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<SharingComment> commentList;

@Builder
public ResSharingCommentList(int totalCount, List<SharingComment> commentList) {
this.totalCount = totalCount;
this.commentList = commentList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<SharingComment, Long> {
@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<SharingComment> findAllByBoard(@Param("sharingBoard") SharingBoard sharingBoard);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,6 +10,7 @@
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

@RequiredArgsConstructor
Expand Down Expand Up @@ -81,4 +83,19 @@ public String deleteComment(Long commentId) {
return "댓글 삭제 성공";
}

// [가계부 공유] 댓글 목록 조회
public ResSharingCommentList getCommentList(Long accountBookId) {
// 게시판 가져오기
SharingBoard sharingBoard = sharingCommentRepository.findBySharingBoardId(accountBookId);

List<SharingComment> commentList = sharingCommentRepository.findAllByBoard(sharingBoard);

ResSharingCommentList resSharingCommentList = ResSharingCommentList.builder()
.totalCount(commentList.size())
.commentList(sharingCommentRepository.findAllByBoard(sharingBoard))
.build();

return resSharingCommentList;
}

}

0 comments on commit 62dd9a9

Please sign in to comment.