From 852c302721bdbdf62ffb4dca08196830ab0eace5 Mon Sep 17 00:00:00 2001 From: Suanna01 Date: Wed, 19 Jul 2023 15:41:37 +0900 Subject: [PATCH 1/5] =?UTF-8?q?:sparkles:=20Feat=20#18=20:=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20=EB=93=B1=EB=A1=9D=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SharingCommentController.java | 21 +++++++ .../sharing/dto/ReqSharingCommentDto.java | 13 +++++ .../repository/SharingCommentRepository.java | 15 +++++ .../service/SharingCommentService.java | 58 +++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentController.java create mode 100644 src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/ReqSharingCommentDto.java create mode 100644 src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingCommentRepository.java create mode 100644 src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingCommentService.java 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 new file mode 100644 index 0000000..d3894c4 --- /dev/null +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentController.java @@ -0,0 +1,21 @@ +package com.umc.DongnaeFriend.domain.account.sharing.controller; + +import com.umc.DongnaeFriend.domain.account.sharing.dto.ReqSharingCommentDto; +import com.umc.DongnaeFriend.domain.account.sharing.service.SharingCommentService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/account-books/sharing/comments") +public class SharingCommentController { + private final SharingCommentService sharingCommentService; + + // [가계부 공유] 댓글 등록 + @PostMapping("/{sharing_board_id}") + public String postComment(@PathVariable("sharing_board_id") Long sharing_board_id, @RequestBody ReqSharingCommentDto reqSharingCommentDto) { + sharingCommentService.newComment(sharing_board_id, reqSharingCommentDto); + return ""; + } + +} diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/ReqSharingCommentDto.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/ReqSharingCommentDto.java new file mode 100644 index 0000000..e8a22b3 --- /dev/null +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/ReqSharingCommentDto.java @@ -0,0 +1,13 @@ +package com.umc.DongnaeFriend.domain.account.sharing.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class ReqSharingCommentDto { + Long parentCommentId; + String content; +} 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 new file mode 100644 index 0000000..d815a35 --- /dev/null +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingCommentRepository.java @@ -0,0 +1,15 @@ +package com.umc.DongnaeFriend.domain.account.sharing.repository; + +import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingBoard; +import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment; +import com.umc.DongnaeFriend.domain.user.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +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); +} 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 new file mode 100644 index 0000000..33c3db4 --- /dev/null +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingCommentService.java @@ -0,0 +1,58 @@ +package com.umc.DongnaeFriend.domain.account.sharing.service; + +import com.umc.DongnaeFriend.domain.account.sharing.dto.ReqSharingCommentDto; +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; +import com.umc.DongnaeFriend.domain.user.entity.User; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.Optional; + +@RequiredArgsConstructor +@Service +public class SharingCommentService { + private final SharingCommentRepository sharingCommentRepository; + + public String newComment(Long sharing_board_id, ReqSharingCommentDto reqSharingCommentDto) { + // !임시! 유저 가져오기 + User user = sharingCommentRepository.findByUserId(1L); + + // 게시판 가져오기 + SharingBoard sharingBoard = sharingCommentRepository.findBySharingBoardId(sharing_board_id); + + // 대댓글 등록 + if (!(reqSharingCommentDto.getParentCommentId() == null)){ + // 부모 댓글 가져오기 + Optional 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() + .content(reqSharingCommentDto.getContent()) + .isDeleted(false) + .sharingBoard(sharingBoard) + .user(user) + .build(); + + sharingCommentRepository.save(comment); + + return "댓글 등록 성공"; + } +} From bb263f1a85512e3054e83bf48f3e3d322703623e Mon Sep 17 00:00:00 2001 From: sungone <20200999@sungshin.ac.kr> Date: Sun, 23 Jul 2023 22:31:35 +0900 Subject: [PATCH 2/5] =?UTF-8?q?:sparkles:=20Feat=20#18=20:=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20=EC=88=98=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SharingCommentController.java | 12 +++++++++--- .../account/sharing/entity/SharingComment.java | 5 +++++ .../sharing/service/SharingCommentService.java | 16 ++++++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) 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 d3894c4..1640e17 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 @@ -12,10 +12,16 @@ public class SharingCommentController { private final SharingCommentService sharingCommentService; // [가계부 공유] 댓글 등록 - @PostMapping("/{sharing_board_id}") - public String postComment(@PathVariable("sharing_board_id") Long sharing_board_id, @RequestBody ReqSharingCommentDto reqSharingCommentDto) { - sharingCommentService.newComment(sharing_board_id, reqSharingCommentDto); + @PostMapping("/{accountBookId}") + public String postComment(@PathVariable("accountBookId") Long accountBookId, @RequestBody ReqSharingCommentDto reqSharingCommentDto) { + sharingCommentService.newComment(accountBookId, reqSharingCommentDto); return ""; } + // [가계부 공유] 댓글 수정 + @PutMapping("/{comment_id}") + public String putComment(@PathVariable("comment_id") Long comment_id, @RequestBody ReqSharingCommentDto reqSharingCommentDto) { + sharingCommentService.modifyComment(comment_id, reqSharingCommentDto); + return ""; + } } diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/entity/SharingComment.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/entity/SharingComment.java index 4b56978..099fa81 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/entity/SharingComment.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/entity/SharingComment.java @@ -6,6 +6,7 @@ import static lombok.AccessLevel.PROTECTED; import com.umc.DongnaeFriend.domain.BaseTimeEntity; +import com.umc.DongnaeFriend.domain.account.sharing.dto.ReqSharingCommentDto; import com.umc.DongnaeFriend.domain.user.entity.User; import java.util.List; import javax.persistence.*; @@ -43,4 +44,8 @@ public class SharingComment extends BaseTimeEntity { @Column(nullable = false) private String content; + + public void modifyComment(ReqSharingCommentDto reqSharingCommentDto) { + this.content = reqSharingCommentDto.getContent(); + } } 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 33c3db4..cb444b2 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 @@ -15,12 +15,12 @@ public class SharingCommentService { private final SharingCommentRepository sharingCommentRepository; - public String newComment(Long sharing_board_id, ReqSharingCommentDto reqSharingCommentDto) { + public String newComment(Long accountBookId, ReqSharingCommentDto reqSharingCommentDto) { // !임시! 유저 가져오기 User user = sharingCommentRepository.findByUserId(1L); // 게시판 가져오기 - SharingBoard sharingBoard = sharingCommentRepository.findBySharingBoardId(sharing_board_id); + SharingBoard sharingBoard = sharingCommentRepository.findBySharingBoardId(accountBookId); // 대댓글 등록 if (!(reqSharingCommentDto.getParentCommentId() == null)){ @@ -55,4 +55,16 @@ public String newComment(Long sharing_board_id, ReqSharingCommentDto reqSharingC return "댓글 등록 성공"; } + + public String modifyComment(Long comment_id, ReqSharingCommentDto reqSharingCommentDto) { + // 댓글 찾기 + Optional sharingCommentOptional = sharingCommentRepository.findById(comment_id); + SharingComment sharingComment = sharingCommentOptional.get(); + + sharingComment.modifyComment(reqSharingCommentDto); + + sharingCommentRepository.save(sharingComment); + + return "댓글 수정 성공"; + } } From d5468273582f762b43f8a901f5f19b3cacbfdaeb Mon Sep 17 00:00:00 2001 From: sungone <20200999@sungshin.ac.kr> Date: Sun, 23 Jul 2023 22:41:45 +0900 Subject: [PATCH 3/5] =?UTF-8?q?:sparkles:=20Feat=20#18=20:=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SharingCommentController.java | 13 ++++++++++--- .../sharing/service/SharingCommentService.java | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) 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 1640e17..73ce9d3 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 @@ -19,9 +19,16 @@ public String postComment(@PathVariable("accountBookId") Long accountBookId, @R } // [가계부 공유] 댓글 수정 - @PutMapping("/{comment_id}") - public String putComment(@PathVariable("comment_id") Long comment_id, @RequestBody ReqSharingCommentDto reqSharingCommentDto) { - sharingCommentService.modifyComment(comment_id, reqSharingCommentDto); + @PutMapping("/{commentId}") + public String putComment(@PathVariable("commentId") Long commentId, @RequestBody ReqSharingCommentDto reqSharingCommentDto) { + sharingCommentService.modifyComment(commentId, reqSharingCommentDto); + return ""; + } + + // [가게부 공유] 댓글 삭제 + @DeleteMapping("/{commentId}") + public String deleteComment(@PathVariable("commentId") Long commentId) { + sharingCommentService.deleteComment(commentId); return ""; } } 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 cb444b2..cd1eb64 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 @@ -56,9 +56,10 @@ public String newComment(Long accountBookId, ReqSharingCommentDto reqSharingComm return "댓글 등록 성공"; } - public String modifyComment(Long comment_id, ReqSharingCommentDto reqSharingCommentDto) { + // [가계부 공유] 댓글 수정 + public String modifyComment(Long commentId, ReqSharingCommentDto reqSharingCommentDto) { // 댓글 찾기 - Optional sharingCommentOptional = sharingCommentRepository.findById(comment_id); + Optional sharingCommentOptional = sharingCommentRepository.findById(commentId); SharingComment sharingComment = sharingCommentOptional.get(); sharingComment.modifyComment(reqSharingCommentDto); @@ -67,4 +68,15 @@ public String modifyComment(Long comment_id, ReqSharingCommentDto reqSharingComm return "댓글 수정 성공"; } + + // [가게부 공유] 댓글 삭제 + public String deleteComment(Long commentId) { + // 댓글 찾기 + Optional sharingCommentOptional = sharingCommentRepository.findById(commentId); + SharingComment sharingComment = sharingCommentOptional.get(); + + sharingCommentRepository.delete(sharingComment); + + return "댓글 삭제 성공"; + } } From 3f2dde877c9c6cdb31a2d6ad5c61a98e331233bf Mon Sep 17 00:00:00 2001 From: sungone <20200999@sungshin.ac.kr> Date: Sun, 30 Jul 2023 01:04:30 +0900 Subject: [PATCH 4/5] =?UTF-8?q?:sparkles:=20Feat=20#18=20:=20[=EA=B0=80?= =?UTF-8?q?=EA=B3=84=EB=B6=80=20=EA=B3=B5=EC=9C=A0]=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20=EC=A2=8B=EC=95=84=EC=9A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SharingCommentController.java | 3 +- .../SharingCommentLikeController.java | 20 ++++++++++++ .../SharingCommentLikeRepository.java | 16 ++++++++++ .../service/SharingCommentLikeService.java | 31 +++++++++++++++++++ .../service/SharingCommentService.java | 4 ++- 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentLikeController.java create mode 100644 src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingCommentLikeRepository.java create mode 100644 src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingCommentLikeService.java 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 73ce9d3..6aa2c0b 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 @@ -25,10 +25,11 @@ public String putComment(@PathVariable("commentId") Long commentId, @RequestBod return ""; } - // [가게부 공유] 댓글 삭제 + // [가계부 공유] 댓글 삭제 @DeleteMapping("/{commentId}") public String deleteComment(@PathVariable("commentId") Long commentId) { sharingCommentService.deleteComment(commentId); return ""; } + } diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentLikeController.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentLikeController.java new file mode 100644 index 0000000..3cd7b64 --- /dev/null +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentLikeController.java @@ -0,0 +1,20 @@ +package com.umc.DongnaeFriend.domain.account.sharing.controller; + +import com.umc.DongnaeFriend.domain.account.sharing.dto.ReqSharingCommentDto; +import com.umc.DongnaeFriend.domain.account.sharing.service.SharingCommentLikeService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/account-books/sharing/likes") +public class SharingCommentLikeController { + private final SharingCommentLikeService sharingCommentLikeService; + + // [가계부 공유] 댓글 좋아요 + @PostMapping("/{commentId}") + public String postCommentLike(@PathVariable("commentId") Long commentId) { + sharingCommentLikeService.newLike(commentId); + return ""; + } +} diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingCommentLikeRepository.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingCommentLikeRepository.java new file mode 100644 index 0000000..c6fabf2 --- /dev/null +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingCommentLikeRepository.java @@ -0,0 +1,16 @@ +package com.umc.DongnaeFriend.domain.account.sharing.repository; + +import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment; +import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingCommentLike; +import com.umc.DongnaeFriend.domain.user.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface SharingCommentLikeRepository extends JpaRepository { + @Query("SELECT u FROM User u WHERE u.id = :user_id") + User findByUserId(@Param("user_id") Long user_id); + + @Query("SELECT sc FROM SharingComment sc WHERE sc.id = :sharing_comment_id") + SharingComment findByCommentId(@Param("sharing_comment_id") Long sharing_comment_id); +} diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingCommentLikeService.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingCommentLikeService.java new file mode 100644 index 0000000..62ceae1 --- /dev/null +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingCommentLikeService.java @@ -0,0 +1,31 @@ +package com.umc.DongnaeFriend.domain.account.sharing.service; + +import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment; +import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingCommentLike; +import com.umc.DongnaeFriend.domain.account.sharing.repository.SharingCommentLikeRepository; +import com.umc.DongnaeFriend.domain.user.entity.User; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class SharingCommentLikeService { + private final SharingCommentLikeRepository sharingCommentLikeRepository; + + public String newLike(Long commentId) { + // !임시! 유저 가져오기 + User user = sharingCommentLikeRepository.findByUserId(1L); + + // 댓글 가져오기 + SharingComment sharingComment = sharingCommentLikeRepository.findByCommentId(commentId); + + SharingCommentLike sharingCommentLike = SharingCommentLike.builder() + .user(user) + .sharingComment(sharingComment) + .build(); + + sharingCommentLikeRepository.save(sharingCommentLike); + + return "가계부 공유 댓글 좋아요 성공"; + } +} 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 cd1eb64..b4264b7 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 @@ -8,6 +8,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.List; import java.util.Optional; @RequiredArgsConstructor @@ -69,7 +70,7 @@ public String modifyComment(Long commentId, ReqSharingCommentDto reqSharingComme return "댓글 수정 성공"; } - // [가게부 공유] 댓글 삭제 + // [가계부 공유] 댓글 삭제 public String deleteComment(Long commentId) { // 댓글 찾기 Optional sharingCommentOptional = sharingCommentRepository.findById(commentId); @@ -79,4 +80,5 @@ public String deleteComment(Long commentId) { return "댓글 삭제 성공"; } + } From 62dd9a9ec8126b734a1163ba28102742d93d631c Mon Sep 17 00:00:00 2001 From: sungone <20200999@sungshin.ac.kr> Date: Sun, 30 Jul 2023 02:35:46 +0900 Subject: [PATCH 5/5] =?UTF-8?q?:sparkles:=20Feat=20#18=20:=20[=EA=B0=80?= =?UTF-8?q?=EA=B3=84=EB=B6=80=20=EA=B3=B5=EC=9C=A0]=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SharingCommentController.java | 10 ++++++++++ .../sharing/dto/ResSharingCommentList.java | 20 +++++++++++++++++++ .../repository/SharingCommentRepository.java | 6 ++++++ .../service/SharingCommentService.java | 17 ++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/ResSharingCommentList.java 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; + } + }