From 82a6c74c2615d7aef8a9d85ed87a211e58b67111 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 11:51:59 +0900 Subject: [PATCH 01/20] =?UTF-8?q?[feat]=20CommentRepository=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=95=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/repository/CommentRepository.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepository.java index e197d82a..c24f8c53 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepository.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepository.java @@ -1,8 +1,8 @@ package com.bbteam.budgetbuddies.domain.comment.repository; import com.bbteam.budgetbuddies.domain.comment.entity.Comment; -import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; -import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -11,10 +11,20 @@ public interface CommentRepository extends JpaRepository { @Query("select c from Comment c where c.discountInfo.id = :discountInfoId" + - " order by c.createdAt asc") + " order by c.createdAt asc") // 익명번호 부여용 List findByDiscountInfo(@Param("discountInfoId")Long discountInfoId); + @Query("select c from Comment c where c.discountInfo.id = :discountInfoId" + + " order by c.createdAt asc") + Page findByDiscountInfoWithPaging(@Param("discountInfoId")Long discountInfoId, + Pageable pageable); + @Query("select c from Comment c where c.supportInfo.id = :supportInfoId" + " order by c.createdAt asc") List findBySupportInfo(@Param("supportInfoId")Long supportInfoId); + + @Query("select c from Comment c where c.supportInfo.id = :supportInfoId" + + " order by c.createdAt asc") + Page findBySupportInfoWithPaging(@Param("supportInfoId")Long supportInfoId, + Pageable pageable); } From 655a9b771f2b30c0b9905ff44a16085d536da02a Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 11:52:29 +0900 Subject: [PATCH 02/20] =?UTF-8?q?[feat]=20=EC=9D=B5=EB=AA=85=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EA=B4=80=EB=A6=AC=EB=A5=BC=20=EC=9C=84=ED=95=B4=20?= =?UTF-8?q?anonymousNumber=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bbteam/budgetbuddies/domain/comment/entity/Comment.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java index 9ce02ba7..634c6a0d 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java @@ -17,7 +17,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @SuperBuilder -public class Comment extends BaseEntity { +public abstract class Comment extends BaseEntity { @Column(nullable = false, length = 1000) private String content; @@ -34,4 +34,6 @@ public class Comment extends BaseEntity { @JoinColumn(name = "support_info_id") private SupportInfo supportInfo; + private Integer anonymousNumber; + } From 052ebed0b90a67f40a4480f05acd7300f8ccd51b Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 12:06:55 +0900 Subject: [PATCH 03/20] =?UTF-8?q?[fix]=20Comment=20abstract=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/bbteam/budgetbuddies/domain/comment/entity/Comment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java index 634c6a0d..9b3cc376 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java @@ -17,7 +17,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @SuperBuilder -public abstract class Comment extends BaseEntity { +public class Comment extends BaseEntity { @Column(nullable = false, length = 1000) private String content; From 247a21bb10046e3d04bd4a89a47aeb5972c6bd87 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 12:09:36 +0900 Subject: [PATCH 04/20] =?UTF-8?q?[feat]=20CommentService=20paging=20method?= =?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 --- .../comment/service/CommentService.java | 6 ++++ .../comment/service/CommentServiceImpl.java | 28 +++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentService.java index fdbb743f..40615f6a 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentService.java @@ -2,6 +2,8 @@ import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import java.util.List; @@ -26,6 +28,10 @@ public interface CommentService { */ List findBySupportInfo(Long supportInfoId); + Page findByDiscountInfoWithPaging(Long discountInfoId, Pageable pageable); + Page findBySupportInfoWithPaging(Long supportInfoId, Pageable pageable); + + diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java index 4b394081..7020abd1 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java @@ -13,6 +13,8 @@ import com.bbteam.budgetbuddies.domain.user.entity.User; import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -64,7 +66,7 @@ public List findByDiscountInfo(Long d HashMap anonymousMapping = countAnonymousNumber(commentList); List collect = commentList.stream() - .map(comment -> CommentConverter.toDiscountInfoCommentDto(comment, anonymousMapping)) + .map(CommentConverter::toDiscountInfoCommentDto) .collect(Collectors.toList()); return collect; @@ -75,7 +77,7 @@ public List findBySupportInfo(Long sup List commentList = commentRepository.findBySupportInfo(supportInfoId); HashMap anonymousMapping = countAnonymousNumber(commentList); List collect = commentList.stream() - .map(comment -> CommentConverter.toSupportInfoCommentDto(comment, anonymousMapping)) + .map(CommentConverter::toSupportInfoCommentDto) .collect(Collectors.toList()); return collect; } @@ -93,19 +95,17 @@ private static HashMap countAnonymousNumber(List commentLis return anonymousMapping; } - @Transactional - public void removeDiscountInfoComment(Long discountInfoId){ - DiscountInfo discountInfo = discountInfoRepository.findById(discountInfoId).orElseThrow(() -> new NoSuchElementException("No such Entity")); - discountInfoRepository.delete(discountInfo); - return; + @Override + public Page findByDiscountInfoWithPaging(Long discountInfoId, Pageable pageable) { + Page commentPage = commentRepository.findByDiscountInfoWithPaging(discountInfoId, pageable); + Page result = commentPage.map(CommentConverter::toDiscountInfoCommentDto); + return result; } - @Transactional - public void removeSupportInfoComment(Long supportInfoId){ - SupportInfo supportInfo = supportInfoRepository.findById(supportInfoId).orElseThrow(() -> new NoSuchElementException("No such Entity")); - supportInfoRepository.delete(supportInfo); - return; + @Override + public Page findBySupportInfoWithPaging(Long supportInfoId, Pageable pageable) { + Page commentPage = commentRepository.findBySupportInfoWithPaging(supportInfoId, pageable); + Page result = commentPage.map(CommentConverter::toSupportInfoCommentDto); + return result; } - - } From 1b50bf545ec3540b6a61c83f64400f38c8921630 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 12:12:02 +0900 Subject: [PATCH 05/20] =?UTF-8?q?[feat]=20CommentService=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20=EC=82=AD=EC=A0=9C=20=EB=A1=9C=EC=A7=81=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 --- .../domain/comment/service/CommentService.java | 2 ++ .../domain/comment/service/CommentServiceImpl.java | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentService.java index 40615f6a..ac49bc5a 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentService.java @@ -31,6 +31,8 @@ public interface CommentService { Page findByDiscountInfoWithPaging(Long discountInfoId, Pageable pageable); Page findBySupportInfoWithPaging(Long supportInfoId, Pageable pageable); + void deleteComment(Long commentId); + diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java index 7020abd1..bc995b41 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java @@ -108,4 +108,10 @@ public Page findBySupportInfoWithPagin Page result = commentPage.map(CommentConverter::toSupportInfoCommentDto); return result; } + + @Override + public void deleteComment(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); + commentRepository.delete(comment); + } } From fa4c855b3144ce7e95fe2396a2c1a2e445aefb59 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 12:49:15 +0900 Subject: [PATCH 06/20] =?UTF-8?q?[feat]=20anonymous=20field=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4=20=EB=A7=A4=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/discountinfo/entity/DiscountInfo.java | 5 +++++ .../budgetbuddies/domain/supportinfo/entity/SupportInfo.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/entity/DiscountInfo.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/entity/DiscountInfo.java index 5caf45b3..072b2ac4 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/entity/DiscountInfo.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/entity/DiscountInfo.java @@ -42,4 +42,9 @@ public void subLikeCount() { this.likeCount--; } + public Integer addAndGetAnonymousNumber() { + this.anonymousNumber++; + return anonymousNumber; + } + } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/entity/SupportInfo.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/entity/SupportInfo.java index aaa651e0..cc83973e 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/entity/SupportInfo.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/entity/SupportInfo.java @@ -43,4 +43,9 @@ public void subLikeCount() { this.likeCount--; } + public Integer addAndGetAnonymousNumber() { + this.anonymousNumber++; + return anonymousNumber; + } + } From d1cb8708575c2669db73a60d292516cf83fb979a Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 12:51:24 +0900 Subject: [PATCH 07/20] =?UTF-8?q?[refactor]=20save=EA=B3=BC=EC=A0=95?= =?UTF-8?q?=EC=97=90=EC=84=9C=20anonymous=20number=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=EB=90=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/service/CommentServiceImpl.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java index bc995b41..b2490b33 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.List; import java.util.NoSuchElementException; +import java.util.Optional; import java.util.stream.Collectors; // 임시로 유저는 service에서 찾아서 처리하는 로직으로 작성함 @@ -39,13 +40,23 @@ public class CommentServiceImpl implements CommentService{ public CommentResponseDto.SupportInfoSuccessDto saveSupportComment(Long userId, CommentRequestDto.SupportInfoCommentDto dto) { User user = userRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("유저 존재 x")); SupportInfo supportInfo = supportInfoRepository.findById(dto.getSupportInfoId()).orElseThrow(() -> new NoSuchElementException()); - - Comment comment = CommentConverter.toSupportComment(dto, user, supportInfo); + int anonymousNumber = getSupportAnonymousNumber(user, supportInfo); + Comment comment = CommentConverter.toSupportComment(dto, user, supportInfo, anonymousNumber); Comment savedComment = commentRepository.save(comment); return CommentConverter.toSupportInfoSuccessDto(savedComment); } + private int getSupportAnonymousNumber(User user, SupportInfo supportInfo) { + int anonymousNumber; + Optional foundComment = commentRepository.findTopByUserAndSupportInfo(user, supportInfo); + if(foundComment.isEmpty()){ + anonymousNumber = supportInfo.addAndGetAnonymousNumber(); + } else { + anonymousNumber = foundComment.get().getAnonymousNumber(); + } + return anonymousNumber; + } @Override @@ -53,13 +64,24 @@ public CommentResponseDto.SupportInfoSuccessDto saveSupportComment(Long userId, public CommentResponseDto.DiscountInfoSuccessDto saveDiscountComment(Long userId, CommentRequestDto.DiscountInfoCommentDto dto) { User user = userRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("유저 존재 x")); DiscountInfo discountInfo = discountInfoRepository.findById(dto.getDiscountInfoId()).orElseThrow(() -> new NoSuchElementException()); - - Comment comment = CommentConverter.toDiscountComment(dto, user, discountInfo); + int anonymousNumber = getDiscountAnonymousNumber(user, discountInfo); + Comment comment = CommentConverter.toDiscountComment(dto, user, discountInfo, anonymousNumber); Comment savedComment = commentRepository.save(comment); return CommentConverter.toDiscountInfoSuccessDto(savedComment); } + private int getDiscountAnonymousNumber(User user, DiscountInfo discountInfo) { + int anonymousNumber; + Optional foundComment = commentRepository.findTopByUserAndDiscountInfo(user, discountInfo); + if(foundComment.isEmpty()){ + anonymousNumber = discountInfo.addAndGetAnonymousNumber(); + } else { + anonymousNumber = foundComment.get().getAnonymousNumber(); + } + return anonymousNumber; + } + @Override public List findByDiscountInfo(Long discountInfoId) { List commentList = commentRepository.findByDiscountInfo(discountInfoId); From 90525d8198ae5d93493a9d36d955c34f1ea63df1 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 13:28:10 +0900 Subject: [PATCH 08/20] =?UTF-8?q?[refactor]=20CommentConverter=20anonymous?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/converter/CommentConverter.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/converter/CommentConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/converter/CommentConverter.java index a589bacf..0a2395bf 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/converter/CommentConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/converter/CommentConverter.java @@ -7,44 +7,44 @@ import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; import com.bbteam.budgetbuddies.domain.user.entity.User; -import java.util.HashMap; - public class CommentConverter { - public static Comment toDiscountComment(CommentRequestDto.DiscountInfoCommentDto dto, User user, DiscountInfo discountInfo) { + public static Comment toDiscountComment(CommentRequestDto.DiscountInfoCommentDto dto, User user, DiscountInfo discountInfo, + Integer anonymousNumber) { return Comment.builder() .user(user) .discountInfo(discountInfo) .content(dto.getContent()) + .anonymousNumber(anonymousNumber) .build(); } - public static Comment toSupportComment(CommentRequestDto.SupportInfoCommentDto dto, User user, SupportInfo supportInfo) { + public static Comment toSupportComment(CommentRequestDto.SupportInfoCommentDto dto, User user, SupportInfo supportInfo, + Integer anonymousNumber) { return Comment.builder() .user(user) .supportInfo(supportInfo) .content(dto.getContent()) + .anonymousNumber(anonymousNumber) .build(); } - public static CommentResponseDto.DiscountInfoCommentDto toDiscountInfoCommentDto(Comment comment, - HashMap anonymousMapping){ + public static CommentResponseDto.DiscountInfoCommentDto toDiscountInfoCommentDto(Comment comment){ return CommentResponseDto.DiscountInfoCommentDto.builder() .discountInfoId(comment.getDiscountInfo().getId()) .userId(comment.getUser().getId()) .content(comment.getContent()) - .anonymousNumber(anonymousMapping.get(comment.getUser().getId())) + .anonymousNumber(comment.getAnonymousNumber()) .build(); } - public static CommentResponseDto.SupportInfoCommentDto toSupportInfoCommentDto(Comment comment, - HashMap anonymousMapping){ + public static CommentResponseDto.SupportInfoCommentDto toSupportInfoCommentDto(Comment comment){ return CommentResponseDto.SupportInfoCommentDto.builder() .supportInfoId(comment.getSupportInfo().getId()) .userId(comment.getUser().getId()) .content(comment.getContent()) - .anonymousNumber(anonymousMapping.get(comment.getUser().getId())) + .anonymousNumber(comment.getAnonymousNumber()) .build(); } From 2f12a50ba4a8dbd009efd68fb06a00d395af7127 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 13:29:40 +0900 Subject: [PATCH 09/20] =?UTF-8?q?[refactor]=20anonymousNumber=20type=20Lon?= =?UTF-8?q?g=20->=20Integer=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../budgetbuddies/domain/comment/dto/CommentResponseDto.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java index 8cd110ba..70e0df40 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java @@ -12,7 +12,7 @@ public static class DiscountInfoCommentDto{ private Long userId; private Long discountInfoId; private String content; - private Long anonymousNumber; + private Integer anonymousNumber; } @Getter @@ -21,7 +21,7 @@ public static class SupportInfoCommentDto{ private Long userId; private Long supportInfoId; private String content; - private Long anonymousNumber; + private Integer anonymousNumber; } @Getter From 8302317c77fc63c2f748f89548c31f5336998c18 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 13:29:51 +0900 Subject: [PATCH 10/20] =?UTF-8?q?[test]=20=ED=8E=98=EC=9D=B4=EC=A7=95=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/service/CommentServiceTest.java | 236 ++++++++++++++++-- 1 file changed, 217 insertions(+), 19 deletions(-) diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTest.java index c3ade564..47636c82 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTest.java @@ -13,11 +13,13 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.transaction.annotation.Transactional; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; /** * comment service는 다음과 같은 기능을 제공해야한다. @@ -31,6 +33,10 @@ * 4. 특정 게시글 id로 댓글 찾는 기능 */ + +/* + 테스트마다 테스트케이스가 다를 수 있어서 공통로직으로 처리하지 않아 매우 깁니다... + */ @SpringBootTest @Transactional class CommentServiceTest { @@ -56,7 +62,9 @@ public void saveDiscountInfoCommentTest(){ .build(); userRepository.save(user1); - DiscountInfo sale1 = DiscountInfo.builder().title("무신사 할인").build(); + DiscountInfo sale1 = DiscountInfo.builder().title("무신사 할인") + .anonymousNumber(0) + .build(); discountInfoRepository.save(sale1); CommentRequestDto.DiscountInfoCommentDto dto1 = CommentRequestDto.DiscountInfoCommentDto.builder() @@ -94,9 +102,13 @@ public void saveDiscountInfoCommentTest2(){ .build(); userRepository.save(user2); - DiscountInfo sale1 = DiscountInfo.builder().title("무신사 할인").build(); + DiscountInfo sale1 = DiscountInfo.builder().title("무신사 할인") + .anonymousNumber(0) + .build(); discountInfoRepository.save(sale1); - DiscountInfo sale2 = DiscountInfo.builder().title("핫트랙스 할인").build(); + DiscountInfo sale2 = DiscountInfo.builder().title("핫트랙스 할인") + .anonymousNumber(0) + .build(); discountInfoRepository.save(sale2); @@ -163,9 +175,9 @@ void DiscountAnonymousCommentTest(){ userRepository.save(user2); userRepository.save(user3); - DiscountInfo sale1 = DiscountInfo.builder().title("무신사 할인").build(); + DiscountInfo sale1 = DiscountInfo.builder().anonymousNumber(0).title("무신사 할인").build(); discountInfoRepository.save(sale1); - DiscountInfo sale2 = DiscountInfo.builder().title("핫트랙스 할인").build(); + DiscountInfo sale2 = DiscountInfo.builder().anonymousNumber(0).title("핫트랙스 할인").build(); discountInfoRepository.save(sale2); @@ -197,10 +209,10 @@ void DiscountAnonymousCommentTest(){ em.flush(); List result = commentService.findByDiscountInfo(sale1.getId()); - Long test1 = result.get(0).getAnonymousNumber(); - Long test2 = result.get(1).getAnonymousNumber(); - Long test3 = result.get(2).getAnonymousNumber(); - Long test4 = result.get(3).getAnonymousNumber(); + Integer test1 = result.get(0).getAnonymousNumber(); + Integer test2 = result.get(1).getAnonymousNumber(); + Integer test3 = result.get(2).getAnonymousNumber(); + Integer test4 = result.get(3).getAnonymousNumber(); Assertions.assertThat(test1).isEqualTo(1); Assertions.assertThat(test2).isEqualTo(2); @@ -228,9 +240,9 @@ public void saveSupportInfoCommentTest2(){ .build(); userRepository.save(user2); - SupportInfo info1 = SupportInfo.builder().title("국가장학금 신청").build(); + SupportInfo info1 = SupportInfo.builder().anonymousNumber(0).title("국가장학금 신청").build(); supportInfoRepository.save(info1); - SupportInfo info2 = SupportInfo.builder().title("봉사활동").build(); + SupportInfo info2 = SupportInfo.builder().anonymousNumber(0).title("봉사활동").build(); supportInfoRepository.save(info2); @@ -303,9 +315,9 @@ void supportAnonymousCommentTest(){ userRepository.save(user3); userRepository.save(user4); - SupportInfo info1 = SupportInfo.builder().title("국가장학금 신청").build(); + SupportInfo info1 = SupportInfo.builder().anonymousNumber(0).title("국가장학금 신청").build(); supportInfoRepository.save(info1); - SupportInfo info2 = SupportInfo.builder().title("봉사활동").build(); + SupportInfo info2 = SupportInfo.builder().anonymousNumber(0).title("봉사활동").build(); supportInfoRepository.save(info2); @@ -347,11 +359,11 @@ void supportAnonymousCommentTest(){ List returnDto = commentService.findBySupportInfo(info1.getId()); List returnDto2 = commentService.findBySupportInfo(info2.getId()); - Long test1 = returnDto.get(0).getAnonymousNumber(); - Long test2 = returnDto.get(1).getAnonymousNumber(); - Long test3 = returnDto.get(2).getAnonymousNumber(); - Long test4 = returnDto.get(3).getAnonymousNumber(); - Long test5 = returnDto.get(4).getAnonymousNumber(); + Integer test1 = returnDto.get(0).getAnonymousNumber(); + Integer test2 = returnDto.get(1).getAnonymousNumber(); + Integer test3 = returnDto.get(2).getAnonymousNumber(); + Integer test4 = returnDto.get(3).getAnonymousNumber(); + Integer test5 = returnDto.get(4).getAnonymousNumber(); Assertions.assertThat(test1).isEqualTo(1); Assertions.assertThat(test2).isEqualTo(2); @@ -360,6 +372,192 @@ void supportAnonymousCommentTest(){ Assertions.assertThat(test5).isEqualTo(1); } + @Test + void DiscountInfoCommentPagingTest() { + User user1 = User.builder() + .name("tester1") + .email("1234") + .age(5) + .phoneNumber("123456") + .build(); + userRepository.save(user1); + + User user2 = User.builder() + .name("tester2") + .email("12345") + .age(7) + .phoneNumber("1234567") + .build(); + + User user3 = User.builder() + .name("tester3") + .email("1234553") + .age(9) + .phoneNumber("1232134567") + .build(); + userRepository.save(user2); + userRepository.save(user3); + + DiscountInfo sale1 = DiscountInfo.builder().anonymousNumber(0).title("무신사 할인").build(); + discountInfoRepository.save(sale1); + DiscountInfo sale2 = DiscountInfo.builder().anonymousNumber(0).title("핫트랙스 할인").build(); + discountInfoRepository.save(sale2); + + + CommentRequestDto.DiscountInfoCommentDto dto1 = CommentRequestDto.DiscountInfoCommentDto.builder() + .discountInfoId(sale1.getId()) + .content("굿") + .build(); + + CommentRequestDto.DiscountInfoCommentDto dto2 = CommentRequestDto.DiscountInfoCommentDto.builder() + .discountInfoId(sale1.getId()) + .content("좋아요") + .build(); + CommentRequestDto.DiscountInfoCommentDto dto3 = CommentRequestDto.DiscountInfoCommentDto.builder() + .discountInfoId(sale2.getId()) + .content("유용해요!") + .build(); + CommentRequestDto.DiscountInfoCommentDto dto4 = CommentRequestDto.DiscountInfoCommentDto.builder() + .discountInfoId(sale1.getId()) + .content("구웃!") + .build(); + + commentService.saveDiscountComment(user1.getId(), dto1); + commentService.saveDiscountComment(user2.getId(), dto2); + commentService.saveDiscountComment(user1.getId(), dto3); + + commentService.saveDiscountComment(user1.getId(), dto4); + commentService.saveDiscountComment(user3.getId(), dto4); + commentService.saveDiscountComment(user2.getId(), dto4); + //sale1 = 5 + em.flush(); + + PageRequest pageRequest1 = PageRequest.of(0, 2); + + Page result1 = commentService.findByDiscountInfoWithPaging(sale1.getId(), pageRequest1); + Assertions.assertThat(result1.getTotalElements()).isEqualTo(5); + Assertions.assertThat(result1.getTotalPages()).isEqualTo(3); + Assertions.assertThat(result1.hasNext()).isTrue(); + Assertions.assertThat(result1.hasPrevious()).isFalse(); + List list1 = result1.getContent(); + Assertions.assertThat(list1.get(0).getUserId()).isEqualTo(user1.getId()); + Assertions.assertThat(list1.get(0).getContent()).isEqualTo("굿"); + Assertions.assertThat(list1.get(0).getAnonymousNumber()).isEqualTo(1); + + PageRequest pageRequest2 = PageRequest.of(1, 3); + + Page result2 = commentService.findByDiscountInfoWithPaging(sale1.getId(), pageRequest2); + Assertions.assertThat(result2.getTotalElements()).isEqualTo(5); + Assertions.assertThat(result2.getTotalPages()).isEqualTo(2); + Assertions.assertThat(result2.hasNext()).isFalse(); + Assertions.assertThat(result2.hasPrevious()).isTrue(); + List list2 = result2.getContent(); + Assertions.assertThat(list2.get(0).getUserId()).isEqualTo(user3.getId()); + Assertions.assertThat(list2.get(0).getContent()).isEqualTo("구웃!"); + Assertions.assertThat(list2.get(0).getAnonymousNumber()).isEqualTo(3); + + + } + + @Test + void SupportInfoPagingTest() { + User user1 = User.builder() + .name("tester1") + .email("1234") + .age(5) + .phoneNumber("123456") + .build(); + userRepository.save(user1); + + User user2 = User.builder() + .name("tester2") + .email("12345") + .age(7) + .phoneNumber("1234567") + .build(); + User user3 = User.builder() + .name("tester432") + .email("123423445") + .age(7) + .phoneNumber("1423234567") + .build(); + User user4 = User.builder() + .name("test43er2") + .email("1232445") + .age(7) + .phoneNumber("123454267") + .build(); + userRepository.save(user2); + userRepository.save(user3); + userRepository.save(user4); + + SupportInfo info1 = SupportInfo.builder().anonymousNumber(0).title("국가장학금 신청").build(); + supportInfoRepository.save(info1); + SupportInfo info2 = SupportInfo.builder().anonymousNumber(0).title("봉사활동").build(); + supportInfoRepository.save(info2); + + + CommentRequestDto.SupportInfoCommentDto dto1 = CommentRequestDto.SupportInfoCommentDto.builder() + .supportInfoId(info1.getId()) + .content("굿") + .build(); + + CommentRequestDto.SupportInfoCommentDto dto2 = CommentRequestDto.SupportInfoCommentDto.builder() + .supportInfoId(info1.getId()) + .content("좋아요") + .build(); + CommentRequestDto.SupportInfoCommentDto dto3 = CommentRequestDto.SupportInfoCommentDto.builder() + .supportInfoId(info2.getId()) + .content("유용해요!") + .build(); + CommentRequestDto.SupportInfoCommentDto dto6 = CommentRequestDto.SupportInfoCommentDto.builder() + .supportInfoId(info1.getId()) + .content("굿") + .build(); + CommentRequestDto.SupportInfoCommentDto dto4 = CommentRequestDto.SupportInfoCommentDto.builder() + .supportInfoId(info1.getId()) + .content("굿") + .build(); + CommentRequestDto.SupportInfoCommentDto dto5 = CommentRequestDto.SupportInfoCommentDto.builder() + .supportInfoId(info1.getId()) + .content("굿") + .build(); + + commentService.saveSupportComment(user1.getId(), dto1); + commentService.saveSupportComment(user2.getId(), dto2); + commentService.saveSupportComment(user1.getId(), dto3); // 얘만 info2 + commentService.saveSupportComment(user3.getId(), dto4); + commentService.saveSupportComment(user4.getId(), dto5); + commentService.saveSupportComment(user1.getId(), dto6); + commentService.saveSupportComment(user2.getId(), dto5); + commentService.saveSupportComment(user3.getId(), dto5); + em.flush(); + + PageRequest pageRequest1 = PageRequest.of(0, 2); + Page result1 = commentService.findBySupportInfoWithPaging(info1.getId(), pageRequest1); + + Assertions.assertThat(result1.getTotalElements()).isEqualTo(7); + Assertions.assertThat(result1.getTotalPages()).isEqualTo(4); + Assertions.assertThat(result1.hasNext()).isTrue(); + Assertions.assertThat(result1.hasPrevious()).isFalse(); + List list1 = result1.getContent(); + Assertions.assertThat(list1.get(0).getUserId()).isEqualTo(user1.getId()); + Assertions.assertThat(list1.get(0).getContent()).isEqualTo("굿"); + Assertions.assertThat(list1.get(0).getAnonymousNumber()).isEqualTo(1); + + PageRequest pageRequest2 = PageRequest.of(1, 5); + Page result2 = commentService.findBySupportInfoWithPaging(info1.getId(), pageRequest2); + + Assertions.assertThat(result2.getTotalElements()).isEqualTo(7); + Assertions.assertThat(result2.getTotalPages()).isEqualTo(2); + Assertions.assertThat(result2.hasNext()).isFalse(); + Assertions.assertThat(result2.hasPrevious()).isTrue(); + List list2 = result2.getContent(); + Assertions.assertThat(list2.get(0).getUserId()).isEqualTo(user2.getId()); + Assertions.assertThat(list2.get(0).getContent()).isEqualTo("굿"); + Assertions.assertThat(list2.get(0).getAnonymousNumber()).isEqualTo(2); + } + } \ No newline at end of file From 66ee00944e4e5a304fcbf6ac832f6032953f47e3 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 14:36:33 +0900 Subject: [PATCH 11/20] =?UTF-8?q?[feat]=20CommentRepository=20=EC=9D=B5?= =?UTF-8?q?=EB=AA=85=EB=B2=88=ED=98=B8=20=ED=99=95=EC=9D=B8=EC=9A=A9=20?= =?UTF-8?q?=EB=A7=A4=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/comment/repository/CommentRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepository.java index c24f8c53..b734eca7 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepository.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepository.java @@ -1,6 +1,9 @@ package com.bbteam.budgetbuddies.domain.comment.repository; import com.bbteam.budgetbuddies.domain.comment.entity.Comment; +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; +import com.bbteam.budgetbuddies.domain.user.entity.User; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; @@ -8,6 +11,7 @@ import org.springframework.data.repository.query.Param; import java.util.List; +import java.util.Optional; public interface CommentRepository extends JpaRepository { @Query("select c from Comment c where c.discountInfo.id = :discountInfoId" + @@ -27,4 +31,8 @@ Page findByDiscountInfoWithPaging(@Param("discountInfoId")Long discount " order by c.createdAt asc") Page findBySupportInfoWithPaging(@Param("supportInfoId")Long supportInfoId, Pageable pageable); + + Optional findTopByUserAndDiscountInfo(User user, DiscountInfo discountInfo); + Optional findTopByUserAndSupportInfo(User user, SupportInfo supportInfo); + } From c9e4014883fb05fbc11d9db22dc186252cbc7d43 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 14:49:08 +0900 Subject: [PATCH 12/20] =?UTF-8?q?[feat]=20getter=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java index b66eef77..b8e40e17 100644 --- a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java +++ b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java @@ -21,6 +21,7 @@ @AllArgsConstructor @SuperBuilder @SoftDelete // boolean 타입의 deleted 필드가 추가 +@Getter public abstract class BaseEntity { @Id From 664bc37608a769b5229a5c8c15550408100e1a1f Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 14:58:38 +0900 Subject: [PATCH 13/20] =?UTF-8?q?[feat]=20CommentController=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=95=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/controller/CommentController.java | 47 ++++++++++++------- .../repository/CommentRepositoryTest.java | 3 -- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java index adc42780..f1f35199 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java @@ -8,6 +8,9 @@ import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.responses.ApiResponses; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.web.PageableDefault; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -26,11 +29,11 @@ public class CommentController { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) @Parameters({ - @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다."), - @Parameter(name = "discountInfoId", description = "댓글을 다는 할인 정보 게시글 id입니다."), - @Parameter(name = "content", description = "댓글 내용입니다."), + @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), + @Parameter(name = "discountInfoId", description = "댓글을 다는 할인 정보 게시글 id입니다. requestBody"), + @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), }) - @PostMapping("/discounts/comments/{userId}/add") + @PostMapping("/discounts/comments/add") public ResponseEntity saveDiscountInfoComment( @RequestParam("userId") Long userId, @RequestBody CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto){ @@ -43,12 +46,15 @@ public ResponseEntity saveDiscountInf @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) @Parameters({ - @Parameter(name = "discountInfoId", description = "댓글을 가져올 할인 정보 게시글 id입니다."), + @Parameter(name = "discountInfoId", description = "댓글을 가져올 할인 정보 게시글 id입니다. parameter"), + @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), + @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") }) - @GetMapping("/discounts/comments/get/{discountInfoId}") - public ResponseEntity> findAllByDiscountInfo( - @RequestParam("discountInfoId") Long discountInfoId){ - List result = commentService.findByDiscountInfo(discountInfoId); + @GetMapping("/discounts/comments/get") + public ResponseEntity> findAllByDiscountInfo( + @RequestParam("discountInfoId") Long discountInfoId, + @PageableDefault(size = 20, page = 0) Pageable pageable){ + Page result = commentService.findByDiscountInfoWithPaging(discountInfoId, pageable); return ResponseEntity.ok(result); } @@ -57,11 +63,11 @@ public ResponseEntity> findAllBy @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) @Parameters({ - @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다."), - @Parameter(name = "supportInfoId", description = "댓글을 다는 지원 정보 게시글 id입니다."), - @Parameter(name = "content", description = "댓글 내용입니다."), + @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), + @Parameter(name = "supportInfoId", description = "댓글을 다는 지원 정보 게시글 id입니다. requestBody"), + @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), }) - @PostMapping("/supports/comments/{userId}/add") + @PostMapping("/supports/comments/add") public ResponseEntity saveSupportInfoComment( @RequestParam("userId") Long userId, @RequestBody CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto){ @@ -74,12 +80,17 @@ public ResponseEntity saveSupportInfoC @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) @Parameters({ - @Parameter(name = "supportInfoId", description = "댓글을 가져올 지원 정보 게시글 id입니다."), + @Parameter(name = "supportInfoId", description = "댓글을 가져올 지원 정보 게시글 id입니다. parameter"), + @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), + @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") + + }) - @GetMapping("/supports/comments/get/{supportInfoId}") - public ResponseEntity> findAllBySupportInfo( - @RequestParam("supportInfoId") Long supportInfoId){ - List result = commentService.findBySupportInfo(supportInfoId); + @GetMapping("/supports/comments/get") + public ResponseEntity> findAllBySupportInfo( + @RequestParam("supportInfoId") Long supportInfoId, + @PageableDefault(size = 20, page = 0)Pageable pageable){ + Page result = commentService.findBySupportInfoWithPaging(supportInfoId, pageable); return ResponseEntity.ok(result); } diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepositoryTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepositoryTest.java index 67186f65..4aa430a7 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepositoryTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepositoryTest.java @@ -7,7 +7,6 @@ import com.bbteam.budgetbuddies.domain.supportinfo.repository.SupportInfoRepository; import jakarta.persistence.EntityManager; import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -15,8 +14,6 @@ import java.util.List; -import static org.junit.jupiter.api.Assertions.*; - @SpringBootTest @Transactional From 1d1177582ee3d62b72ac9f4e01a35b17ae40d084 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 15:09:17 +0900 Subject: [PATCH 14/20] =?UTF-8?q?[feat]=20CommentController=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20=EC=82=AD=EC=A0=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/controller/CommentController.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java index f1f35199..066a33a2 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java @@ -94,6 +94,21 @@ public ResponseEntity> findAllByS return ResponseEntity.ok(result); } + @Operation(summary = "[User] 특정 댓글 삭제하기", description = "특정 댓글을 삭제하는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "commentId", description = "삭제할 댓글 id 입니다. parameter") + + + }) + @GetMapping("/comments/delete") + public ResponseEntity deleteComment(@RequestParam("commentId") Long commentId) { + commentService.deleteComment(commentId); + return ResponseEntity.ok("ok"); + } + From 00cb90593a38a4348a81abcf48d74f4950851611 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 15:09:38 +0900 Subject: [PATCH 15/20] =?UTF-8?q?[refactor]=20CommentServiceImpl=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EB=A1=9C=EC=A7=81=EC=97=90=20Transactiona?= =?UTF-8?q?l=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../budgetbuddies/domain/comment/service/CommentServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java index b2490b33..df8063fa 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java @@ -132,6 +132,7 @@ public Page findBySupportInfoWithPagin } @Override + @Transactional public void deleteComment(Long commentId) { Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); commentRepository.delete(comment); From 7bb8af7d2d193c6f109dd9d004d0c3ace32ceaf3 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 15:10:01 +0900 Subject: [PATCH 16/20] =?UTF-8?q?[refactor]=20Dto=EA=B0=80=20commentId=20?= =?UTF-8?q?=ED=8F=AC=ED=95=A8=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/comment/converter/CommentConverter.java | 4 ++++ .../budgetbuddies/domain/comment/dto/CommentResponseDto.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/converter/CommentConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/converter/CommentConverter.java index 0a2395bf..626a1e6f 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/converter/CommentConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/converter/CommentConverter.java @@ -31,6 +31,7 @@ public static Comment toSupportComment(CommentRequestDto.SupportInfoCommentDto d public static CommentResponseDto.DiscountInfoCommentDto toDiscountInfoCommentDto(Comment comment){ return CommentResponseDto.DiscountInfoCommentDto.builder() + .commentId(comment.getId()) .discountInfoId(comment.getDiscountInfo().getId()) .userId(comment.getUser().getId()) .content(comment.getContent()) @@ -41,6 +42,7 @@ public static CommentResponseDto.DiscountInfoCommentDto toDiscountInfoCommentDto public static CommentResponseDto.SupportInfoCommentDto toSupportInfoCommentDto(Comment comment){ return CommentResponseDto.SupportInfoCommentDto.builder() + .commentId(comment.getId()) .supportInfoId(comment.getSupportInfo().getId()) .userId(comment.getUser().getId()) .content(comment.getContent()) @@ -51,6 +53,7 @@ public static CommentResponseDto.SupportInfoCommentDto toSupportInfoCommentDto(C public static CommentResponseDto.DiscountInfoSuccessDto toDiscountInfoSuccessDto(Comment comment){ return CommentResponseDto.DiscountInfoSuccessDto.builder() + .commentId(comment.getId()) .discountInfoId(comment.getDiscountInfo().getId()) .userId(comment.getUser().getId()) .content(comment.getContent()) @@ -59,6 +62,7 @@ public static CommentResponseDto.DiscountInfoSuccessDto toDiscountInfoSuccessDto public static CommentResponseDto.SupportInfoSuccessDto toSupportInfoSuccessDto(Comment comment){ return CommentResponseDto.SupportInfoSuccessDto.builder() + .commentId(comment.getId()) .supportInfoId(comment.getSupportInfo().getId()) .userId(comment.getUser().getId()) .content(comment.getContent()) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java index 70e0df40..bfc27405 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java @@ -9,6 +9,7 @@ public class CommentResponseDto { @Getter @Builder public static class DiscountInfoCommentDto{ + private Long commentId; private Long userId; private Long discountInfoId; private String content; @@ -18,6 +19,7 @@ public static class DiscountInfoCommentDto{ @Getter @Builder public static class SupportInfoCommentDto{ + private Long commentId; private Long userId; private Long supportInfoId; private String content; @@ -27,6 +29,7 @@ public static class SupportInfoCommentDto{ @Getter @Builder public static class DiscountInfoSuccessDto{ + private Long commentId; private Long userId; private Long discountInfoId; private String content; @@ -35,6 +38,7 @@ public static class DiscountInfoSuccessDto{ @Getter @Builder public static class SupportInfoSuccessDto{ + private Long commentId; private Long userId; private Long supportInfoId; private String content; From ffde7fb1e9e04176af93345dead09575204f736f Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 21:56:01 +0900 Subject: [PATCH 17/20] =?UTF-8?q?[refactor]=20CommentController=20Interfac?= =?UTF-8?q?e=20=EB=B6=84=EB=A6=AC=EB=A1=9C=20Swagger=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/controller/CommentController.java | 70 +++++-------------- .../controller/CommentControllerImpl.java | 64 +++++++++++++++++ 2 files changed, 83 insertions(+), 51 deletions(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java index 066a33a2..36500a8b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java @@ -1,29 +1,21 @@ package com.bbteam.budgetbuddies.domain.comment.controller; + import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; -import com.bbteam.budgetbuddies.domain.comment.service.CommentService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.responses.ApiResponses; -import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequiredArgsConstructor -public class CommentController { - - private final CommentService commentService; - - // user, discountInfo 인증 어노테이션 추후 추가 예정 +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +public interface CommentController { @Operation(summary = "[User] 특정 할인 정보 게시글에 댓글달기", description = "특정 할인 정보 게시글에 댓글을 다는 API입니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), @@ -33,13 +25,10 @@ public class CommentController { @Parameter(name = "discountInfoId", description = "댓글을 다는 할인 정보 게시글 id입니다. requestBody"), @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), }) - @PostMapping("/discounts/comments/add") - public ResponseEntity saveDiscountInfoComment( - @RequestParam("userId") Long userId, - @RequestBody CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto){ - CommentResponseDto.DiscountInfoSuccessDto dto = commentService.saveDiscountComment(userId, discountInfoCommentDto); - return ResponseEntity.ok(dto); - } + ResponseEntity saveDiscountInfoComment( + Long userId, + CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto); + @Operation(summary = "[User] 특정 할인 정보 게시글의 댓글 조회하기", description = "특정 할인 정보 게시글의 댓글을 가져오는 API입니다.") @ApiResponses({ @@ -50,13 +39,9 @@ public ResponseEntity saveDiscountInf @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") }) - @GetMapping("/discounts/comments/get") - public ResponseEntity> findAllByDiscountInfo( - @RequestParam("discountInfoId") Long discountInfoId, - @PageableDefault(size = 20, page = 0) Pageable pageable){ - Page result = commentService.findByDiscountInfoWithPaging(discountInfoId, pageable); - return ResponseEntity.ok(result); - } + ResponseEntity> findAllByDiscountInfo( + Long discountInfoId, + Pageable pageable); @Operation(summary = "[User] 특정 지원 정보 게시글에 댓글달기", description = "특정 지원 정보 게시글에 댓글을 다는 API입니다.") @ApiResponses({ @@ -67,13 +52,9 @@ public ResponseEntity> findAllBy @Parameter(name = "supportInfoId", description = "댓글을 다는 지원 정보 게시글 id입니다. requestBody"), @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), }) - @PostMapping("/supports/comments/add") - public ResponseEntity saveSupportInfoComment( - @RequestParam("userId") Long userId, - @RequestBody CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto){ - CommentResponseDto.SupportInfoSuccessDto dto = commentService.saveSupportComment(userId, supportInfoCommentDto); - return ResponseEntity.ok(dto); - } + ResponseEntity saveSupportInfoComment( + Long userId, + CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto); @Operation(summary = "[User] 특정 지원 정보 게시글의 댓글 조회하기", description = "특정 지원 정보 게시글의 댓글을 가져오는 API입니다.") @ApiResponses({ @@ -86,13 +67,9 @@ public ResponseEntity saveSupportInfoC }) - @GetMapping("/supports/comments/get") - public ResponseEntity> findAllBySupportInfo( - @RequestParam("supportInfoId") Long supportInfoId, - @PageableDefault(size = 20, page = 0)Pageable pageable){ - Page result = commentService.findBySupportInfoWithPaging(supportInfoId, pageable); - return ResponseEntity.ok(result); - } + ResponseEntity> findAllBySupportInfo( + Long supportInfoId, + Pageable pageable); @Operation(summary = "[User] 특정 댓글 삭제하기", description = "특정 댓글을 삭제하는 API입니다.") @ApiResponses({ @@ -100,16 +77,7 @@ public ResponseEntity> findAllByS }) @Parameters({ @Parameter(name = "commentId", description = "삭제할 댓글 id 입니다. parameter") - - }) @GetMapping("/comments/delete") - public ResponseEntity deleteComment(@RequestParam("commentId") Long commentId) { - commentService.deleteComment(commentId); - return ResponseEntity.ok("ok"); - } - - - - + ResponseEntity deleteComment(Long commentId); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java new file mode 100644 index 00000000..3a59c2c3 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java @@ -0,0 +1,64 @@ +package com.bbteam.budgetbuddies.domain.comment.controller; + +import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; +import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; +import com.bbteam.budgetbuddies.domain.comment.service.CommentService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.web.PageableDefault; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +public class CommentControllerImpl implements CommentController{ + + private final CommentService commentService; + + @PostMapping("/discounts/comments/add") + public ResponseEntity saveDiscountInfoComment( + @RequestParam("userId") Long userId, + @RequestBody CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto){ + CommentResponseDto.DiscountInfoSuccessDto dto = commentService.saveDiscountComment(userId, discountInfoCommentDto); + return ResponseEntity.ok(dto); + } + + + @GetMapping("/discounts/comments/get") + public ResponseEntity> findAllByDiscountInfo( + @RequestParam("discountInfoId") Long discountInfoId, + @PageableDefault(size = 20, page = 0) Pageable pageable){ + Page result = commentService.findByDiscountInfoWithPaging(discountInfoId, pageable); + return ResponseEntity.ok(result); + } + + + @PostMapping("/supports/comments/add") + public ResponseEntity saveSupportInfoComment( + @RequestParam("userId") Long userId, + @RequestBody CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto){ + CommentResponseDto.SupportInfoSuccessDto dto = commentService.saveSupportComment(userId, supportInfoCommentDto); + return ResponseEntity.ok(dto); + } + + + @GetMapping("/supports/comments/get") + public ResponseEntity> findAllBySupportInfo( + @RequestParam("supportInfoId") Long supportInfoId, + @PageableDefault(size = 20, page = 0)Pageable pageable){ + Page result = commentService.findBySupportInfoWithPaging(supportInfoId, pageable); + return ResponseEntity.ok(result); + } + + + public ResponseEntity deleteComment(@RequestParam("commentId") Long commentId) { + commentService.deleteComment(commentId); + return ResponseEntity.ok("ok"); + } + +} From c3e0a89eb6c898e07829be20336af6ec32adbe5f Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 21:59:26 +0900 Subject: [PATCH 18/20] =?UTF-8?q?[refactor]=20CommentController=20URI=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/comment/controller/CommentControllerImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java index 3a59c2c3..816a4fc0 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java @@ -20,7 +20,7 @@ public class CommentControllerImpl implements CommentController{ private final CommentService commentService; - @PostMapping("/discounts/comments/add") + @PostMapping("/discounts/comments") public ResponseEntity saveDiscountInfoComment( @RequestParam("userId") Long userId, @RequestBody CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto){ @@ -29,7 +29,7 @@ public ResponseEntity saveDiscountInf } - @GetMapping("/discounts/comments/get") + @GetMapping("/discounts/comments") public ResponseEntity> findAllByDiscountInfo( @RequestParam("discountInfoId") Long discountInfoId, @PageableDefault(size = 20, page = 0) Pageable pageable){ @@ -38,7 +38,7 @@ public ResponseEntity> findAllBy } - @PostMapping("/supports/comments/add") + @PostMapping("/supports/comments") public ResponseEntity saveSupportInfoComment( @RequestParam("userId") Long userId, @RequestBody CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto){ @@ -47,7 +47,7 @@ public ResponseEntity saveSupportInfoC } - @GetMapping("/supports/comments/get") + @GetMapping("/supports/comments") public ResponseEntity> findAllBySupportInfo( @RequestParam("supportInfoId") Long supportInfoId, @PageableDefault(size = 20, page = 0)Pageable pageable){ From 21407872521a513dc5e40d0b37872e8581ba1c67 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 22:00:26 +0900 Subject: [PATCH 19/20] =?UTF-8?q?[refactor]=20anonymousNumber=20nullable?= =?UTF-8?q?=20=3D=20false=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/bbteam/budgetbuddies/domain/comment/entity/Comment.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java index 9b3cc376..49dbf6dd 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java @@ -11,6 +11,7 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; import org.hibernate.annotations.Where; +import org.springframework.lang.Nullable; @Entity @Getter @@ -34,6 +35,7 @@ public class Comment extends BaseEntity { @JoinColumn(name = "support_info_id") private SupportInfo supportInfo; + @Column(nullable = false) private Integer anonymousNumber; } From 975962d3f19fe2d26fdbec30f48b1a75c98c1434 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 22:00:40 +0900 Subject: [PATCH 20/20] =?UTF-8?q?[refactor]=20=ED=95=84=EC=97=AC=EC=97=86?= =?UTF-8?q?=EB=8A=94=20import=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/comment/controller/CommentControllerImpl.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java index 816a4fc0..8f9691d7 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java @@ -3,10 +3,6 @@ import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; import com.bbteam.budgetbuddies.domain.comment.service.CommentService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Parameters; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable;