Skip to content

Commit

Permalink
✨ Feat #71 : [가계부 공유] 댓글 목록 조회 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Suanna01 committed Aug 20, 2023
1 parent cccf44e commit 76e69b7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
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.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/account-books/sharing/comments")
Expand Down Expand Up @@ -38,8 +36,7 @@ public String deleteComment(@PathVariable("commentId") Long commentId) {

// [가계부 공유] 댓글 목록 조회
@GetMapping("")
public ResSharingCommentList getList(@RequestParam Long accountBookId) {
ResSharingCommentList resSharingCommentList = sharingCommentService.getCommentList(accountBookId);
return resSharingCommentList;
public ResponseEntity<ReqSharingCommentDto.CommentListResponse> getList(@RequestParam Long accountBookId) {
return ResponseEntity.status(HttpStatus.OK).body(sharingCommentService.getList(accountBookId));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
package com.umc.DongnaeFriend.domain.account.sharing.dto;

import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.stream.Collectors;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class ReqSharingCommentDto {
Long parentCommentId;
String content;

public static ReqSharingCommentDto from(SharingComment sharingComment) {
return new ReqSharingCommentDto(
sharingComment.getContent()
);
}

@Getter
public static class CommentListResponse {
private List<ReqSharingCommentDto> list;

public CommentListResponse(List<ReqSharingCommentDto> list) {
this.list = list;
}

public static CommentListResponse of(List<SharingComment> list) {
List<ReqSharingCommentDto> sharingCommentDtos = list
.stream()
.map(ReqSharingCommentDto::from)
.collect(Collectors.toList());

return new CommentListResponse(sharingCommentDtos);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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 @@ -10,7 +9,6 @@
import org.springframework.stereotype.Service;

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

@RequiredArgsConstructor
Expand All @@ -25,26 +23,26 @@ public String newComment(Long accountBookId, ReqSharingCommentDto reqSharingComm
// 게시판 가져오기
SharingBoard sharingBoard = sharingCommentRepository.findBySharingBoardId(accountBookId);

// 대댓글 등록
if (!(reqSharingCommentDto.getParentCommentId() == null)){
// 부모 댓글 가져오기
Optional<SharingComment> parentCommentOptional = sharingCommentRepository.findById(reqSharingCommentDto.getParentCommentId());
SharingComment parentComment = parentCommentOptional.get();

// 댓글 빌드
SharingComment comment = SharingComment.builder()
.parentComment(parentComment)
.content(reqSharingCommentDto.getContent())
.isDeleted(false)
.sharingBoard(sharingBoard)
.user(user)
.build();

sharingCommentRepository.save(comment);

return "대댓글 등록 성공";

}
// // 대댓글 등록
// if (!(reqSharingCommentDto.getParentCommentId() == null)){
// // 부모 댓글 가져오기
// Optional<SharingComment> parentCommentOptional = sharingCommentRepository.findById(reqSharingCommentDto.getParentCommentId());
// SharingComment parentComment = parentCommentOptional.get();
//
// // 댓글 빌드
// SharingComment comment = SharingComment.builder()
// .parentComment(parentComment)
// .content(reqSharingCommentDto.getContent())
// .isDeleted(false)
// .sharingBoard(sharingBoard)
// .user(user)
// .build();
//
// sharingCommentRepository.save(comment);
//
// return "대댓글 등록 성공";
//
// }

// 댓글 등록
SharingComment comment = SharingComment.builder()
Expand Down Expand Up @@ -84,18 +82,13 @@ public String deleteComment(Long commentId) {
}

// [가계부 공유] 댓글 목록 조회
public ResSharingCommentList getCommentList(Long accountBookId) {
public ReqSharingCommentDto.CommentListResponse getList(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();
List<SharingComment> list = sharingCommentRepository.findAllByBoard(sharingBoard);

return resSharingCommentList;
return ReqSharingCommentDto.CommentListResponse.of(list);
}

}

0 comments on commit 76e69b7

Please sign in to comment.