From 09c5c86673c5ba9b1f58930c2b35d97f6ebb674f Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 18 Jul 2024 16:32:08 +0900 Subject: [PATCH 001/126] =?UTF-8?q?feat=20:=20CommentRepository=20?= =?UTF-8?q?=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 | 20 ++ .../repository/CommentRepositoryTest.java | 256 ++++++++++++++++++ 2 files changed, 276 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepository.java create mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepositoryTest.java 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 new file mode 100644 index 00000000..85441385 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepository.java @@ -0,0 +1,20 @@ +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.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; + +public interface CommentRepository extends JpaRepository { + @Query("select c from Comment c where c.discountInfo.id = :discountInfoId" + + " order by c.createdAt asc") // delete_at 을 어떻게 식별해야할지??? + List findByDiscountInfo(@Param("discountInfoId")Long discountInfoId); + + @Query("select c from Comment c where c.supportInfo.id = :supportInfoId" + + " order by c.createdAt asc") + List findBySupportInfo(@Param("supportInfoId")Long supportInfoId); +} 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 new file mode 100644 index 00000000..67186f65 --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/comment/repository/CommentRepositoryTest.java @@ -0,0 +1,256 @@ +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.discountinfo.repository.DiscountInfoRepository; +import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; +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; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + + +@SpringBootTest +@Transactional +class CommentRepositoryTest { + + @Autowired + CommentRepository commentRepository; + + @Autowired + SupportInfoRepository supportInfoRepository; + + @Autowired + DiscountInfoRepository discountInfoRepository; + + @Autowired + EntityManager em; + + + @Test + public void saveTest(){ + Comment comment1 = Comment.builder().content("test1").build(); + Comment comment2 = Comment.builder().content("test2").build(); + + commentRepository.save(comment1); + commentRepository.save(comment2); + + em.flush(); + + Comment found1 = commentRepository.findById(comment1.getId()).get(); + Comment found2 = commentRepository.findById(comment2.getId()).get(); + + + Assertions.assertThat(comment1).isEqualTo(found1); + Assertions.assertThat(comment2).isEqualTo(found2); + } + + @Test + public void findByDiscountInfoTest(){ + DiscountInfo sale1 = DiscountInfo.builder().title("무신사 할인").build(); + DiscountInfo sale2 = DiscountInfo.builder().title("옥션 할인").build(); + + discountInfoRepository.save(sale1); + discountInfoRepository.save(sale2); + Comment comment1 = Comment.builder().content("test1") + .discountInfo(sale1) + .build(); + Comment comment2 = Comment.builder().content("test2") + .discountInfo(sale2) + .build(); + Comment comment3 = Comment.builder().content("test3") + .discountInfo(sale1) + .build(); + Comment comment4 = Comment.builder().content("test4") + .discountInfo(sale1) + .build(); + Comment comment5 = Comment.builder().content("test5") + .discountInfo(sale2) + .build(); + + commentRepository.save(comment1); + commentRepository.save(comment2); + commentRepository.save(comment3); + commentRepository.save(comment4); + commentRepository.save(comment5); + + + em.flush(); + + List found1 = commentRepository.findByDiscountInfo(sale1.getId()); + List found2 = commentRepository.findByDiscountInfo(sale2.getId()); + + Assertions.assertThat(found1.size()).isEqualTo(3); + Assertions.assertThat(found2.size()).isEqualTo(2); + + + Assertions.assertThat(found1.get(0)).isEqualTo(comment1); + Assertions.assertThat(found1.get(1)).isEqualTo(comment3); + Assertions.assertThat(found1.get(2)).isEqualTo(comment4); + Assertions.assertThat(found2.get(0)).isEqualTo(comment2); + Assertions.assertThat(found2.get(1)).isEqualTo(comment5); + + + } + + @Test + public void findBySupportInfoTest(){ +// DiscountInfo sale1 = DiscountInfo.builder().title("무신사 할인").build(); +// DiscountInfo sale2 = DiscountInfo.builder().title("옥션 할인").build(); + + SupportInfo support1 = SupportInfo.builder().title("국가장학금").build(); + SupportInfo support2 = SupportInfo.builder().title("비전장학금").build(); + SupportInfo support3 = SupportInfo.builder().title("좋은장학금").build(); + SupportInfo support4 = SupportInfo.builder().title("서울봉사").build(); + SupportInfo support5 = SupportInfo.builder().title("청년대출").build(); + + supportInfoRepository.save(support1); + supportInfoRepository.save(support2); + supportInfoRepository.save(support3); + supportInfoRepository.save(support4); + supportInfoRepository.save(support5); + + Comment comment1 = Comment.builder().content("test1") + .supportInfo(support1) + .build(); + Comment comment2 = Comment.builder().content("test2") + .supportInfo(support2) + .build(); + Comment comment3 = Comment.builder().content("test3") + .supportInfo(support3) + .build(); + Comment comment4 = Comment.builder().content("test4") + .supportInfo(support4) + .build(); + Comment comment5 = Comment.builder().content("test5") + .supportInfo(support5) + .build(); + Comment comment6 = Comment.builder().content("test6") + .supportInfo(support1) + .build(); + Comment comment7 = Comment.builder().content("test7") + .supportInfo(support1) + .build(); + Comment comment8 = Comment.builder().content("test8") + .supportInfo(support3) + .build(); + Comment comment9 = Comment.builder().content("test9") + .supportInfo(support4) + .build(); + Comment comment10 = Comment.builder().content("test10") + .supportInfo(support4) + .build(); + + + commentRepository.save(comment1); + commentRepository.save(comment2); + commentRepository.save(comment3); + commentRepository.save(comment4); + commentRepository.save(comment5); + commentRepository.save(comment6); + commentRepository.save(comment7); + commentRepository.save(comment8); + commentRepository.save(comment9); + commentRepository.save(comment10); + + + em.flush(); + + List found1 = commentRepository.findBySupportInfo(support1.getId()); + List found2 = commentRepository.findBySupportInfo(support2.getId()); + List found3 = commentRepository.findBySupportInfo(support3.getId()); + List found4 = commentRepository.findBySupportInfo(support4.getId()); + List found5 = commentRepository.findBySupportInfo(support5.getId()); + + Assertions.assertThat(found1.size()).isEqualTo(3); + Assertions.assertThat(found2.size()).isEqualTo(1); + Assertions.assertThat(found3.size()).isEqualTo(2); + Assertions.assertThat(found4.size()).isEqualTo(3); + Assertions.assertThat(found5.size()).isEqualTo(1); + + } + + @Test + public void deleteTest(){ + SupportInfo support1 = SupportInfo.builder().title("국가장학금").build(); + SupportInfo support2 = SupportInfo.builder().title("비전장학금").build(); + SupportInfo support3 = SupportInfo.builder().title("좋은장학금").build(); + SupportInfo support4 = SupportInfo.builder().title("서울봉사").build(); + SupportInfo support5 = SupportInfo.builder().title("청년대출").build(); + + supportInfoRepository.save(support1); + supportInfoRepository.save(support2); + supportInfoRepository.save(support3); + supportInfoRepository.save(support4); + supportInfoRepository.save(support5); + + Comment comment1 = Comment.builder().content("test1") + .supportInfo(support1) + .build(); + Comment comment2 = Comment.builder().content("test2") + .supportInfo(support2) + .build(); + Comment comment3 = Comment.builder().content("test3") + .supportInfo(support3) + .build(); + Comment comment4 = Comment.builder().content("test4") + .supportInfo(support4) + .build(); + Comment comment5 = Comment.builder().content("test5") + .supportInfo(support5) + .build(); + Comment comment6 = Comment.builder().content("test6") + .supportInfo(support1) + .build(); + Comment comment7 = Comment.builder().content("test7") + .supportInfo(support1) + .build(); + Comment comment8 = Comment.builder().content("test8") + .supportInfo(support3) + .build(); + Comment comment9 = Comment.builder().content("test9") + .supportInfo(support4) + .build(); + Comment comment10 = Comment.builder().content("test10") + .supportInfo(support4) + .build(); + + + commentRepository.save(comment1); + commentRepository.save(comment2); + commentRepository.save(comment3); + commentRepository.save(comment4); + commentRepository.save(comment5); + commentRepository.save(comment6); + commentRepository.save(comment7); + commentRepository.save(comment8); + commentRepository.save(comment9); + commentRepository.save(comment10); + + commentRepository.delete(comment1); // comment1이 삭제되면 support1의 개수는 2개가 되어야한다. + + em.flush(); + + List found1 = commentRepository.findBySupportInfo(support1.getId()); + List found2 = commentRepository.findBySupportInfo(support2.getId()); + List found3 = commentRepository.findBySupportInfo(support3.getId()); + List found4 = commentRepository.findBySupportInfo(support4.getId()); + List found5 = commentRepository.findBySupportInfo(support5.getId()); + + Assertions.assertThat(found1.size()).isEqualTo(2); // 해당 로직 검증 + Assertions.assertThat(found2.size()).isEqualTo(1); + Assertions.assertThat(found3.size()).isEqualTo(2); + Assertions.assertThat(found4.size()).isEqualTo(3); + Assertions.assertThat(found5.size()).isEqualTo(1); + } + + +} \ No newline at end of file From df12c8a90fd886b80de8354c91b28620f200b736 Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 18 Jul 2024 18:54:41 +0900 Subject: [PATCH 002/126] =?UTF-8?q?[feat]=20TopGoalCategoryResponseDTO=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/TopGoalCategoryResponseDTO.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopGoalCategoryResponseDTO.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopGoalCategoryResponseDTO.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopGoalCategoryResponseDTO.java new file mode 100644 index 00000000..6507cafb --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopGoalCategoryResponseDTO.java @@ -0,0 +1,20 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.dto; + +import com.bbteam.budgetbuddies.domain.category.entity.Category; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TopGoalCategoryResponseDTO { + + private Category category; + + private Long consumeAmount; + +} \ No newline at end of file From 8ec52363ae7a4e0f23ddaf31b7dc4e9e872cc152 Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 18 Jul 2024 22:19:07 +0900 Subject: [PATCH 003/126] =?UTF-8?q?[feat]=20ConsumptionGoalRepository=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ConsumptionGoalRepository.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java new file mode 100644 index 00000000..f338fee5 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java @@ -0,0 +1,10 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; + +@Repository +public interface ConsumptionGoalRepository extends JpaRepository { +} \ No newline at end of file From 5a178b61b647e6742946e3a221a47f25e7100737 Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 18 Jul 2024 22:39:54 +0900 Subject: [PATCH 004/126] =?UTF-8?q?[feat]=20ConsumptionGoal=20id=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20/=20=EC=A7=80=EC=97=B0=EB=A1=9C=EB=94=A9?= =?UTF-8?q?=EC=9C=BC=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 --- .../domain/consumptiongoal/entity/ConsumptionGoal.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java index 932a9bf4..2a630997 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java @@ -20,6 +20,10 @@ @SuperBuilder public class ConsumptionGoal extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @Column(nullable = false) @Min(value = 1, message = "0 또는 음수의 목표금액을 설정할 수 없습니다.") private Long goalAmount; @@ -31,11 +35,11 @@ public class ConsumptionGoal extends BaseEntity { @Column(nullable = false) private LocalDate goalMonth; - @ManyToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; - @ManyToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "category_id") private Category category; From b44813eb60ae9caf105158106d3de0241f901074 Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 18 Jul 2024 23:43:21 +0900 Subject: [PATCH 005/126] =?UTF-8?q?[fix]=20TopGoalCategoryResponseDTO=20?= =?UTF-8?q?=EB=AA=A9=ED=91=9C=EA=B8=88=EC=95=A1=EC=9C=BC=EB=A1=9C=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/consumptiongoal/dto/TopGoalCategoryResponseDTO.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopGoalCategoryResponseDTO.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopGoalCategoryResponseDTO.java index 6507cafb..23859cc9 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopGoalCategoryResponseDTO.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopGoalCategoryResponseDTO.java @@ -15,6 +15,6 @@ public class TopGoalCategoryResponseDTO { private Category category; - private Long consumeAmount; + private Long goalAmount; } \ No newline at end of file From 8dc0bc2f5bb4f9e887906718b250d695e64862f0 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Fri, 19 Jul 2024 19:29:35 +0900 Subject: [PATCH 006/126] =?UTF-8?q?feat=20:=20CommentService=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 --- .../comment/service/CommentService.java | 20 + .../comment/service/CommentServiceImpl.java | 111 ++++++ .../comment/service/CommentServiceTest.java | 365 ++++++++++++++++++ 3 files changed, 496 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentService.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java create mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTest.java 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 new file mode 100644 index 00000000..2e5693de --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentService.java @@ -0,0 +1,20 @@ +package com.bbteam.budgetbuddies.domain.comment.service; + +import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; +import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; + +import java.util.List; + +public interface CommentService { + CommentResponseDto.SupportInfoSuccessDto saveSupportComment(Long userId, CommentRequestDto.SupportInfoCommentDto dto); + CommentResponseDto.DiscountInfoSuccessDto saveDiscountComment(Long userId, CommentRequestDto.DiscountInfoCommentDto dto); + + + List findByDiscountInfo(Long discountInfoId); + + List findBySupportInfo(Long supportInfoId); + + + + +} 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 new file mode 100644 index 00000000..4b394081 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java @@ -0,0 +1,111 @@ +package com.bbteam.budgetbuddies.domain.comment.service; + + +import com.bbteam.budgetbuddies.domain.comment.converter.CommentConverter; +import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; +import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; +import com.bbteam.budgetbuddies.domain.comment.entity.Comment; +import com.bbteam.budgetbuddies.domain.comment.repository.CommentRepository; +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +import com.bbteam.budgetbuddies.domain.discountinfo.repository.DiscountInfoRepository; +import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; +import com.bbteam.budgetbuddies.domain.supportinfo.repository.SupportInfoRepository; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.HashMap; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.stream.Collectors; + +// 임시로 유저는 service에서 찾아서 처리하는 로직으로 작성함 +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class CommentServiceImpl implements CommentService{ + + private final CommentRepository commentRepository; + private final UserRepository userRepository; + private final DiscountInfoRepository discountInfoRepository; + private final SupportInfoRepository supportInfoRepository; + + @Override + @Transactional + 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); + Comment savedComment = commentRepository.save(comment); + + return CommentConverter.toSupportInfoSuccessDto(savedComment); + } + + + + @Override + @Transactional + 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); + Comment savedComment = commentRepository.save(comment); + + return CommentConverter.toDiscountInfoSuccessDto(savedComment); + } + + @Override + public List findByDiscountInfo(Long discountInfoId) { + List commentList = commentRepository.findByDiscountInfo(discountInfoId); + + HashMap anonymousMapping = countAnonymousNumber(commentList); + List collect = commentList.stream() + .map(comment -> CommentConverter.toDiscountInfoCommentDto(comment, anonymousMapping)) + .collect(Collectors.toList()); + return collect; + + } + + @Override + public List findBySupportInfo(Long supportInfoId) { + List commentList = commentRepository.findBySupportInfo(supportInfoId); + HashMap anonymousMapping = countAnonymousNumber(commentList); + List collect = commentList.stream() + .map(comment -> CommentConverter.toSupportInfoCommentDto(comment, anonymousMapping)) + .collect(Collectors.toList()); + return collect; + } + + private static HashMap countAnonymousNumber(List commentList) { + HashMap anonymousMapping = new HashMap<>(); + Long count = 1L; + for (Comment comment : commentList) { + Long id = comment.getUser().getId(); + if(!anonymousMapping.containsKey(id)){ + anonymousMapping.put(id, count); + count++; + } + } + return anonymousMapping; + } + + @Transactional + public void removeDiscountInfoComment(Long discountInfoId){ + DiscountInfo discountInfo = discountInfoRepository.findById(discountInfoId).orElseThrow(() -> new NoSuchElementException("No such Entity")); + discountInfoRepository.delete(discountInfo); + return; + } + + @Transactional + public void removeSupportInfoComment(Long supportInfoId){ + SupportInfo supportInfo = supportInfoRepository.findById(supportInfoId).orElseThrow(() -> new NoSuchElementException("No such Entity")); + supportInfoRepository.delete(supportInfo); + return; + } + + +} 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 new file mode 100644 index 00000000..c3ade564 --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTest.java @@ -0,0 +1,365 @@ +package com.bbteam.budgetbuddies.domain.comment.service; + +import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; +import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +import com.bbteam.budgetbuddies.domain.discountinfo.repository.DiscountInfoRepository; +import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; +import com.bbteam.budgetbuddies.domain.supportinfo.repository.SupportInfoRepository; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; +import jakarta.persistence.EntityManager; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * comment service는 다음과 같은 기능을 제공해야한다. + * 1. comment 저장 기능 + * 2. 특정 게시글에 따른 comment return + * 현재 게시글의 종류는 2가지로 각각 할인정보, 지원정보이다. + * 즉, 할인정보, 지원정보 ID가 들어오면 해당 게시글에 대한 댓글 정보를 다 가지고 올 수 있어야한다. + * 아마 관리 측면에선 댓글 삭제 기능도 필요할 것이다. + * 3. 특정 userid로 댓글 찾는 기능 + * 얘는 게시글 ID랑 제목 정도 같이??? + * 4. 특정 게시글 id로 댓글 찾는 기능 + */ + +@SpringBootTest +@Transactional +class CommentServiceTest { + @Autowired + CommentService commentService; + + @Autowired + UserRepository userRepository; + @Autowired + DiscountInfoRepository discountInfoRepository; + @Autowired + SupportInfoRepository supportInfoRepository; + @Autowired + EntityManager em; + + @Test + public void saveDiscountInfoCommentTest(){ + User user1 = User.builder() + .name("tester1") + .email("1234") + .age(5) + .phoneNumber("123456") + .build(); + userRepository.save(user1); + + DiscountInfo sale1 = DiscountInfo.builder().title("무신사 할인").build(); + discountInfoRepository.save(sale1); + + CommentRequestDto.DiscountInfoCommentDto dto1 = CommentRequestDto.DiscountInfoCommentDto.builder() + .discountInfoId(sale1.getId()) + .content("굿") + .build(); + + commentService.saveDiscountComment(user1.getId(), dto1); + em.flush(); + + List returnDto = commentService.findByDiscountInfo(sale1.getId()); + + Assertions.assertThat(returnDto.size()).isEqualTo(1); + Assertions.assertThat(returnDto.get(0).getDiscountInfoId()).isEqualTo(sale1.getId()); + Assertions.assertThat(returnDto.get(0).getUserId()).isEqualTo(user1.getId()); + Assertions.assertThat(returnDto.get(0).getContent()).isEqualTo("굿"); + + } + + @Test + public void saveDiscountInfoCommentTest2(){ + 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(); + userRepository.save(user2); + + DiscountInfo sale1 = DiscountInfo.builder().title("무신사 할인").build(); + discountInfoRepository.save(sale1); + DiscountInfo sale2 = DiscountInfo.builder().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(); + + commentService.saveDiscountComment(user1.getId(), dto1); + commentService.saveDiscountComment(user2.getId(), dto2); + commentService.saveDiscountComment(user1.getId(), dto3); + + em.flush(); + + List returnDto = commentService.findByDiscountInfo(sale1.getId()); + List returnDto2 = commentService.findByDiscountInfo(sale2.getId()); + Assertions.assertThat(returnDto.size()).isEqualTo(2); + Assertions.assertThat(returnDto.get(0).getDiscountInfoId()).isEqualTo(sale1.getId()); + Assertions.assertThat(returnDto.get(0).getUserId()).isEqualTo(user1.getId()); + Assertions.assertThat(returnDto.get(0).getContent()).isEqualTo("굿"); + Assertions.assertThat(returnDto.get(1).getDiscountInfoId()).isEqualTo(sale1.getId()); + Assertions.assertThat(returnDto.get(1).getUserId()).isEqualTo(user2.getId()); + Assertions.assertThat(returnDto.get(1).getContent()).isEqualTo("좋아요"); + + Assertions.assertThat(returnDto2.size()).isEqualTo(1); + Assertions.assertThat(returnDto2.get(0).getDiscountInfoId()).isEqualTo(sale2.getId()); + Assertions.assertThat(returnDto2.get(0).getUserId()).isEqualTo(user1.getId()); + Assertions.assertThat(returnDto2.get(0).getContent()).isEqualTo("유용해요!"); + + } + + @Test + void DiscountAnonymousCommentTest(){ + 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().title("무신사 할인").build(); + discountInfoRepository.save(sale1); + DiscountInfo sale2 = DiscountInfo.builder().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); + + 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(); + + Assertions.assertThat(test1).isEqualTo(1); + Assertions.assertThat(test2).isEqualTo(2); + Assertions.assertThat(test3).isEqualTo(1); + Assertions.assertThat(test4).isEqualTo(3); + + + } + + @Test + public void saveSupportInfoCommentTest2(){ + 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(); + userRepository.save(user2); + + SupportInfo info1 = SupportInfo.builder().title("국가장학금 신청").build(); + supportInfoRepository.save(info1); + SupportInfo info2 = SupportInfo.builder().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(); + + commentService.saveSupportComment(user1.getId(), dto1); + commentService.saveSupportComment(user2.getId(), dto2); + commentService.saveSupportComment(user1.getId(), dto3); + + em.flush(); + + List returnDto = commentService.findBySupportInfo(info1.getId()); + List returnDto2 = commentService.findBySupportInfo(info2.getId()); + Assertions.assertThat(returnDto.size()).isEqualTo(2); + Assertions.assertThat(returnDto.get(0).getSupportInfoId()).isEqualTo(info1.getId()); + Assertions.assertThat(returnDto.get(0).getUserId()).isEqualTo(user1.getId()); + Assertions.assertThat(returnDto.get(0).getContent()).isEqualTo("굿"); + Assertions.assertThat(returnDto.get(1).getSupportInfoId()).isEqualTo(info1.getId()); + Assertions.assertThat(returnDto.get(1).getUserId()).isEqualTo(user2.getId()); + Assertions.assertThat(returnDto.get(1).getContent()).isEqualTo("좋아요"); + + Assertions.assertThat(returnDto2.size()).isEqualTo(1); + Assertions.assertThat(returnDto2.get(0).getSupportInfoId()).isEqualTo(info2.getId()); + Assertions.assertThat(returnDto2.get(0).getUserId()).isEqualTo(user1.getId()); + Assertions.assertThat(returnDto2.get(0).getContent()).isEqualTo("유용해요!"); + + } + + @Test + void supportAnonymousCommentTest(){ + 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().title("국가장학금 신청").build(); + supportInfoRepository.save(info1); + SupportInfo info2 = SupportInfo.builder().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); + commentService.saveSupportComment(user3.getId(), dto4); + commentService.saveSupportComment(user4.getId(), dto5); + commentService.saveSupportComment(user1.getId(), dto6); + + em.flush(); + + 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(); + + Assertions.assertThat(test1).isEqualTo(1); + Assertions.assertThat(test2).isEqualTo(2); + Assertions.assertThat(test3).isEqualTo(3); + Assertions.assertThat(test4).isEqualTo(4); + Assertions.assertThat(test5).isEqualTo(1); + } + + + +} \ No newline at end of file From e85b549004c37e7660a8c71c71f1556b4b45941e Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Fri, 19 Jul 2024 19:32:15 +0900 Subject: [PATCH 007/126] =?UTF-8?q?[chore]=20=EC=97=B0=EA=B4=80=EA=B4=80?= =?UTF-8?q?=EA=B3=84=20=EB=A1=9C=EB=94=A9=EC=8B=9C=20FetchType.Eager=20->?= =?UTF-8?q?=20FetchType.Lazy=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 --- .../budgetbuddies/domain/comment/entity/Comment.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 43918096..9ce02ba7 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 @@ -10,6 +10,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.Where; @Entity @Getter @@ -21,15 +22,15 @@ public class Comment extends BaseEntity { @Column(nullable = false, length = 1000) private String content; - @ManyToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; - @ManyToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "discount_info_id") private DiscountInfo discountInfo; - @ManyToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "support_info_id") private SupportInfo supportInfo; From 7ec033e278834cc2cad9ee34960866cd3db521cf Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Fri, 19 Jul 2024 19:33:45 +0900 Subject: [PATCH 008/126] =?UTF-8?q?[feat]=20CommentRequestDto,=20CommentRe?= =?UTF-8?q?sponseDto,=20CommentConverter=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/converter/CommentConverter.java | 68 +++++++++++++++++++ .../domain/comment/dto/CommentRequestDto.java | 24 +++++++ .../comment/dto/CommentResponseDto.java | 41 +++++++++++ 3 files changed, 133 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/converter/CommentConverter.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentRequestDto.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java 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 new file mode 100644 index 00000000..a589bacf --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/converter/CommentConverter.java @@ -0,0 +1,68 @@ +package com.bbteam.budgetbuddies.domain.comment.converter; + +import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; +import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; +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 java.util.HashMap; + +public class CommentConverter { + + public static Comment toDiscountComment(CommentRequestDto.DiscountInfoCommentDto dto, User user, DiscountInfo discountInfo) { + return Comment.builder() + .user(user) + .discountInfo(discountInfo) + .content(dto.getContent()) + .build(); + } + + public static Comment toSupportComment(CommentRequestDto.SupportInfoCommentDto dto, User user, SupportInfo supportInfo) { + return Comment.builder() + .user(user) + .supportInfo(supportInfo) + .content(dto.getContent()) + .build(); + } + + public static CommentResponseDto.DiscountInfoCommentDto toDiscountInfoCommentDto(Comment comment, + HashMap anonymousMapping){ + return CommentResponseDto.DiscountInfoCommentDto.builder() + .discountInfoId(comment.getDiscountInfo().getId()) + .userId(comment.getUser().getId()) + .content(comment.getContent()) + .anonymousNumber(anonymousMapping.get(comment.getUser().getId())) + .build(); + + } + + public static CommentResponseDto.SupportInfoCommentDto toSupportInfoCommentDto(Comment comment, + HashMap anonymousMapping){ + return CommentResponseDto.SupportInfoCommentDto.builder() + .supportInfoId(comment.getSupportInfo().getId()) + .userId(comment.getUser().getId()) + .content(comment.getContent()) + .anonymousNumber(anonymousMapping.get(comment.getUser().getId())) + .build(); + + } + + public static CommentResponseDto.DiscountInfoSuccessDto toDiscountInfoSuccessDto(Comment comment){ + return CommentResponseDto.DiscountInfoSuccessDto.builder() + .discountInfoId(comment.getDiscountInfo().getId()) + .userId(comment.getUser().getId()) + .content(comment.getContent()) + .build(); + } + + public static CommentResponseDto.SupportInfoSuccessDto toSupportInfoSuccessDto(Comment comment){ + return CommentResponseDto.SupportInfoSuccessDto.builder() + .supportInfoId(comment.getSupportInfo().getId()) + .userId(comment.getUser().getId()) + .content(comment.getContent()) + .build(); + } + +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentRequestDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentRequestDto.java new file mode 100644 index 00000000..c5488bff --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentRequestDto.java @@ -0,0 +1,24 @@ +package com.bbteam.budgetbuddies.domain.comment.dto; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + + +public class CommentRequestDto { + @Setter + @Getter + @Builder + public static class DiscountInfoCommentDto { + private String content; + private Long discountInfoId; + } + + @Setter + @Getter + @Builder + public static class SupportInfoCommentDto { + private String content; + private Long supportInfoId; + } +} 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 new file mode 100644 index 00000000..01f17bb2 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java @@ -0,0 +1,41 @@ +package com.bbteam.budgetbuddies.domain.comment.dto; + +import lombok.Builder; +import lombok.Getter; + +public class CommentResponseDto { + + @Getter + @Builder + public static class DiscountInfoCommentDto{ + private Long userId; + private Long discountInfoId; + private String content; + private Long anonymousNumber; + } + + @Getter + @Builder + public static class SupportInfoCommentDto{ + private Long userId; + private Long supportInfoId; + private String content; + private Long anonymousNumber; + } + + @Getter + @Builder + public static class DiscountInfoSuccessDto{ + private Long userId; + private Long discountInfoId; + private String content; + } + + @Getter + @Builder + public static class SupportInfoSuccessDto{ + private Long userId; + private Long supportInfoId; + private String content; + } +} From fe41b46babe298defdd8365acc1a3dcd9be47911 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Fri, 19 Jul 2024 19:34:15 +0900 Subject: [PATCH 009/126] =?UTF-8?q?[fix]=20Id=EB=A5=BC=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EA=B8=B0=20=EC=9C=84=ED=95=B4=20getter=20?= =?UTF-8?q?=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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java index e743a0e2..e673c934 100644 --- a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java +++ b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java @@ -3,6 +3,7 @@ import jakarta.persistence.*; import lombok.AccessLevel; import lombok.AllArgsConstructor; +import lombok.Getter; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; import org.hibernate.annotations.SoftDelete; @@ -18,6 +19,7 @@ @AllArgsConstructor @SuperBuilder @SoftDelete // boolean 타입의 deleted 필드가 추가 +@Getter public abstract class BaseEntity { @Id From 51ada16019a05a5f33836337e31f28f1f395f46e Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Fri, 19 Jul 2024 20:14:37 +0900 Subject: [PATCH 010/126] =?UTF-8?q?[feat]=20CommentService=20=EC=97=90=20?= =?UTF-8?q?=EC=A3=BC=EC=84=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/comment/service/CommentService.java | 12 ++++++++++++ 1 file changed, 12 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 2e5693de..fdbb743f 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 @@ -10,8 +10,20 @@ public interface CommentService { CommentResponseDto.DiscountInfoSuccessDto saveDiscountComment(Long userId, CommentRequestDto.DiscountInfoCommentDto dto); + /** + * + * @param discountInfoId + * @return List + * 해당 로직은 익명 구분을 위한 익명 구분 숫자도 같이 return 합니다. + */ List findByDiscountInfo(Long discountInfoId); + /** + * + * @param supportInfoId + * @return List + * 해당 로직은 익명 구분을 위한 익명 구분 숫자도 같이 return 합니다. + */ List findBySupportInfo(Long supportInfoId); From ca725de5b36873882f159bc3e09de42cce812786 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Fri, 19 Jul 2024 20:14:52 +0900 Subject: [PATCH 011/126] =?UTF-8?q?[feat]=20CommentController=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 --- .../comment/controller/CommentController.java | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.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 new file mode 100644 index 00000000..5ef52bb3 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java @@ -0,0 +1,90 @@ +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.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/comments") +public class CommentController { + + private final CommentService commentService; + + // user, discountInfo 인증 어노테이션 추후 추가 예정 + + @Operation(summary = "[User] 특정 할인 정보 게시글에 댓글달기", description = "특정 할인 정보 게시글에 댓글을 다는 API입니다.") + @ApiResponses({ + @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 = "댓글 내용입니다."), + }) + @PostMapping("/discounts/{userId}/add") + public ResponseEntity saveDiscountInfoComment( + @RequestParam("userId") Long userId, + @RequestBody CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto){ + CommentResponseDto.DiscountInfoSuccessDto dto = commentService.saveDiscountComment(userId, discountInfoCommentDto); + return ResponseEntity.ok(dto); + } + + @Operation(summary = "[User] 특정 할인 정보 게시글의 댓글 조회하기", description = "특정 할인 정보 게시글의 댓글을 가져오는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "discountInfoId", description = "댓글을 가져올 할인 정보 게시글 id입니다."), + }) + @GetMapping("/discounts/get/{discountInfoId}") + public ResponseEntity> findAllByDiscountInfo( + @RequestParam("discountInfoId") Long discountInfoId){ + List result = commentService.findByDiscountInfo(discountInfoId); + return ResponseEntity.ok(result); + } + + @Operation(summary = "[User] 특정 지원 정보 게시글에 댓글달기", description = "특정 지원 정보 게시글에 댓글을 다는 API입니다.") + @ApiResponses({ + @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 = "댓글 내용입니다."), + }) + @PostMapping("/supports/{userId}/add") + public ResponseEntity saveSupportInfoComment( + @RequestParam("userId") Long userId, + @RequestBody CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto){ + CommentResponseDto.SupportInfoSuccessDto dto = commentService.saveSupportComment(userId, supportInfoCommentDto); + return ResponseEntity.ok(dto); + } + + @Operation(summary = "[User] 특정 지원 정보 게시글의 댓글 조회하기", description = "특정 지원 정보 게시글의 댓글을 가져오는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "supportInfoId", description = "댓글을 가져올 지원 정보 게시글 id입니다."), + }) + @GetMapping("/supports/get/{supportInfoId}") + public ResponseEntity> findAllBySupportInfo( + @RequestParam("supportInfoId") Long supportInfoId){ + List result = commentService.findBySupportInfo(supportInfoId); + return ResponseEntity.ok(result); + } + + + + +} From bf1b561b5983548b70617f299ad68ccd9ec8cb70 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Fri, 19 Jul 2024 20:15:20 +0900 Subject: [PATCH 012/126] =?UTF-8?q?[fix]=20CommentRepository=20=EC=A3=BC?= =?UTF-8?q?=EC=84=9D=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/comment/repository/CommentRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 85441385..e197d82a 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 @@ -11,7 +11,7 @@ public interface CommentRepository extends JpaRepository { @Query("select c from Comment c where c.discountInfo.id = :discountInfoId" + - " order by c.createdAt asc") // delete_at 을 어떻게 식별해야할지??? + " order by c.createdAt asc") List findByDiscountInfo(@Param("discountInfoId")Long discountInfoId); @Query("select c from Comment c where c.supportInfo.id = :supportInfoId" + From 5f8685884397a7ddd23a377a47d1c264738b2840 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Fri, 19 Jul 2024 20:24:30 +0900 Subject: [PATCH 013/126] =?UTF-8?q?"=ED=95=98=EB=82=98=EC=9D=98=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=EA=B0=80=20=EB=8F=99=EC=9D=BC=ED=95=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=EC=9D=98=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=83=9D=EC=84=B1=EC=8B=9C=20exception=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=20=EC=BD=94=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 --- .../budgetbuddies/apiPayload/ApiResponse.java | 38 ++++++++++++++++++ .../apiPayload/code/BaseCode.java | 10 +++++ .../apiPayload/code/BaseErrorCode.java | 4 ++ .../apiPayload/code/status/SuccessStatus.java | 14 +++++++ .../budgetbuddies/common/BaseEntity.java | 3 +- .../controller/CategoryController.java | 38 ++++++++++++++++++ .../category/converter/CategoryConverter.java | 28 +++++++++++++ .../category/dto/CategoryRequestDTO.java | 12 ++++++ .../category/dto/CategoryResponseDTO.java | 14 +++++++ .../domain/category/entity/Category.java | 8 ++++ .../repository/CategoryRepository.java | 10 +++++ .../category/service/CategoryService.java | 9 +++++ .../category/service/CategoryServiceImpl.java | 39 +++++++++++++++++++ .../comment/dto/CommentResponseDto.java | 4 ++ .../user/controller/UserController.java | 31 +++++++++++++++ .../domain/user/service/UserService.java | 27 +++++++++++++ 16 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/apiPayload/ApiResponse.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/apiPayload/code/BaseCode.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/apiPayload/code/BaseErrorCode.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/SuccessStatus.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/controller/CategoryController.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/converter/CategoryConverter.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/dto/CategoryRequestDTO.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/dto/CategoryResponseDTO.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryService.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryServiceImpl.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/controller/UserController.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserService.java diff --git a/src/main/java/com/bbteam/budgetbuddies/apiPayload/ApiResponse.java b/src/main/java/com/bbteam/budgetbuddies/apiPayload/ApiResponse.java new file mode 100644 index 00000000..b9d069a0 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/apiPayload/ApiResponse.java @@ -0,0 +1,38 @@ +package com.bbteam.budgetbuddies.apiPayload; + +import com.bbteam.budgetbuddies.apiPayload.code.BaseCode; +import com.bbteam.budgetbuddies.apiPayload.code.status.SuccessStatus; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +@JsonPropertyOrder({"isSuccess", "code", "message", "result"}) +public class ApiResponse { + + @JsonProperty("isSuccess") + private final Boolean isSuccess; + private final String code; + private final String message; + @JsonInclude(JsonInclude.Include.NON_NULL) + private T result; + + + // 성공한 경우 응답 생성 + public static ApiResponse onSuccess(T result){ + return new ApiResponse<>(true, SuccessStatus.OK.getCode() , SuccessStatus.OK.getMessage(), result); + } + + public static ApiResponse of(BaseCode code, T result){ + return new ApiResponse<>(true, code.getReasonHttpStatus().getCode() , code.getReasonHttpStatus().getMessage(), result); + } + + + // 실패한 경우 응답 생성 + public static ApiResponse onFailure(String code, String message, T data){ + return new ApiResponse<>(true, code, message, data); + } +} \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/BaseCode.java b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/BaseCode.java new file mode 100644 index 00000000..d5fb4d79 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/BaseCode.java @@ -0,0 +1,10 @@ +package com.bbteam.budgetbuddies.apiPayload.code; + +public interface BaseCode { + ReasonHttpStatus getReasonHttpStatus(); + + interface ReasonHttpStatus { + String getCode(); + String getMessage(); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/BaseErrorCode.java b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/BaseErrorCode.java new file mode 100644 index 00000000..c3388e55 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/BaseErrorCode.java @@ -0,0 +1,4 @@ +package com.bbteam.budgetbuddies.apiPayload.code; + +public interface BaseErrorCode { +} diff --git a/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/SuccessStatus.java b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/SuccessStatus.java new file mode 100644 index 00000000..414fe213 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/SuccessStatus.java @@ -0,0 +1,14 @@ +package com.bbteam.budgetbuddies.apiPayload.code.status; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum SuccessStatus { + OK("200", "OK"); + + private final String code; + private final String message; +} + diff --git a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java index 7a9756c1..d1528aa1 100644 --- a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java +++ b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java @@ -2,6 +2,7 @@ import jakarta.persistence.*; import lombok.*; + import lombok.experimental.SuperBuilder; import org.hibernate.annotations.SoftDelete; import org.springframework.data.annotation.CreatedDate; @@ -12,9 +13,9 @@ @EntityListeners(AuditingEntityListener.class) @MappedSuperclass +@Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor -@Getter @SuperBuilder @SoftDelete // boolean 타입의 deleted 필드가 추가 public abstract class BaseEntity { diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/controller/CategoryController.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/controller/CategoryController.java new file mode 100644 index 00000000..fc866203 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/controller/CategoryController.java @@ -0,0 +1,38 @@ +package com.bbteam.budgetbuddies.domain.category.controller; + +import com.bbteam.budgetbuddies.domain.category.dto.CategoryRequestDTO; +import com.bbteam.budgetbuddies.domain.category.dto.CategoryResponseDTO; +import com.bbteam.budgetbuddies.domain.category.service.CategoryService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/categories") +public class CategoryController { + + private final CategoryService categoryService; + + @Operation(summary = "카테고리 추가", description = "사용자 임의의 카테고리를 추가합니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) + }) + @PostMapping("/add") + public ResponseEntity createCategory( + @Parameter(description = "user_id, name(사용자가 입력한 카테고리명), is_default(default 카테고리 여부)로 request") + @RequestBody CategoryRequestDTO categoryRequestDTO + ) { + CategoryResponseDTO response = categoryService.createCategory(categoryRequestDTO); + return ResponseEntity.ok(response); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/converter/CategoryConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/converter/CategoryConverter.java new file mode 100644 index 00000000..69069b9d --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/converter/CategoryConverter.java @@ -0,0 +1,28 @@ +package com.bbteam.budgetbuddies.domain.category.converter; + +import com.bbteam.budgetbuddies.domain.category.dto.CategoryRequestDTO; +import com.bbteam.budgetbuddies.domain.category.dto.CategoryResponseDTO; +import com.bbteam.budgetbuddies.domain.category.entity.Category; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import org.springframework.stereotype.Component; + +@Component +public class CategoryConverter { + + public Category toCategoryEntity(CategoryRequestDTO categoryRequestDTO, User user) { + return Category.builder() + .name(categoryRequestDTO.getName()) + .isDefault(categoryRequestDTO.getIsDefault()) + .user(user) + .build(); + } + + public CategoryResponseDTO toCategoryResponseDTO(Category category) { + return CategoryResponseDTO.builder() + .id(category.getId()) + .name(category.getName()) + .userId(category.getUser().getId()) + .isDefault(category.getIsDefault()) + .build(); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/dto/CategoryRequestDTO.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/dto/CategoryRequestDTO.java new file mode 100644 index 00000000..3f8eee35 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/dto/CategoryRequestDTO.java @@ -0,0 +1,12 @@ +package com.bbteam.budgetbuddies.domain.category.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class CategoryRequestDTO { + private Long userId; + private String name; + private Boolean isDefault; +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/dto/CategoryResponseDTO.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/dto/CategoryResponseDTO.java new file mode 100644 index 00000000..41381edb --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/dto/CategoryResponseDTO.java @@ -0,0 +1,14 @@ +package com.bbteam.budgetbuddies.domain.category.dto; + +import com.bbteam.budgetbuddies.domain.user.entity.User; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class CategoryResponseDTO { + private Long id; + private Long userId; + private String name; + private Boolean isDefault; +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/entity/Category.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/entity/Category.java index 366167ef..b25530f3 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/category/entity/Category.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/entity/Category.java @@ -3,9 +3,17 @@ import com.bbteam.budgetbuddies.common.BaseEntity; import com.bbteam.budgetbuddies.domain.user.entity.User; import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; import org.hibernate.annotations.ColumnDefault; @Entity +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder public class Category { @Id diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java new file mode 100644 index 00000000..36528fd7 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java @@ -0,0 +1,10 @@ +package com.bbteam.budgetbuddies.domain.category.repository; + +import com.bbteam.budgetbuddies.domain.category.entity.Category; +import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + +public interface CategoryRepository extends JpaRepository { + Optional findByUserIdAndName(Long userId, String name); +} + diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryService.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryService.java new file mode 100644 index 00000000..352b64c6 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryService.java @@ -0,0 +1,9 @@ +package com.bbteam.budgetbuddies.domain.category.service; + +import com.bbteam.budgetbuddies.domain.category.dto.CategoryRequestDTO; +import com.bbteam.budgetbuddies.domain.category.dto.CategoryResponseDTO; + +public interface CategoryService { + CategoryResponseDTO createCategory(CategoryRequestDTO categoryRequestDTO); +} + diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryServiceImpl.java new file mode 100644 index 00000000..257360aa --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryServiceImpl.java @@ -0,0 +1,39 @@ +package com.bbteam.budgetbuddies.domain.category.service; + +import com.bbteam.budgetbuddies.domain.category.converter.CategoryConverter; +import com.bbteam.budgetbuddies.domain.category.dto.CategoryRequestDTO; +import com.bbteam.budgetbuddies.domain.category.dto.CategoryResponseDTO; +import com.bbteam.budgetbuddies.domain.category.entity.Category; +import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class CategoryServiceImpl implements CategoryService { + + private final CategoryRepository categoryRepository; + private final UserRepository userRepository; + private final CategoryConverter categoryConverter; + + @Override + @Transactional + public CategoryResponseDTO createCategory(CategoryRequestDTO categoryRequestDTO) { + User user = userRepository.findById(categoryRequestDTO.getUserId()) + .orElseThrow(() -> new IllegalArgumentException("cannot find user")); + + categoryRepository.findByUserIdAndName(categoryRequestDTO.getUserId(), categoryRequestDTO.getName()) + .ifPresent(existingCategory -> { + throw new IllegalArgumentException("Category with the same name already exists for this user"); + }); + + Category category = categoryConverter.toCategoryEntity(categoryRequestDTO, user); + Category savedCategory = categoryRepository.save(category); + + return categoryConverter.toCategoryResponseDTO(savedCategory); + } +} 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 new file mode 100644 index 00000000..29fb1c27 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentResponseDto.java @@ -0,0 +1,4 @@ +package com.bbteam.budgetbuddies.domain.comment.dto; + +public class CommentResponseDto { +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/controller/UserController.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/controller/UserController.java new file mode 100644 index 00000000..b14921cd --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/user/controller/UserController.java @@ -0,0 +1,31 @@ +package com.bbteam.budgetbuddies.domain.user.controller; + +import com.bbteam.budgetbuddies.domain.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/users") +public class UserController { + + @Autowired + private UserService userService; + + @PostMapping + public User createUser(@RequestBody User user){ + return userService.createUser(user); + } + + @GetMapping + public List getAllusers() { + return userService.getAllUser(); + } + + @GetMapping("/{id}") + public User getUserById(@PathVariable Long id){ + return userService.getUserById(id); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserService.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserService.java new file mode 100644 index 00000000..6012970d --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserService.java @@ -0,0 +1,27 @@ +package com.bbteam.budgetbuddies.domain.user.service; + +import com.bbteam.budgetbuddies.domain.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class UserService { + + @Autowired + private UserRepository userRepository; + + public User createUser(User user){ + return userRepository.save(user); + } + + public List getAllUser() { + return userRepository.findAll(); + } + + public User getUserById(Long id){ + return userRepository.findById(id).orElse(null); + } +} From 5f9950b08f1ce3f1331a297f49c3d6957ef10f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=9E=AC=ED=98=81?= Date: Fri, 19 Jul 2024 20:31:11 +0900 Subject: [PATCH 014/126] Create gradle.yml --- .github/workflows/gradle.yml | 117 +++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 .github/workflows/gradle.yml diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 00000000..4f1c13a1 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,117 @@ +name: CI/CD + +# 동작 조건 설정: release 브랜치에 push나 pull_request가 발생할 경우 동작한다. +on: + push: + branches: [ "dev" ] + pull_request: + branches: [ "dev" ] + +permissions: + contents: read + +jobs: + CI-CD: + runs-on: ubuntu-latest + steps: + # JDK setting - github actions에서 사용할 JDK 설정 (aws 과 project의 java 버전과 별도로 관리) + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + ## gradle caching (빌드 시간 줄이기) + - name: Gradle Caching + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + # 환경별 yml 파일 생성(1) - dev + - name: make application-dev.yml + if: contains(github.ref, 'develop') + run: | + cd ./src/main/resources + touch ./application.yml + echo "${{ secrets.YML }}" > ./application.yml + shell: bash + + # 환경별 yml 파일 생성(2) - prod + - name: make application-prod.yml + if: contains(github.ref, 'main') + run: | + cd ./src/main/resources + touch ./application.yml + echo "${{ secrets.YML }}" > ./application.yml + shell: bash + + # gradle chmod + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + # gradle build + - name: Build with Gradle + run: ./gradlew clean build -x test + + # docker login + - name: Docker Hub Login + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # docker build & push to production + - name: Docker build & push to prod + if: contains(github.ref, 'main') + run: | + docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }}/binjumeoniz . + docker push ${{ secrets.DOCKER_REPO }}/binjumeoniz + + # docker build & push to develop + - name: Docker build & push to dev + if: contains(github.ref, 'develop') + run: | + docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }}/binjumeoniz . + docker push ${{ secrets.DOCKER_REPO }}/binjumeoniz + + ## deploy to production + - name: Deploy to prod + uses: appleboy/ssh-action@master + id: deploy-prod + if: contains(github.ref, 'main') + with: + host: ${{ secrets.HOST_PROD }} # EC2 퍼블릭 IPv4 DNS + username: ubuntu + key: ${{ secrets.PRIVATE_KEY }} + envs: GITHUB_SHA + script: | + sudo docker ps + sudo docker rm -f $(docker ps -qa) + sudo docker pull ${{ secrets.DOCKER_REPO }}/binjumeoniz + sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_REPO }}/binjumeoniz + sudo docker image prune -f +## ## sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_REPO }}/binjumeoniz + + ## deploy to develop + - name: Deploy to dev + uses: appleboy/ssh-action@master + id: deploy-dev + if: contains(github.ref, 'develop') + with: + host: ${{ secrets.HOST_DEV }} # EC2 퍼블릭 IPv4 DNS + username: ${{ secrets.USERNAME }} # ubuntu + password: ${{ secrets.PASSWORD }} + port: 22 + key: ${{ secrets.PRIVATE_KEY }} + script: | + sudo docker ps + sudo docker rm -f $(docker ps -qa) + sudo docker pull ${{ secrets.DOCKER_REPO }}/binjumeoniz + sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_REPO }}/binjumeoniz + sudo docker image prune -f From 95ae8c1cb8875d0c0f8fb8a8a9b6924e9369e598 Mon Sep 17 00:00:00 2001 From: ggamD00 Date: Fri, 19 Jul 2024 20:34:45 +0900 Subject: [PATCH 015/126] create DockerFile --- DockerFile | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 DockerFile diff --git a/DockerFile b/DockerFile new file mode 100644 index 00000000..b48c1483 --- /dev/null +++ b/DockerFile @@ -0,0 +1,11 @@ +# open jdk 17 버전의 환경을 구성한다. +FROM openjdk:17-alpine + +# build가 될 때 JAR_FILE이라는 변수 명에 build/libs/*.jar 선언 +# build/libs - gradle로 빌드했을 때 jar 파일이 생성되는 경로임 +ARG JAR_FILE=build/libs/*.jar + +# JAR_FILE을 agaproject.jar로 복사 (이 부분(.jar)은 개발환경에 따라 다름) +COPY ${JAR_FILE} app.jar + +ENTRYPOINT ["java", "-jar", "/app.jar"] \ No newline at end of file From dfc027a94af08a1f6cc8e4ee14827cfc8fd7efef Mon Sep 17 00:00:00 2001 From: JunRain Date: Fri, 19 Jul 2024 21:40:29 +0900 Subject: [PATCH 016/126] =?UTF-8?q?[feat]=20CategoryRepository=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=EC=9D=98=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../category/repository/CategoryRepository.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java new file mode 100644 index 00000000..f9511efd --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java @@ -0,0 +1,14 @@ +package com.bbteam.budgetbuddies.domain.category.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import com.bbteam.budgetbuddies.domain.category.entity.Category; + +public interface CategoryRepository extends JpaRepository { + @Query(value = "SELECT c FROM Category AS c WHERE c.isDefault=TRUE OR c.user.id=:id") + List findUserCategoryByUserId(@Param("id") Long id); +} From bd935f7a1f192ccd9852e54e545a31bb2cd176b2 Mon Sep 17 00:00:00 2001 From: JunRain Date: Fri, 19 Jul 2024 21:41:25 +0900 Subject: [PATCH 017/126] =?UTF-8?q?[feat]=20CategoryRepository=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=EC=9D=98=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/CategoryRepositoryTest.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepositoryTest.java diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepositoryTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepositoryTest.java new file mode 100644 index 00000000..f87f8a95 --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepositoryTest.java @@ -0,0 +1,67 @@ +package com.bbteam.budgetbuddies.domain.category.repository; + +import static org.assertj.core.api.Assertions.*; + +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +import com.bbteam.budgetbuddies.domain.category.entity.Category; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; + +@DisplayName("Category 레포지토리 테스트의 ") +@DataJpaTest +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) +class CategoryRepositoryTest { + @Autowired + UserRepository userRepository; + @Autowired + CategoryRepository categoryRepository; + + @Test + @DisplayName("Custom 카테고리와 Base 카테고리 조회 성공") + void findUserCategoryByUserIdTest_Success() { + User user = userRepository.save(User.builder() + .email("email") + .age(24) + .name("name") + .phoneNumber("010-1234-5678") + .build()); + + User otherUser = userRepository.save(User.builder() + .email("email2") + .age(25) + .name("name2") + .phoneNumber("010-2345-5678") + .build()); + + Category defaultCategory = categoryRepository.save(Category.builder() + .name("디폴트 카테고리") + .user(null) + .isDefault(true) + .build()); + + Category userCategory = categoryRepository.save(Category.builder() + .name("유저 카테고리") + .user(user) + .isDefault(false) + .build()); + + categoryRepository.save(Category.builder() + .name("다른 유저 카테고리") + .user(otherUser) + .isDefault(false) + .build()); + + // when + List result = categoryRepository.findUserCategoryByUserId(user.getId()); + + // then + assertThat(result).usingRecursiveComparison().isEqualTo(List.of(defaultCategory, userCategory)); + } +} \ No newline at end of file From d49d7c1f4d1189ff6370d141f88a1efa52e1929e Mon Sep 17 00:00:00 2001 From: MJJ Date: Sat, 20 Jul 2024 12:59:02 +0900 Subject: [PATCH 018/126] =?UTF-8?q?[fix]=20ConsumptionGoal=20Id=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/ConsumptionGoal.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java index 2a630997..70b6b434 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java @@ -1,9 +1,16 @@ package com.bbteam.budgetbuddies.domain.consumptiongoal.entity; +import java.time.LocalDate; + import com.bbteam.budgetbuddies.common.BaseEntity; import com.bbteam.budgetbuddies.domain.category.entity.Category; import com.bbteam.budgetbuddies.domain.user.entity.User; -import jakarta.persistence.*; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; import jakarta.validation.constraints.Min; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -11,8 +18,6 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; -import java.time.LocalDate; - @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -20,27 +25,23 @@ @SuperBuilder public class ConsumptionGoal extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(nullable = false) - @Min(value = 1, message = "0 또는 음수의 목표금액을 설정할 수 없습니다.") - private Long goalAmount; + @Column(nullable = false) + @Min(value = 1, message = "0 또는 음수의 목표금액을 설정할 수 없습니다.") + private Long goalAmount; - @Column(nullable = false) - @Min(value = 1, message = "0 또는 음수의 소비금액을 설정할 수 없습니다.") - private Long consumeAmount; + @Column(nullable = false) + @Min(value = 1, message = "0 또는 음수의 소비금액을 설정할 수 없습니다.") + private Long consumeAmount; - @Column(nullable = false) - private LocalDate goalMonth; + @Column(nullable = false) + private LocalDate goalMonth; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "user_id") - private User user; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "category_id") - private Category category; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "category_id") + private Category category; } From a83cb227757b83283f49b2bcec49011d828d0e30 Mon Sep 17 00:00:00 2001 From: MJJ Date: Sat, 20 Jul 2024 16:59:01 +0900 Subject: [PATCH 019/126] =?UTF-8?q?[feat]=20TopGoalCategoryResponseDTO=20C?= =?UTF-8?q?ategory=20=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumptiongoal/dto/TopGoalCategoryResponseDTO.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopGoalCategoryResponseDTO.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopGoalCategoryResponseDTO.java index 23859cc9..99c394b4 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopGoalCategoryResponseDTO.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopGoalCategoryResponseDTO.java @@ -1,7 +1,5 @@ package com.bbteam.budgetbuddies.domain.consumptiongoal.dto; -import com.bbteam.budgetbuddies.domain.category.entity.Category; - import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -13,7 +11,7 @@ @AllArgsConstructor public class TopGoalCategoryResponseDTO { - private Category category; + private String categoryName; private Long goalAmount; From f7a4327894992c5e7e63807effc2570820423b0e Mon Sep 17 00:00:00 2001 From: MJJ Date: Sat, 20 Jul 2024 17:05:14 +0900 Subject: [PATCH 020/126] =?UTF-8?q?[feat]=20TopCategoryConverter=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/TopCategoryConverter.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopCategoryConverter.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopCategoryConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopCategoryConverter.java new file mode 100644 index 00000000..458d42a5 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopCategoryConverter.java @@ -0,0 +1,21 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.converter; + +import org.springframework.stereotype.Component; + +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; +import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; + +@Component +public class TopCategoryConverter { + + public TopGoalCategoryResponseDTO fromEntity(ConsumptionGoal consumptionGoal) { + if (consumptionGoal == null || consumptionGoal.getCategory() == null) { + return null; + } + + return TopGoalCategoryResponseDTO.builder() + .categoryName(consumptionGoal.getCategory().getName()) + .goalAmount(consumptionGoal.getGoalAmount()) + .build(); + } +} From d33646fbab3269fd32a7d77511b24774c7ade85b Mon Sep 17 00:00:00 2001 From: MJJ Date: Sat, 20 Jul 2024 17:05:45 +0900 Subject: [PATCH 021/126] =?UTF-8?q?[fix]=20=ED=8C=A8=ED=82=A4=EC=A7=80=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/consumptiongoal/controller/package-info.java | 1 - .../budgetbuddies/domain/consumptiongoal/dto/package-info.java | 1 - .../domain/consumptiongoal/repository/package-info.java | 1 - .../domain/consumptiongoal/service/package-info.java | 1 - 4 files changed, 4 deletions(-) delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/package-info.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/package-info.java deleted file mode 100644 index c4780977..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.consumptiongoal.controller; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/package-info.java deleted file mode 100644 index 65ea60a1..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.consumptiongoal.dto; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/package-info.java deleted file mode 100644 index ce8587a8..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.consumptiongoal.repository; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/package-info.java deleted file mode 100644 index 95d9a924..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.consumptiongoal.service; \ No newline at end of file From 6c61564096e3794876831d25fdc6d8bc2ef12911 Mon Sep 17 00:00:00 2001 From: MJJ Date: Sat, 20 Jul 2024 17:06:23 +0900 Subject: [PATCH 022/126] =?UTF-8?q?[feat]=20ConsumptionGoalRepository=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ConsumptionGoalRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java index f338fee5..d42ee716 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java @@ -1,10 +1,18 @@ package com.bbteam.budgetbuddies.domain.consumptiongoal.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; @Repository public interface ConsumptionGoalRepository extends JpaRepository { + + @Query("SELECT cg FROM ConsumptionGoal cg " + + "WHERE cg.category.isDefault = true " + + "ORDER BY cg.goalAmount DESC") + List findTopCategoriesAndGoalAmount(); } \ No newline at end of file From fdcfe8f37cee68109979e7b9225b7f9985356feb Mon Sep 17 00:00:00 2001 From: MJJ Date: Sat, 20 Jul 2024 17:08:21 +0900 Subject: [PATCH 023/126] =?UTF-8?q?[feat]=20Category=20Entity=20Getter=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bbteam/budgetbuddies/domain/category/entity/Category.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/entity/Category.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/entity/Category.java index 366167ef..06c43d53 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/category/entity/Category.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/entity/Category.java @@ -1,11 +1,13 @@ package com.bbteam.budgetbuddies.domain.category.entity; -import com.bbteam.budgetbuddies.common.BaseEntity; import com.bbteam.budgetbuddies.domain.user.entity.User; import jakarta.persistence.*; +import lombok.Getter; + import org.hibernate.annotations.ColumnDefault; @Entity +@Getter public class Category { @Id From b207602c6870c27b71e6415794c5b517bc8e39e1 Mon Sep 17 00:00:00 2001 From: MJJ Date: Sat, 20 Jul 2024 17:12:33 +0900 Subject: [PATCH 024/126] =?UTF-8?q?[feat]=20ConsumptionGoalService=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalService.java | 10 ++++++ .../service/ConsumptionGoalServiceImpl.java | 32 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java new file mode 100644 index 00000000..0cfde5ee --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java @@ -0,0 +1,10 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.service; + +import java.util.List; + +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; + +public interface ConsumptionGoalService { + + List getTopGoalCategories(int top); +} \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java new file mode 100644 index 00000000..f52b3de9 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java @@ -0,0 +1,32 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.service; + +import java.util.List; +import java.util.stream.Collectors; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.TopCategoryConverter; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; +import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; +import com.bbteam.budgetbuddies.domain.consumptiongoal.repository.ConsumptionGoalRepository; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class ConsumptionGoalServiceImpl implements ConsumptionGoalService { + + private final ConsumptionGoalRepository consumptionGoalRepository; + private final TopCategoryConverter topCategoryConverter; + + @Override + @Transactional(readOnly = true) + public List getTopGoalCategories(int top) { + List topGoals = consumptionGoalRepository.findTopCategoriesAndGoalAmount(); + return topGoals.stream() + .limit(top) // 여기서 top 개수만큼 제한 + .map(topCategoryConverter::fromEntity) + .collect(Collectors.toList()); + } +} From f191a2e9290cda079b8fe6927203027e8de5e291 Mon Sep 17 00:00:00 2001 From: MJJ Date: Sat, 20 Jul 2024 17:14:52 +0900 Subject: [PATCH 025/126] =?UTF-8?q?[feat]=20ConsumptionGoalController=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ConsumptionGoalController.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java new file mode 100644 index 00000000..013147b8 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java @@ -0,0 +1,28 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.controller; + +import java.util.List; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; +import com.bbteam.budgetbuddies.domain.consumptiongoal.service.ConsumptionGoalService; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequestMapping +@RequiredArgsConstructor +public class ConsumptionGoalController { + + private final ConsumptionGoalService consumptionGoalService; + + @GetMapping("/consumption-goal/top-categories") + public ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaultValue = "5") int top) { + List topCategory = consumptionGoalService.getTopGoalCategories(top); + return ResponseEntity.ok(topCategory); + } +} \ No newline at end of file From d3bbcb7b9189e992ff2b46882bcfad5d89c00be2 Mon Sep 17 00:00:00 2001 From: MJJ Date: Sat, 20 Jul 2024 20:40:06 +0900 Subject: [PATCH 026/126] =?UTF-8?q?[feat]=20ConsumptionGoalController=20sw?= =?UTF-8?q?agger=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ConsumptionGoalController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java index 013147b8..796f178d 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java @@ -11,6 +11,11 @@ import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.service.ConsumptionGoalService; +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.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import lombok.RequiredArgsConstructor; @RestController @@ -20,6 +25,13 @@ public class ConsumptionGoalController { private final ConsumptionGoalService consumptionGoalService; + @Operation(summary = "또래들이 가장 큰 계획을 세운 카테고리 조회 API", description = "특정 사용자의 소비 목표 카테고리별 소비 목표 금액을 조회하는 API입니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "top", description = "가장 큰 목표를 세운 카테고리의 개수를 지정합니다. (기본값은 5입니다"), + }) @GetMapping("/consumption-goal/top-categories") public ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaultValue = "5") int top) { List topCategory = consumptionGoalService.getTopGoalCategories(top); From c74f7ab22dc0718b252be4f81c6090c056c7d2b8 Mon Sep 17 00:00:00 2001 From: MJJ Date: Sat, 20 Jul 2024 20:40:53 +0900 Subject: [PATCH 027/126] =?UTF-8?q?[fix]=20ConsumptionGoalController=20Map?= =?UTF-8?q?ping=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumptiongoal/controller/ConsumptionGoalController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java index 796f178d..bfbca312 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java @@ -19,8 +19,8 @@ import lombok.RequiredArgsConstructor; @RestController -@RequestMapping @RequiredArgsConstructor +@RequestMapping("/consumption-goal") public class ConsumptionGoalController { private final ConsumptionGoalService consumptionGoalService; @@ -32,7 +32,7 @@ public class ConsumptionGoalController { @Parameters({ @Parameter(name = "top", description = "가장 큰 목표를 세운 카테고리의 개수를 지정합니다. (기본값은 5입니다"), }) - @GetMapping("/consumption-goal/top-categories") + @GetMapping("/top-categories") public ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaultValue = "5") int top) { List topCategory = consumptionGoalService.getTopGoalCategories(top); return ResponseEntity.ok(topCategory); From cede6951a2418703bf270e713028c9b42ad94ba0 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 21 Jul 2024 15:54:46 +0900 Subject: [PATCH 028/126] =?UTF-8?q?[feat]=20=EC=A7=80=EC=9B=90=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20Controller=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - [User] 특정 년월 지원정보 리스트 가져오기 API - [ADMIN] 지원정보 등록하기 API - [User] 특정 지원정보에 좋아요 클릭 API --- .../controller/SupportInfoController.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoController.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoController.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoController.java new file mode 100644 index 00000000..059ae9b6 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoController.java @@ -0,0 +1,86 @@ +package com.bbteam.budgetbuddies.domain.supportinfo.controller; + +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequestDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; +import com.bbteam.budgetbuddies.domain.supportinfo.service.SupportInfoService; +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.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/supports") +public class SupportInfoController { + + private final SupportInfoService supportInfoService; + + @Operation(summary = "[User] 특정 년월 지원정보 리스트 가져오기 API", description = "특정 년도와 월에 해당하는 지원정보 목록을 조회하는 API이며, 페이징을 포함합니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), +// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), +// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), +// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) + }) + @Parameters({ + @Parameter(name = "year", description = "데이터를 가져올 연도입니다."), + @Parameter(name = "month", description = "데이터를 가져올 월입니다."), + @Parameter(name = "page", description = "페이지 번호, 0번이 1 페이지 입니다. (기본값은 0입니다.)"), + @Parameter(name = "size", description = "한 페이지에 불러올 데이터 개수입니다. (기본값은 10개입니다.)") + }) + @GetMapping("") + public ResponseEntity> getSupportsByYearAndMonth( + @RequestParam Integer year, + @RequestParam Integer month, + @RequestParam(defaultValue = "0") Integer page, + @RequestParam(defaultValue = "10") Integer size + ) { + Page supports = supportInfoService.getSupportsByYearAndMonth(year, month, page, size); + + return ResponseEntity.ok(supports); + } + + @Operation(summary = "[ADMIN] 지원정보 등록하기 API", description = "지원정보를 등록하는 API이며, 추후에는 관리자만 접근 가능하도록 할 예정입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), +// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), +// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), +// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) + }) + @PostMapping("") + public ResponseEntity registerDiscountInfo( + @RequestBody SupportRequestDto requestDto + ) { + SupportResponseDto supportResponseDto = supportInfoService.registerSupportInfo(requestDto); + + return ResponseEntity.ok(supportResponseDto); + } + + @Operation(summary = "[User] 특정 지원정보에 좋아요 클릭 API", description = "특정 지원정보에 좋아요 버튼을 클릭하는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), +// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), +// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), +// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) + }) + @Parameters({ + @Parameter(name = "userId", description = "좋아요를 누른 사용자의 id입니다."), + @Parameter(name = "supportInfoId", description = "좋아요를 누를 지원정보의 id입니다."), + }) + @PostMapping("/{supportInfoId}/likes") + public ResponseEntity likeDiscountInfo( + @RequestParam Long userId, + @PathVariable Long supportInfoId + ) { + SupportResponseDto supportResponseDto = supportInfoService.toggleLike(userId, supportInfoId); + + return ResponseEntity.ok(supportResponseDto); + } + +} From 702918849641b0fe791be400a9b5ecaf4981885e Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 21 Jul 2024 15:55:22 +0900 Subject: [PATCH 029/126] =?UTF-8?q?[feat]=20=EC=A7=80=EC=9B=90=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20Service=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/SupportInfoService.java | 20 +++ .../service/SupportInfoServiceImpl.java | 116 ++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoService.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoService.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoService.java new file mode 100644 index 00000000..bc01ebd9 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoService.java @@ -0,0 +1,20 @@ +package com.bbteam.budgetbuddies.domain.supportinfo.service; + +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequestDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; +import org.springframework.data.domain.Page; + +public interface SupportInfoService { + Page getSupportsByYearAndMonth( + Integer year, + Integer month, + Integer page, + Integer size + ); + + SupportResponseDto registerSupportInfo(SupportRequestDto supportRequestDto); + + SupportResponseDto toggleLike(Long userId, Long supportInfoId); +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java new file mode 100644 index 00000000..6f5568f9 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java @@ -0,0 +1,116 @@ +package com.bbteam.budgetbuddies.domain.supportinfo.service; + +import com.bbteam.budgetbuddies.domain.discountinfo.converter.DiscountInfoConverter; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +import com.bbteam.budgetbuddies.domain.discountinfo.repository.DiscountInfoRepository; +import com.bbteam.budgetbuddies.domain.discountinfolike.entity.DiscountInfoLike; +import com.bbteam.budgetbuddies.domain.discountinfolike.repository.DiscountInfoLikeRepository; +import com.bbteam.budgetbuddies.domain.supportinfo.converter.SupportInfoConverter; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequestDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; +import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; +import com.bbteam.budgetbuddies.domain.supportinfo.repository.SupportInfoRepository; +import com.bbteam.budgetbuddies.domain.supportinfolike.entity.SupportInfoLike; +import com.bbteam.budgetbuddies.domain.supportinfolike.repository.SupportInfoLikeRepository; +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.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.util.Optional; + +@Service +@RequiredArgsConstructor +public class SupportInfoServiceImpl implements SupportInfoService { + + private final SupportInfoRepository supportInfoRepository; + + private final SupportInfoLikeRepository supportInfoLikeRepository; + + private final SupportInfoConverter supportInfoConverter; + + private final UserRepository userRepository; + + + @Transactional(readOnly = true) + @Override + public Page getSupportsByYearAndMonth(Integer year, Integer month, Integer page, Integer size) { + /** + * 1. Pageable 객체 생성 (사용자로부터 입력받은 page 번호와 size) + * 2. 사용자가 요청한 년월을 기준으로 해당 년월의 1일로 LocalDate 객체 생성 + * 3. 해당 년월에 겹치는 할인정보 데이터 가져오기 + * 4. Entity 리스트를 -> Dto로 모두 변환하여 리턴 + */ + Pageable pageable = PageRequest.of(page, size); + + LocalDate startDate = LocalDate.of(year, month, 1); + LocalDate endDate = startDate.withDayOfMonth(startDate.lengthOfMonth()); + + Page supportInfoPage = supportInfoRepository.findByDateRange(startDate, endDate, pageable); + + return supportInfoPage.map(supportInfoConverter::toDto); + } + + @Transactional + @Override + public SupportResponseDto registerSupportInfo(SupportRequestDto supportRequestDto) { + /** + * 1. RequestDto -> Entity로 변환 + * 2. Entity 저장 + * 3. Entity -> ResponseDto로 변환 후 리턴 + */ + SupportInfo entity = supportInfoConverter.toEntity(supportRequestDto); + + supportInfoRepository.save(entity); + + return supportInfoConverter.toDto(entity); + } + + @Transactional + @Override + public SupportResponseDto toggleLike(Long userId, Long supportInfoId) { + /** + * 1. 사용자 조회 -> 없으면 에러 + * 2. 할인정보 조회 -> 없으면 에러 + * 3. 사용자가 특정 할인정보에 좋아요를 눌렀는지 확인 (SupportInfoLike 테이블에서 userId로부터 데이터 가져오기) + * 4. 누르지 않은 상태라면, + * 4-1. SupportInfo의 likeCount 1 증가 + * 4-2. SupportInfoLike의 + * 5. 이미 누른 상태라면, + * 5-1. SupportInfo의 likeCount 1 감소 + */ + + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + + SupportInfo supportInfo = supportInfoRepository.findById(supportInfoId) + .orElseThrow(() -> new IllegalArgumentException("SupportInfo not found")); + + Optional existingLike = supportInfoLikeRepository.findByUserAndSupportInfo(user, supportInfo); + + if (existingLike.isPresent()) { + // 이미 좋아요를 누른 상태라면 + supportInfoLikeRepository.delete(existingLike.get()); + supportInfo.subLikeCount(); + } else { + // 아직 좋아요를 누르지 않은 상태라면 + SupportInfoLike newLike = SupportInfoLike.builder() + .user(user) + .supportInfo(supportInfo) + .build(); + supportInfoLikeRepository.save(newLike); + supportInfo.addLikeCount(); + } + + SupportInfo savedEntity = supportInfoRepository.save(supportInfo); + + return supportInfoConverter.toDto(savedEntity); + } +} From ae1c39133d3942c100fe72bb3ab06ee467b0bdcf Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 21 Jul 2024 15:55:43 +0900 Subject: [PATCH 030/126] =?UTF-8?q?[feat]=20=EC=A7=80=EC=9B=90=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20Request,=20ResponseDto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supportinfo/dto/SupportRequestDto.java | 24 +++++++++++++++ .../supportinfo/dto/SupportResponseDto.java | 30 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequestDto.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportResponseDto.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequestDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequestDto.java new file mode 100644 index 00000000..ff883f7d --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequestDto.java @@ -0,0 +1,24 @@ +package com.bbteam.budgetbuddies.domain.supportinfo.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SupportRequestDto { + + private String title; + + private LocalDate startDate; + + private LocalDate endDate; + + private String siteUrl; + +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportResponseDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportResponseDto.java new file mode 100644 index 00000000..b04825f7 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportResponseDto.java @@ -0,0 +1,30 @@ +package com.bbteam.budgetbuddies.domain.supportinfo.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SupportResponseDto { + + private Long id; + + private String title; + + private LocalDate startDate; + + private LocalDate endDate; + + private Integer anonymousNumber; + + private Integer likeCount; + + private String siteUrl; + +} From 7fd3d09c3fa3576f634800254c80ad8197a13ceb Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 21 Jul 2024 15:55:54 +0900 Subject: [PATCH 031/126] =?UTF-8?q?[feat]=20=EC=A7=80=EC=9B=90=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20Repository=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/SupportInfoRepository.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepository.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepository.java new file mode 100644 index 00000000..fa44e97f --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepository.java @@ -0,0 +1,17 @@ +package com.bbteam.budgetbuddies.domain.supportinfo.repository; + +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 java.time.LocalDate; + +public interface SupportInfoRepository extends JpaRepository { + + @Query("SELECT i FROM SupportInfo i WHERE (i.startDate <= :endDate AND i.endDate >= :startDate)") + Page findByDateRange(LocalDate startDate, LocalDate endDate, Pageable pageable); + +} From d8c8728cc51f9dfa049d3118ebc8e6342673d14b Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 21 Jul 2024 15:56:22 +0900 Subject: [PATCH 032/126] =?UTF-8?q?[feat]=20=EC=A7=80=EC=9B=90=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20Converter=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - entity -> responseDto - requestDto -> entity --- .../converter/SupportInfoConverter.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/converter/SupportInfoConverter.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/converter/SupportInfoConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/converter/SupportInfoConverter.java new file mode 100644 index 00000000..8e9bd62f --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/converter/SupportInfoConverter.java @@ -0,0 +1,46 @@ +package com.bbteam.budgetbuddies.domain.supportinfo.converter; + +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequestDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; +import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; +import org.springframework.stereotype.Service; + +@Service +public class SupportInfoConverter { + /** + * @param entity + * @return responseDto + */ + public SupportResponseDto toDto(SupportInfo entity) { + + return SupportResponseDto.builder() + .id(entity.getId()) + .title(entity.getTitle()) + .startDate(entity.getStartDate()) + .endDate(entity.getEndDate()) + .anonymousNumber(entity.getAnonymousNumber()) + .likeCount(entity.getLikeCount()) + .siteUrl(entity.getSiteUrl()) + .build(); + } + + /** + * + * @param requestDto + * @return entity + */ + public SupportInfo toEntity(SupportRequestDto requestDto) { + + return SupportInfo.builder() + .title(requestDto.getTitle()) + .startDate(requestDto.getStartDate()) + .endDate(requestDto.getEndDate()) + .anonymousNumber(0) + .likeCount(0) + .siteUrl(requestDto.getSiteUrl()) + .build(); + } +} From 94faca5a1dd4ae1c2e3677a3fdc0d73873bf2f57 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 21 Jul 2024 15:56:47 +0900 Subject: [PATCH 033/126] =?UTF-8?q?[feat]=20SupportInfoLikeRepository=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/SupportInfoLikeRepository.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/repository/SupportInfoLikeRepository.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/repository/SupportInfoLikeRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/repository/SupportInfoLikeRepository.java new file mode 100644 index 00000000..b2618344 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/repository/SupportInfoLikeRepository.java @@ -0,0 +1,16 @@ +package com.bbteam.budgetbuddies.domain.supportinfolike.repository; + +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +import com.bbteam.budgetbuddies.domain.discountinfolike.entity.DiscountInfoLike; +import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; +import com.bbteam.budgetbuddies.domain.supportinfolike.entity.SupportInfoLike; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface SupportInfoLikeRepository extends JpaRepository { + + Optional findByUserAndSupportInfo(User user, SupportInfo supportInfo); + +} From 3abebd4e5e073b07a575f05b32c78c7e325e3db4 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 21 Jul 2024 15:59:02 +0900 Subject: [PATCH 034/126] =?UTF-8?q?[feat]=20Supportinfo=20Entity=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - likeCount 0으로 초기화 - addLikeCount(), subLikeCount() 메소드 추가 - anonymousNumber 필드 추가 --- .../domain/supportinfo/entity/SupportInfo.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 78ffa7ca..aaa651e0 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 @@ -27,9 +27,20 @@ public class SupportInfo extends BaseEntity { private LocalDate endDate; @ColumnDefault("0") - private Integer likeCount; + private Integer likeCount = 0; + + @ColumnDefault("0") + private Integer anonymousNumber = 0; @Column(length = 1000) private String siteUrl; + public void addLikeCount() { + this.likeCount++; + } + + public void subLikeCount() { + this.likeCount--; + } + } From f9d87b7568055cd9f856244a93cf44743f35ca75 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 21 Jul 2024 15:59:27 +0900 Subject: [PATCH 035/126] =?UTF-8?q?[feat]=20package-info.java=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 --- .../domain/supportinfo/controller/package-info.java | 1 - .../budgetbuddies/domain/supportinfo/dto/package-info.java | 1 - .../domain/supportinfo/repository/package-info.java | 1 - .../budgetbuddies/domain/supportinfo/service/package-info.java | 1 - 4 files changed, 4 deletions(-) delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/package-info.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/package-info.java deleted file mode 100644 index a4bccaf4..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.supportinfo.controller; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/package-info.java deleted file mode 100644 index 7137c5b3..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.supportinfo.dto; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/package-info.java deleted file mode 100644 index 8a76d616..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.supportinfo.repository; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/package-info.java deleted file mode 100644 index ceaba27e..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.supportinfo.service; \ No newline at end of file From 2d813734ce7b205802c8abc66952fc37569d0d1b Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Sun, 21 Jul 2024 16:05:17 +0900 Subject: [PATCH 036/126] =?UTF-8?q?[feat]=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=B6=94=EA=B0=80=20API?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CategoryController.java | 2 +- .../category/controller/package-info.java | 1 - .../domain/category/dto/package-info.java | 1 - .../repository/CategoryRepository.java | 3 +- .../category/repository/package-info.java | 1 - .../category/service/CategoryServiceImpl.java | 13 ++++---- .../domain/category/service/package-info.java | 1 - .../user/controller/UserController.java | 31 ------------------- .../domain/user/service/UserService.java | 27 ---------------- 9 files changed, 8 insertions(+), 72 deletions(-) delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/controller/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/dto/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/repository/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/service/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/controller/UserController.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserService.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/controller/CategoryController.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/controller/CategoryController.java index fc866203..beb16f89 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/category/controller/CategoryController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/controller/CategoryController.java @@ -20,7 +20,7 @@ public class CategoryController { private final CategoryService categoryService; - @Operation(summary = "카테고리 추가", description = "사용자 임의의 카테고리를 추가합니다.") + @Operation(summary = "카테고리 추가", description = "사용자가 직접 카테고리를 추가합니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/controller/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/controller/package-info.java deleted file mode 100644 index 3ed2cb13..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/category/controller/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.category.controller; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/dto/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/dto/package-info.java deleted file mode 100644 index 54a5f6c4..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/category/dto/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.category.dto; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java index 36528fd7..009926c7 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/CategoryRepository.java @@ -2,9 +2,8 @@ import com.bbteam.budgetbuddies.domain.category.entity.Category; import org.springframework.data.jpa.repository.JpaRepository; -import java.util.Optional; public interface CategoryRepository extends JpaRepository { - Optional findByUserIdAndName(Long userId, String name); + boolean existsByUserIdAndName(Long userId, String name); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/package-info.java deleted file mode 100644 index 995bc7a0..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.category.repository; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryServiceImpl.java index 257360aa..52b26658 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryServiceImpl.java @@ -13,7 +13,7 @@ @Service @RequiredArgsConstructor -@Transactional(readOnly = true) +@Transactional public class CategoryServiceImpl implements CategoryService { private final CategoryRepository categoryRepository; @@ -21,19 +21,18 @@ public class CategoryServiceImpl implements CategoryService { private final CategoryConverter categoryConverter; @Override - @Transactional public CategoryResponseDTO createCategory(CategoryRequestDTO categoryRequestDTO) { User user = userRepository.findById(categoryRequestDTO.getUserId()) .orElseThrow(() -> new IllegalArgumentException("cannot find user")); - categoryRepository.findByUserIdAndName(categoryRequestDTO.getUserId(), categoryRequestDTO.getName()) - .ifPresent(existingCategory -> { - throw new IllegalArgumentException("Category with the same name already exists for this user"); - }); + if (categoryRepository.existsByUserIdAndName(categoryRequestDTO.getUserId(), categoryRequestDTO.getName())) { + throw new IllegalArgumentException("User already has a category with the same name"); + } + Category category = categoryConverter.toCategoryEntity(categoryRequestDTO, user); Category savedCategory = categoryRepository.save(category); return categoryConverter.toCategoryResponseDTO(savedCategory); } -} +} \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/service/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/service/package-info.java deleted file mode 100644 index 69cdabf3..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/category/service/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.category.service; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/controller/UserController.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/controller/UserController.java deleted file mode 100644 index b14921cd..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/user/controller/UserController.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.bbteam.budgetbuddies.domain.user.controller; - -import com.bbteam.budgetbuddies.domain.user.entity.User; -import com.bbteam.budgetbuddies.domain.user.service.UserService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequestMapping("/api/users") -public class UserController { - - @Autowired - private UserService userService; - - @PostMapping - public User createUser(@RequestBody User user){ - return userService.createUser(user); - } - - @GetMapping - public List getAllusers() { - return userService.getAllUser(); - } - - @GetMapping("/{id}") - public User getUserById(@PathVariable Long id){ - return userService.getUserById(id); - } -} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserService.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserService.java deleted file mode 100644 index 6012970d..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserService.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.bbteam.budgetbuddies.domain.user.service; - -import com.bbteam.budgetbuddies.domain.user.entity.User; -import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -public class UserService { - - @Autowired - private UserRepository userRepository; - - public User createUser(User user){ - return userRepository.save(user); - } - - public List getAllUser() { - return userRepository.findAll(); - } - - public User getUserById(Long id){ - return userRepository.findById(id).orElse(null); - } -} From 4834129672ee832c7ac72316ea1a28649d2c3968 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Sun, 21 Jul 2024 18:14:29 +0900 Subject: [PATCH 037/126] =?UTF-8?q?[fix]=20CommentController=20URL=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/CommentController.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 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 5ef52bb3..adc42780 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 @@ -15,7 +15,6 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/comments") public class CommentController { private final CommentService commentService; @@ -31,7 +30,7 @@ public class CommentController { @Parameter(name = "discountInfoId", description = "댓글을 다는 할인 정보 게시글 id입니다."), @Parameter(name = "content", description = "댓글 내용입니다."), }) - @PostMapping("/discounts/{userId}/add") + @PostMapping("/discounts/comments/{userId}/add") public ResponseEntity saveDiscountInfoComment( @RequestParam("userId") Long userId, @RequestBody CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto){ @@ -46,7 +45,7 @@ public ResponseEntity saveDiscountInf @Parameters({ @Parameter(name = "discountInfoId", description = "댓글을 가져올 할인 정보 게시글 id입니다."), }) - @GetMapping("/discounts/get/{discountInfoId}") + @GetMapping("/discounts/comments/get/{discountInfoId}") public ResponseEntity> findAllByDiscountInfo( @RequestParam("discountInfoId") Long discountInfoId){ List result = commentService.findByDiscountInfo(discountInfoId); @@ -62,7 +61,7 @@ public ResponseEntity> findAllBy @Parameter(name = "supportInfoId", description = "댓글을 다는 지원 정보 게시글 id입니다."), @Parameter(name = "content", description = "댓글 내용입니다."), }) - @PostMapping("/supports/{userId}/add") + @PostMapping("/supports/comments/{userId}/add") public ResponseEntity saveSupportInfoComment( @RequestParam("userId") Long userId, @RequestBody CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto){ @@ -77,7 +76,7 @@ public ResponseEntity saveSupportInfoC @Parameters({ @Parameter(name = "supportInfoId", description = "댓글을 가져올 지원 정보 게시글 id입니다."), }) - @GetMapping("/supports/get/{supportInfoId}") + @GetMapping("/supports/comments/get/{supportInfoId}") public ResponseEntity> findAllBySupportInfo( @RequestParam("supportInfoId") Long supportInfoId){ List result = commentService.findBySupportInfo(supportInfoId); From 6492f095cb30b9b2851f078fa56ceb7cc216d5e3 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Sun, 21 Jul 2024 18:21:10 +0900 Subject: [PATCH 038/126] =?UTF-8?q?[refactor]=20comment=20package=20?= =?UTF-8?q?=EB=82=B4=EB=B6=80=20package-info=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../budgetbuddies/domain/comment/controller/package-info.java | 1 - .../bbteam/budgetbuddies/domain/comment/dto/package-info.java | 1 - .../budgetbuddies/domain/comment/repository/package-info.java | 1 - .../budgetbuddies/domain/comment/service/package-info.java | 1 - 4 files changed, 4 deletions(-) delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/package-info.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/package-info.java deleted file mode 100644 index 6a816c5b..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.comment.controller; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/package-info.java deleted file mode 100644 index da2cf08a..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.comment.dto; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/package-info.java deleted file mode 100644 index 4d31a705..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.comment.repository; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/package-info.java deleted file mode 100644 index 4ffc9ed9..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.comment.service; \ No newline at end of file From a68b7b87fb484249e231c50ab247345c1140608f Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Sun, 21 Jul 2024 18:27:37 +0900 Subject: [PATCH 039/126] =?UTF-8?q?[refactor]=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20setter=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../budgetbuddies/domain/comment/dto/CommentRequestDto.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentRequestDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentRequestDto.java index c5488bff..45b91e8e 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentRequestDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/CommentRequestDto.java @@ -6,7 +6,6 @@ public class CommentRequestDto { - @Setter @Getter @Builder public static class DiscountInfoCommentDto { @@ -14,7 +13,6 @@ public static class DiscountInfoCommentDto { private Long discountInfoId; } - @Setter @Getter @Builder public static class SupportInfoCommentDto { From d25409379ac6b43ae9ac53d5717dcfdda44ad3ae Mon Sep 17 00:00:00 2001 From: MJJ Date: Sun, 21 Jul 2024 18:59:08 +0900 Subject: [PATCH 040/126] =?UTF-8?q?[fix]=20ConsumptionGoalController=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20peerAge,=20Gender=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ConsumptionGoalController.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java index bfbca312..68ee01b2 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java @@ -25,16 +25,17 @@ public class ConsumptionGoalController { private final ConsumptionGoalService consumptionGoalService; - @Operation(summary = "또래들이 가장 큰 계획을 세운 카테고리 조회 API", description = "특정 사용자의 소비 목표 카테고리별 소비 목표 금액을 조회하는 API입니다.") - @ApiResponses(value = { - @ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), - }) - @Parameters({ - @Parameter(name = "top", description = "가장 큰 목표를 세운 카테고리의 개수를 지정합니다. (기본값은 5입니다"), - }) + @Operation(summary = "또래들이 가장 큰 계획을 세운 카테고리 조회 API", description = "특정 사용자의 소비 목표 카테고리별 소비 목표 금액을 조회하는 API 입니다.") + @ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")}) + @Parameters({@Parameter(name = "top", description = "가장 큰 목표를 세운 카테고리의 개수를 지정합니다. (기본값은 5입니다")}) @GetMapping("/top-categories") - public ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaultValue = "5") int top) { - List topCategory = consumptionGoalService.getTopGoalCategories(top); + public ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaultValue = "5") int top, + @RequestParam(name = "userId") Long userId, + @RequestParam(name = "peerAgeStart", defaultValue = "0") int peerAgeStart, + @RequestParam(name = "peerAgeEnd", defaultValue = "0") int peerAgeEnd, + @RequestParam(name = "peerGender", defaultValue = "none") String peerGender) { + List topCategory = consumptionGoalService.getTopGoalCategories(top, userId, + peerAgeStart, peerAgeEnd, peerGender); return ResponseEntity.ok(topCategory); } } \ No newline at end of file From f8aa657a4d7ad612f3e0a01cbbbe2a74e231a1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=B1=EC=95=84?= Date: Sun, 21 Jul 2024 19:25:28 +0900 Subject: [PATCH 041/126] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 580d57db..a4b2469e 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@
# 빈주머니즈_Spring - +![빈주머니즈_커버_대지 1 사본](https://github.com/user-attachments/assets/744ef4c6-87cd-4db9-9c0b-f848231a203c) ![Java](https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white) ![MySQL](https://img.shields.io/badge/mysql-4479A1.svg?style=for-the-badge&logo=mysql&logoColor=white) ![IntelliJ IDEA](https://img.shields.io/badge/IntelliJIDEA-000000.svg?style=for-the-badge&logo=intellij-idea&logoColor=white) ![Postman](https://img.shields.io/badge/Postman-FF6C37?style=for-the-badge&logo=postman&logoColor=white) + + ## Team ||||||| |:-:|:-:|:-:|:-:|:-:|:-:| From 583f26d94e6553a1e4ae0029a4ce53cee56a8cfc Mon Sep 17 00:00:00 2001 From: MJJ Date: Sun, 21 Jul 2024 19:01:30 +0900 Subject: [PATCH 042/126] =?UTF-8?q?[fix]=20ConsumptionGoalRepository=20pee?= =?UTF-8?q?rAge,=20peerGender=EB=A1=9C=20=ED=95=84=ED=84=B0=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 --- .../repository/ConsumptionGoalRepository.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java index d42ee716..cc0ee32a 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java @@ -4,15 +4,22 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; +import com.bbteam.budgetbuddies.enums.Gender; @Repository public interface ConsumptionGoalRepository extends JpaRepository { - @Query("SELECT cg FROM ConsumptionGoal cg " + - "WHERE cg.category.isDefault = true " + - "ORDER BY cg.goalAmount DESC") - List findTopCategoriesAndGoalAmount(); + @Query("SELECT cg FROM ConsumptionGoal cg " + + "WHERE cg.category.isDefault = true " + + "AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " + + "AND cg.user.gender = :peerGender " + + "ORDER BY cg.goalAmount DESC") + List findTopCategoriesAndGoalAmount( + @Param("peerAgeStart") int peerAgeStart, + @Param("peerAgeEnd") int peerAgeEnd, + @Param("peerGender") Gender peerGender); } \ No newline at end of file From 1b12f123bb7f61866fd19ca6f8362690095b9a1e Mon Sep 17 00:00:00 2001 From: MJJ Date: Sun, 21 Jul 2024 19:26:14 +0900 Subject: [PATCH 043/126] =?UTF-8?q?[fix]=20ConsumptionGoalService=20@Servi?= =?UTF-8?q?ce=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumptiongoal/service/ConsumptionGoalService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java index 0cfde5ee..becbb85d 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java @@ -2,9 +2,13 @@ import java.util.List; +import org.springframework.stereotype.Service; + import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; +@Service public interface ConsumptionGoalService { - List getTopGoalCategories(int top); + List getTopGoalCategories(int top, Long userId, int peerAgeStart, int peerAgeEnd, + String peerGender); } \ No newline at end of file From 021ccf940a520caa2603eab762327690f033e5ae Mon Sep 17 00:00:00 2001 From: MJJ Date: Sun, 21 Jul 2024 19:26:57 +0900 Subject: [PATCH 044/126] =?UTF-8?q?[feat]=20UserRepository=20findById=20Op?= =?UTF-8?q?tional=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/repository/UserRepository.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/repository/UserRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/repository/UserRepository.java index 3495835a..f932a14e 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/user/repository/UserRepository.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/user/repository/UserRepository.java @@ -1,8 +1,13 @@ package com.bbteam.budgetbuddies.domain.user.repository; -import com.bbteam.budgetbuddies.domain.user.entity.User; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; +import com.bbteam.budgetbuddies.domain.user.entity.User; + public interface UserRepository extends JpaRepository { + Optional findById(Long userId); + } From 6e6fbc42cd6228af8235cf67dad5003c44d9bd7c Mon Sep 17 00:00:00 2001 From: MJJ Date: Sun, 21 Jul 2024 19:30:11 +0900 Subject: [PATCH 045/126] =?UTF-8?q?[fix]=20ConsumptionGoalServiceImpl=20Re?= =?UTF-8?q?quest=EB=A1=9C=20=EB=98=90=EB=9E=98=20=EC=8B=9C=EC=9E=91=20?= =?UTF-8?q?=EB=82=98=EC=9D=B4=EC=99=80=20=EB=81=9D=20=EB=82=98=EC=9D=B4,?= =?UTF-8?q?=20=EC=84=B1=EB=B3=84=20=EB=B0=9B=EC=95=84=EC=84=9C=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalServiceImpl.java | 64 +++++++++++++++++-- 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java index f52b3de9..86add557 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java @@ -1,6 +1,8 @@ package com.bbteam.budgetbuddies.domain.consumptiongoal.service; import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; import java.util.stream.Collectors; import org.springframework.stereotype.Service; @@ -10,23 +12,73 @@ import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; import com.bbteam.budgetbuddies.domain.consumptiongoal.repository.ConsumptionGoalRepository; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; +import com.bbteam.budgetbuddies.enums.Gender; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Service @RequiredArgsConstructor public class ConsumptionGoalServiceImpl implements ConsumptionGoalService { private final ConsumptionGoalRepository consumptionGoalRepository; private final TopCategoryConverter topCategoryConverter; + private final UserRepository userRepository; + + private int peerAgeStartByUser; + private int peerAgeEndByUser; @Override @Transactional(readOnly = true) - public List getTopGoalCategories(int top) { - List topGoals = consumptionGoalRepository.findTopCategoriesAndGoalAmount(); - return topGoals.stream() - .limit(top) // 여기서 top 개수만큼 제한 - .map(topCategoryConverter::fromEntity) - .collect(Collectors.toList()); + public List getTopGoalCategories(int top, Long userId, int peerAgeStart, + int peerAgeEnd, + String peerGender) { + + Gender gender = convertToGender(peerGender); + + Optional user = userRepository.findById(userId); + + if (user.isEmpty()) { + throw new NoSuchElementException("유저를 찾을 수 없습니다."); + } + + if (peerAgeStart == 0 || peerAgeEnd == 0 || gender == Gender.NONE) { + + gender = user.get().getGender(); + setAgeGroupByUser(user.get().getAge()); + + } + + List topGoals = consumptionGoalRepository.findTopCategoriesAndGoalAmount(peerAgeStartByUser, + peerAgeEndByUser, gender); + return topGoals.stream().limit(top) // 여기서 top 개수만큼 제한 + .map(topCategoryConverter::fromEntity).collect(Collectors.toList()); + } + + private Gender convertToGender(String genderString) { + try { + return Gender.valueOf(genderString.toUpperCase()); + } catch (IllegalArgumentException e) { + return Gender.NONE; // default or invalid value + } + } + + private void setAgeGroupByUser(int userAge) { + if (userAge >= 20 && userAge <= 22) { + peerAgeStartByUser = 20; + peerAgeEndByUser = 22; + } else if (userAge >= 23 && userAge <= 25) { + peerAgeStartByUser = 23; + peerAgeEndByUser = 25; + } else if (userAge >= 26 && userAge <= 28) { + peerAgeStartByUser = 26; + peerAgeEndByUser = 28; + } else if (userAge >= 29) { + peerAgeStartByUser = 29; + peerAgeEndByUser = 100; + } } } From b478fb96a29ec36a25ab0706012ea24040945ef6 Mon Sep 17 00:00:00 2001 From: MJJ Date: Sun, 21 Jul 2024 21:26:47 +0900 Subject: [PATCH 046/126] =?UTF-8?q?[fix]=20ConsumptionGoalController=20swa?= =?UTF-8?q?gger=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumptiongoal/controller/ConsumptionGoalController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java index 68ee01b2..180a6b37 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java @@ -27,7 +27,7 @@ public class ConsumptionGoalController { @Operation(summary = "또래들이 가장 큰 계획을 세운 카테고리 조회 API", description = "특정 사용자의 소비 목표 카테고리별 소비 목표 금액을 조회하는 API 입니다.") @ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")}) - @Parameters({@Parameter(name = "top", description = "가장 큰 목표를 세운 카테고리의 개수를 지정합니다. (기본값은 5입니다")}) + @Parameters({@Parameter(name = "top", description = "가장 큰 목표를 세운 카테고리의 개수를 지정합니다. (기본값은 5입니다)")}) @GetMapping("/top-categories") public ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaultValue = "5") int top, @RequestParam(name = "userId") Long userId, From e7da3b59fe5c8b2bbf51e4b1b06d437e1e315589 Mon Sep 17 00:00:00 2001 From: JunRain Date: Sun, 21 Jul 2024 23:58:53 +0900 Subject: [PATCH 047/126] =?UTF-8?q?[feat]=20ConsumptionGoal=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20DTO=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/package-info.java | 1 - .../dto/ConsumptionGoalResponseDto.java | 49 +++++++++++++++++++ .../dto/ConsumptionGoalResponseListDto.java | 17 +++++++ .../consumptiongoal/dto/package-info.java | 1 - .../repository/package-info.java | 1 - .../consumptiongoal/service/package-info.java | 1 - 6 files changed, 66 insertions(+), 4 deletions(-) delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseDto.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseListDto.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/package-info.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/package-info.java deleted file mode 100644 index c4780977..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.consumptiongoal.controller; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseDto.java new file mode 100644 index 00000000..304e83a5 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseDto.java @@ -0,0 +1,49 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.dto; + +import java.time.LocalDate; + +import com.bbteam.budgetbuddies.domain.category.entity.Category; +import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; + +import lombok.Builder; +import lombok.Getter; + +@Getter +public class ConsumptionGoalResponseDto { + private String categoryName; + private Long categoryId; + private Long goalAmount; + private Long consumeAmount; + private LocalDate goalMonth; + + @Builder + public ConsumptionGoalResponseDto(String categoryName, Long categoryId, Long goalAmount, Long consumeAmount, + LocalDate goalMonth) { + this.categoryName = categoryName; + this.categoryId = categoryId; + this.goalAmount = goalAmount; + this.consumeAmount = consumeAmount; + this.goalMonth = goalMonth; + } + + public static ConsumptionGoalResponseDto initializeFromCategoryAndGoalMonth(Category category, + LocalDate goalMonth) { + return ConsumptionGoalResponseDto.builder() + .categoryName(category.getName()) + .categoryId(category.getId()) + .goalAmount(0L) + .consumeAmount(0L) + .goalMonth(goalMonth) + .build(); + } + + public static ConsumptionGoalResponseDto of(ConsumptionGoal consumptionGoal) { + return ConsumptionGoalResponseDto.builder() + .categoryName(consumptionGoal.getCategory().getName()) + .categoryId(consumptionGoal.getCategory().getId()) + .goalAmount(consumptionGoal.getGoalAmount()) + .consumeAmount(consumptionGoal.getConsumeAmount()) + .goalMonth(consumptionGoal.getGoalMonth()) + .build(); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseListDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseListDto.java new file mode 100644 index 00000000..87ff4015 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseListDto.java @@ -0,0 +1,17 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.dto; + +import java.util.List; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ConsumptionGoalResponseListDto { + private List consumptionGoalResponseDtoList; + + public ConsumptionGoalResponseListDto(List consumptionGoalResponseDtoList) { + this.consumptionGoalResponseDtoList = consumptionGoalResponseDtoList; + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/package-info.java deleted file mode 100644 index 65ea60a1..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.consumptiongoal.dto; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/package-info.java deleted file mode 100644 index ce8587a8..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.consumptiongoal.repository; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/package-info.java deleted file mode 100644 index 95d9a924..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.consumptiongoal.service; \ No newline at end of file From 900a04f3a6c0b7d79cd973d7096563bb2636773d Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 22 Jul 2024 00:00:20 +0900 Subject: [PATCH 048/126] =?UTF-8?q?[feat]=20ConsumptionGoalRepository=20?= =?UTF-8?q?=EB=AA=A9=ED=91=9C=20=EB=8B=AC=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=86=8C=EB=B9=84=20=EB=AA=A9=ED=91=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ConsumptionGoalRepository.java | 14 +++ .../ConsumptionGoalRepositoryTest.java | 109 ++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java create mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepositoryTest.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java new file mode 100644 index 00000000..dfb4e957 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java @@ -0,0 +1,14 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.repository; + +import java.time.LocalDate; +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; + +public interface ConsumptionGoalRepository extends JpaRepository { + @Query(value = "SELECT cg FROM ConsumptionGoal AS cg WHERE cg.user.id = :userId AND cg.goalMonth = :goalMonth") + List findConsumptionGoalByUserIdAndGoalMonth(Long userId, LocalDate goalMonth); +} diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepositoryTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepositoryTest.java new file mode 100644 index 00000000..4bd1bec1 --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepositoryTest.java @@ -0,0 +1,109 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.repository; + +import static org.assertj.core.api.Assertions.*; + +import java.time.LocalDate; +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +import com.bbteam.budgetbuddies.domain.category.entity.Category; +import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; +import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; + +@DisplayName("ConsumptionGoal 레포지토리 테스트의 ") +@DataJpaTest +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) +class ConsumptionGoalRepositoryTest { + @Autowired + ConsumptionGoalRepository consumptionGoalRepository; + @Autowired + UserRepository userRepository; + @Autowired + CategoryRepository categoryRepository; + + @Test + @DisplayName("유저 아이디와 LocalDate를 통해 GoalConsumption 조회 성공") + void findConsumptionGoalByUserIdAndGoalMonth_Success() { + LocalDate goalMonth = LocalDate.of(2024, 07, 01); + + User user = userRepository.save(User.builder() + .email("email") + .age(24) + .name("name") + .phoneNumber("010-1234-5678") + .build()); + + User otherUser = userRepository.save(User.builder() + .email("email2") + .age(24) + .name("name2") + .phoneNumber("010-1567-5678") + .build()); + + Category defaultCategory = categoryRepository.save(Category.builder() + .name("디폴트 카테고리") + .user(null) + .isDefault(true) + .build()); + + Category userCategory = categoryRepository.save(Category.builder() + .name("유저 카테고리") + .user(user) + .isDefault(false) + .build()); + + ConsumptionGoal defaultCategoryConsumptionGoal = consumptionGoalRepository.save( + ConsumptionGoal.builder() + .goalAmount(1L) + .consumeAmount(1L) + .user(user) + .goalMonth(goalMonth) + .category(defaultCategory) + .build() + ); + + ConsumptionGoal customCategoryConsumptionGoal = consumptionGoalRepository.save( + ConsumptionGoal.builder() + .goalAmount(1L) + .consumeAmount(1L) + .user(user) + .goalMonth(goalMonth) + .category(userCategory) + .build() + ); + + consumptionGoalRepository.save( + ConsumptionGoal.builder() + .goalAmount(1L) + .consumeAmount(1L) + .user(user) + .goalMonth(goalMonth.minusMonths(1)) + .category(defaultCategory) + .build() + ); + + consumptionGoalRepository.save( + ConsumptionGoal.builder() + .goalAmount(1L) + .consumeAmount(1L) + .user(otherUser) + .goalMonth(goalMonth) + .category(defaultCategory) + .build() + ); + + List result = consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(user.getId(), + goalMonth); + + assertThat(result).usingRecursiveComparison() + .isEqualTo( + List.of(defaultCategoryConsumptionGoal, customCategoryConsumptionGoal)); + } +} \ No newline at end of file From 43fea74e145c69d1417ff7cd07d9ed02203911d5 Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 22 Jul 2024 00:01:57 +0900 Subject: [PATCH 049/126] =?UTF-8?q?[feat]=20ConsumptionGoalService=20?= =?UTF-8?q?=EB=AA=A9=ED=91=9C=20=EB=8B=AC=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=86=8C=EB=B9=84=20=EB=AA=A9=ED=91=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalService.java | 50 +++++++ .../service/ConsumptionGoalServiceTest.java | 125 ++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java create mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java new file mode 100644 index 00000000..8c322e3c --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java @@ -0,0 +1,50 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.service; + +import java.time.LocalDate; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.springframework.stereotype.Service; + +import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseDto; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; +import com.bbteam.budgetbuddies.domain.consumptiongoal.repository.ConsumptionGoalRepository; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class ConsumptionGoalService { + private final ConsumptionGoalRepository consumptionGoalRepository; + private final CategoryRepository categoryRepository; + + public ConsumptionGoalResponseListDto findUserConsumptionGoal(Long userId, LocalDate localDate) { + final LocalDate goalMonth = LocalDate.of(localDate.getYear(), localDate.getMonth(), 1); + + Map consumptionGoalResponseDtoMap = categoryRepository + .findUserCategoryByUserId(userId) + .stream() + .map(c -> ConsumptionGoalResponseDto.initializeFromCategoryAndGoalMonth(c, goalMonth)) + .collect(Collectors.toMap(ConsumptionGoalResponseDto::getCategoryId, c -> c)); + + List lastMonthConsumptionGoalList = consumptionGoalRepository + .findConsumptionGoalByUserIdAndGoalMonth(userId, goalMonth.minusMonths(1)) + .stream().map(ConsumptionGoalResponseDto::of).toList(); + + for (ConsumptionGoalResponseDto cgd : lastMonthConsumptionGoalList) { + consumptionGoalResponseDtoMap.put(cgd.getCategoryId(), cgd); + } + + List consumptionGoalList = consumptionGoalRepository + .findConsumptionGoalByUserIdAndGoalMonth(userId, goalMonth) + .stream().map(ConsumptionGoalResponseDto::of).toList(); + + for (ConsumptionGoalResponseDto cgd : consumptionGoalList) { + consumptionGoalResponseDtoMap.put(cgd.getCategoryId(), cgd); + } + + return new ConsumptionGoalResponseListDto(consumptionGoalResponseDtoMap.values().stream().toList()); + } +} diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java new file mode 100644 index 00000000..350cf441 --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java @@ -0,0 +1,125 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.service; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.BDDMockito.*; + +import java.time.LocalDate; +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.bbteam.budgetbuddies.domain.category.entity.Category; +import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseDto; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; +import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; +import com.bbteam.budgetbuddies.domain.consumptiongoal.repository.ConsumptionGoalRepository; +import com.bbteam.budgetbuddies.domain.user.entity.User; + +// TODO 꺠끗하게 작성하기; +@DisplayName("ConsumptionGoal 테스트의 ") +@ExtendWith(MockitoExtension.class) +class ConsumptionGoalServiceTest { + @InjectMocks + private ConsumptionGoalService consumptionGoalService; + + @Mock + private CategoryRepository categoryRepository; + @Mock + private ConsumptionGoalRepository consumptionGoalRepository; + + @Test + @DisplayName("findUserConsumptionGoal 성공") + void findUserConsumptionGoal_success() { + LocalDate goalMonth = LocalDate.of(2024, 07, 01); + + User user = Mockito.spy(User.builder() + .email("email") + .age(24) + .name("name") + .phoneNumber("010-1234-5678") + .build()); + given(user.getId()).willReturn(-1L); + + Category defaultCategory = Mockito.spy(Category.builder() + .name("디폴트 카테고리") + .user(null) + .isDefault(true) + .build()); + given(defaultCategory.getId()).willReturn(-1L); + + Category userCategory = Mockito.spy(Category.builder() + .name("유저 카테고리") + .user(user) + .isDefault(false) + .build()); + given(userCategory.getId()).willReturn(-2L); + + Category userCategory2 = Mockito.spy(Category.builder() + .name("유저 카테고리2") + .user(user) + .isDefault(false) + .build()); + given(userCategory2.getId()).willReturn(-3L); + + Category userCategory3 = Mockito.spy(Category.builder() + .name("유저 카테고리3") + .user(user) + .isDefault(false) + .build()); + given(userCategory3.getId()).willReturn(-4L); + + given(categoryRepository.findUserCategoryByUserId(user.getId())) + .willReturn(List.of(defaultCategory, userCategory, userCategory2, userCategory3)); + + // default + ConsumptionGoal consumptionGoal1 = ConsumptionGoal.builder() + .goalAmount(1L) + .consumeAmount(1L) + .user(user) + .category(defaultCategory) + .goalMonth(goalMonth) + .build(); + + // custom + ConsumptionGoal consumptionGoal2 = ConsumptionGoal.builder() + .goalAmount(1L) + .consumeAmount(1L) + .user(user) + .category(userCategory2) + .goalMonth(goalMonth) + .build(); + + // 1달 전 + ConsumptionGoal consumptionGoal3 = ConsumptionGoal.builder() + .goalAmount(1L) + .consumeAmount(1L) + .user(user) + .category(userCategory2) + .goalMonth(goalMonth.withMonth(1)) + .build(); + + given(consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(user.getId(), goalMonth)).willReturn( + List.of(consumptionGoal1, consumptionGoal2)); + + given(consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(user.getId(), goalMonth.minusMonths(1))) + .willReturn(List.of(consumptionGoal3)); + + List expected = List.of( + ConsumptionGoalResponseDto.of(consumptionGoal1), // default + ConsumptionGoalResponseDto.initializeFromCategoryAndGoalMonth(userCategory, goalMonth), // 1 + ConsumptionGoalResponseDto.of(consumptionGoal2), // 2 + ConsumptionGoalResponseDto.initializeFromCategoryAndGoalMonth(userCategory3, goalMonth)); // 3 + + ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoal(user.getId(), + goalMonth.plusDays(2)); + + assertThat(result.getConsumptionGoalResponseDtoList()).usingRecursiveComparison().isEqualTo(expected); + } +} \ No newline at end of file From 4cede184f3ba2816d363614bcaa4d69e36f7ba15 Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 22 Jul 2024 00:31:27 +0900 Subject: [PATCH 050/126] =?UTF-8?q?[feat]=20ConsumptionGoalController=20?= =?UTF-8?q?=EB=AA=A9=ED=91=9C=20=EB=8B=AC=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=86=8C=EB=B9=84=20=EB=AA=A9=ED=91=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ConsumptionGoalController.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java new file mode 100644 index 00000000..cf7b6ba1 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java @@ -0,0 +1,32 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.controller; + +import java.time.LocalDate; + +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; +import com.bbteam.budgetbuddies.domain.consumptiongoal.service.ConsumptionGoalService; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/consumption-goal") +public class ConsumptionGoalController { + private final ConsumptionGoalService consumptionGoalService; + + @GetMapping("/{userId}") + public ResponseEntity findUserConsumptionGoal( + @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date, @PathVariable Long userId) { + + ConsumptionGoalResponseListDto response = consumptionGoalService.findUserConsumptionGoal(userId, date); + + return ResponseEntity.ok(response); + } +} From 0d7c1e8edbe7b99ba9dfe6761389d79dc5b788bc Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 22 Jul 2024 11:59:39 +0900 Subject: [PATCH 051/126] =?UTF-8?q?[refactor]=20ConsumptioGoalService=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=86=8C=EB=B9=84=20=EB=AA=A9=ED=91=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=B0=98=EB=B3=B5=EB=90=98=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalService.java | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java index 8c322e3c..de75966a 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java @@ -1,12 +1,13 @@ package com.bbteam.budgetbuddies.domain.consumptiongoal.service; import java.time.LocalDate; -import java.util.List; +import java.util.ArrayList; import java.util.Map; import java.util.stream.Collectors; import org.springframework.stereotype.Service; +import com.bbteam.budgetbuddies.domain.category.entity.Category; import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; @@ -20,31 +21,39 @@ public class ConsumptionGoalService { private final ConsumptionGoalRepository consumptionGoalRepository; private final CategoryRepository categoryRepository; - public ConsumptionGoalResponseListDto findUserConsumptionGoal(Long userId, LocalDate localDate) { - final LocalDate goalMonth = LocalDate.of(localDate.getYear(), localDate.getMonth(), 1); + public ConsumptionGoalResponseListDto findUserConsumptionGoal(Long userId, LocalDate date) { + LocalDate goalMonth = date.withDayOfMonth(1); + Map goalMap = initializeGoalMap(userId, goalMonth); - Map consumptionGoalResponseDtoMap = categoryRepository - .findUserCategoryByUserId(userId) - .stream() - .map(c -> ConsumptionGoalResponseDto.initializeFromCategoryAndGoalMonth(c, goalMonth)) - .collect(Collectors.toMap(ConsumptionGoalResponseDto::getCategoryId, c -> c)); + updateGoalMapWithPreviousMonth(userId, goalMonth, goalMap); + updateGoalMapWithCurrentMonth(userId, goalMonth, goalMap); - List lastMonthConsumptionGoalList = consumptionGoalRepository - .findConsumptionGoalByUserIdAndGoalMonth(userId, goalMonth.minusMonths(1)) - .stream().map(ConsumptionGoalResponseDto::of).toList(); + return new ConsumptionGoalResponseListDto(new ArrayList<>(goalMap.values())); + } - for (ConsumptionGoalResponseDto cgd : lastMonthConsumptionGoalList) { - consumptionGoalResponseDtoMap.put(cgd.getCategoryId(), cgd); - } + private Map initializeGoalMap(Long userId, LocalDate goalMonth) { + return categoryRepository.findUserCategoryByUserId(userId) + .stream() + .collect(Collectors.toMap( + Category::getId, + category -> ConsumptionGoalResponseDto.initializeFromCategoryAndGoalMonth(category, goalMonth) + )); + } - List consumptionGoalList = consumptionGoalRepository - .findConsumptionGoalByUserIdAndGoalMonth(userId, goalMonth) - .stream().map(ConsumptionGoalResponseDto::of).toList(); + private void updateGoalMapWithPreviousMonth(Long userId, LocalDate goalMonth, + Map goalMap) { + updateGoalMap(userId, goalMonth.minusMonths(1), goalMap); + } - for (ConsumptionGoalResponseDto cgd : consumptionGoalList) { - consumptionGoalResponseDtoMap.put(cgd.getCategoryId(), cgd); - } + private void updateGoalMapWithCurrentMonth(Long userId, LocalDate goalMonth, + Map goalMap) { + updateGoalMap(userId, goalMonth, goalMap); + } - return new ConsumptionGoalResponseListDto(consumptionGoalResponseDtoMap.values().stream().toList()); + private void updateGoalMap(Long userId, LocalDate month, Map goalMap) { + consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(userId, month) + .stream() + .map(ConsumptionGoalResponseDto::of) + .forEach(goal -> goalMap.put(goal.getCategoryId(), goal)); } } From 447c56e772db3a23b65c566eee007a23b32138d5 Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 22 Jul 2024 14:32:08 +0900 Subject: [PATCH 052/126] =?UTF-8?q?[refactor]=20ConsumptionGoalResponseLis?= =?UTF-8?q?tDto=20=ED=95=84=EB=93=9C=EB=AA=85=20=EB=8B=A8=EC=88=9C?= =?UTF-8?q?=ED=95=98=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumptiongoal/dto/ConsumptionGoalResponseListDto.java | 4 ++-- .../consumptiongoal/service/ConsumptionGoalServiceTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseListDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseListDto.java index 87ff4015..a4f9f5b3 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseListDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseListDto.java @@ -9,9 +9,9 @@ @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) public class ConsumptionGoalResponseListDto { - private List consumptionGoalResponseDtoList; + private List consumptionGoalList; public ConsumptionGoalResponseListDto(List consumptionGoalResponseDtoList) { - this.consumptionGoalResponseDtoList = consumptionGoalResponseDtoList; + this.consumptionGoalList = consumptionGoalResponseDtoList; } } diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java index 350cf441..9528dd38 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java @@ -22,7 +22,7 @@ import com.bbteam.budgetbuddies.domain.consumptiongoal.repository.ConsumptionGoalRepository; import com.bbteam.budgetbuddies.domain.user.entity.User; -// TODO 꺠끗하게 작성하기; +// TODO 깨끗하게 작성하기; @DisplayName("ConsumptionGoal 테스트의 ") @ExtendWith(MockitoExtension.class) class ConsumptionGoalServiceTest { @@ -120,6 +120,6 @@ void findUserConsumptionGoal_success() { ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoal(user.getId(), goalMonth.plusDays(2)); - assertThat(result.getConsumptionGoalResponseDtoList()).usingRecursiveComparison().isEqualTo(expected); + assertThat(result.getConsumptionGoalList()).usingRecursiveComparison().isEqualTo(expected); } } \ No newline at end of file From eb6ce790049382101c7423c5ceebb4a9473a4d64 Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 22 Jul 2024 15:00:58 +0900 Subject: [PATCH 053/126] =?UTF-8?q?[refactor]=20ConsumptionGoalRepositoryT?= =?UTF-8?q?est=20=EC=A1=B0=ED=9A=8C=EB=90=98=EB=A9=B4=20=EC=95=88=EB=90=98?= =?UTF-8?q?=EB=8A=94=20Entity=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 테스트를 성공하기 위해 조회되면 안되는 값을 다른 메서드로 분리함으로써 조회되면 안되는 케이스의 추가를 유연하게 할 수 있다. --- .../ConsumptionGoalRepositoryTest.java | 93 ++++++++----------- 1 file changed, 40 insertions(+), 53 deletions(-) diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepositoryTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepositoryTest.java index 4bd1bec1..571f5189 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepositoryTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepositoryTest.java @@ -29,81 +29,68 @@ class ConsumptionGoalRepositoryTest { CategoryRepository categoryRepository; @Test - @DisplayName("유저 아이디와 LocalDate를 통해 GoalConsumption 조회 성공") + @DisplayName("유저 아이디와 goalMonth를 통해 GoalConsumption 조회 성공") void findConsumptionGoalByUserIdAndGoalMonth_Success() { + // given + // 목표 달 LocalDate goalMonth = LocalDate.of(2024, 07, 01); - User user = userRepository.save(User.builder() - .email("email") - .age(24) - .name("name") - .phoneNumber("010-1234-5678") - .build()); + User mainUser = userRepository.save( + User.builder().email("email").age(24).name("name").phoneNumber("010-1234-5678").build()); - User otherUser = userRepository.save(User.builder() - .email("email2") - .age(24) - .name("name2") - .phoneNumber("010-1567-5678") - .build()); + Category defaultCategory = categoryRepository.save( + Category.builder().name("디폴트 카테고리").user(null).isDefault(true).build()); + + Category userCategory = categoryRepository.save( + Category.builder().name("유저 카테고리").user(mainUser).isDefault(false).build()); - Category defaultCategory = categoryRepository.save(Category.builder() - .name("디폴트 카테고리") - .user(null) - .isDefault(true) + ConsumptionGoal defaultCategoryConsumptionGoal = consumptionGoalRepository.save(ConsumptionGoal.builder() + .goalAmount(1L) + .consumeAmount(1L) + .user(mainUser) + .goalMonth(goalMonth) + .category(defaultCategory) .build()); - Category userCategory = categoryRepository.save(Category.builder() - .name("유저 카테고리") - .user(user) - .isDefault(false) + ConsumptionGoal userCategoryConsumptionGoal = consumptionGoalRepository.save(ConsumptionGoal.builder() + .goalAmount(1L) + .consumeAmount(1L) + .user(mainUser) + .goalMonth(goalMonth) + .category(userCategory) .build()); - ConsumptionGoal defaultCategoryConsumptionGoal = consumptionGoalRepository.save( - ConsumptionGoal.builder() - .goalAmount(1L) - .consumeAmount(1L) - .user(user) - .goalMonth(goalMonth) - .category(defaultCategory) - .build() - ); + setUnselectedConsumptionGoal(mainUser, goalMonth, defaultCategory); - ConsumptionGoal customCategoryConsumptionGoal = consumptionGoalRepository.save( - ConsumptionGoal.builder() - .goalAmount(1L) - .consumeAmount(1L) - .user(user) - .goalMonth(goalMonth) - .category(userCategory) - .build() - ); + // when + List result = consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(mainUser.getId(), + goalMonth); + + // then + assertThat(result).usingRecursiveComparison() + .isEqualTo(List.of(defaultCategoryConsumptionGoal, userCategoryConsumptionGoal)); + } - consumptionGoalRepository.save( + private void setUnselectedConsumptionGoal(User mainUser, LocalDate goalMonth, Category defaultCategory) { + User otherUser = userRepository.save( + User.builder().email("email2").age(24).name("name2").phoneNumber("010-1567-5678").build()); + + ConsumptionGoal lastMonthDefaultCategoryConsumptionGoal = consumptionGoalRepository.save( ConsumptionGoal.builder() .goalAmount(1L) .consumeAmount(1L) - .user(user) + .user(mainUser) .goalMonth(goalMonth.minusMonths(1)) .category(defaultCategory) - .build() - ); + .build()); - consumptionGoalRepository.save( + ConsumptionGoal otherUserDefaultCategoryConsumptionGoal = consumptionGoalRepository.save( ConsumptionGoal.builder() .goalAmount(1L) .consumeAmount(1L) .user(otherUser) .goalMonth(goalMonth) .category(defaultCategory) - .build() - ); - - List result = consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(user.getId(), - goalMonth); - - assertThat(result).usingRecursiveComparison() - .isEqualTo( - List.of(defaultCategoryConsumptionGoal, customCategoryConsumptionGoal)); + .build()); } } \ No newline at end of file From 2949847dbe894b5ad9dff132f5c169df97f89685 Mon Sep 17 00:00:00 2001 From: MJJ Date: Mon, 22 Jul 2024 15:20:16 +0900 Subject: [PATCH 054/126] =?UTF-8?q?[fix]=20limit=20=EC=BF=BC=EB=A6=AC?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ConsumptionGoalRepository.java | 3 ++- .../service/ConsumptionGoalServiceImpl.java | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java index cc0ee32a..d1c11190 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java @@ -17,8 +17,9 @@ public interface ConsumptionGoalRepository extends JpaRepository findTopCategoriesAndGoalAmount( + @Param("top") int top, @Param("peerAgeStart") int peerAgeStart, @Param("peerAgeEnd") int peerAgeEnd, @Param("peerGender") Gender peerGender); diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java index 86add557..178a4e03 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java @@ -33,8 +33,7 @@ public class ConsumptionGoalServiceImpl implements ConsumptionGoalService { @Override @Transactional(readOnly = true) - public List getTopGoalCategories(int top, Long userId, int peerAgeStart, - int peerAgeEnd, + public List getTopGoalCategories(int top, Long userId, int peerAgeStart, int peerAgeEnd, String peerGender) { Gender gender = convertToGender(peerGender); @@ -50,11 +49,18 @@ public List getTopGoalCategories(int top, Long userI gender = user.get().getGender(); setAgeGroupByUser(user.get().getAge()); + } else { + peerAgeStartByUser = peerAgeStart; + peerAgeEndByUser = peerAgeEnd; } - List topGoals = consumptionGoalRepository.findTopCategoriesAndGoalAmount(peerAgeStartByUser, - peerAgeEndByUser, gender); - return topGoals.stream().limit(top) // 여기서 top 개수만큼 제한 + log.info("peerAgeStartByUser: {}", peerAgeStartByUser); + log.info("peerAgeStartByUser: {}", peerAgeEndByUser); + log.info("peerAgeStartByUser: {}", gender); + + List topGoals = consumptionGoalRepository.findTopCategoriesAndGoalAmount(top, + peerAgeStartByUser, peerAgeEndByUser, gender); + return topGoals.stream()// 여기서 top 개수만큼 제한 .map(topCategoryConverter::fromEntity).collect(Collectors.toList()); } From 8b2c1fd8215a543b27bc9afbf4c95c4b24ca6b87 Mon Sep 17 00:00:00 2001 From: MJJ Date: Mon, 22 Jul 2024 16:38:22 +0900 Subject: [PATCH 055/126] =?UTF-8?q?[fix]=20ConsumptionGoalServiceImpl=20lo?= =?UTF-8?q?g=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumptiongoal/service/ConsumptionGoalServiceImpl.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java index 178a4e03..023b57b7 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java @@ -19,7 +19,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -@Slf4j @Service @RequiredArgsConstructor public class ConsumptionGoalServiceImpl implements ConsumptionGoalService { @@ -54,10 +53,6 @@ public List getTopGoalCategories(int top, Long userI peerAgeEndByUser = peerAgeEnd; } - log.info("peerAgeStartByUser: {}", peerAgeStartByUser); - log.info("peerAgeStartByUser: {}", peerAgeEndByUser); - log.info("peerAgeStartByUser: {}", gender); - List topGoals = consumptionGoalRepository.findTopCategoriesAndGoalAmount(top, peerAgeStartByUser, peerAgeEndByUser, gender); return topGoals.stream()// 여기서 top 개수만큼 제한 From da97b2ded5644bdb0dafbb195148cbc56e7823be Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 22 Jul 2024 16:53:40 +0900 Subject: [PATCH 056/126] =?UTF-8?q?[refactor]=20ConsumptionGoalServiceTest?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20?= =?UTF-8?q?=EC=86=8C=EB=B9=84=EB=AA=A9=ED=91=9C=EA=B0=80=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EA=B2=BD=EC=9A=B0,=20=EC=9D=B4=EC=A0=84=EB=8B=AC?= =?UTF-8?q?=20=EC=86=8C=EB=B9=84=EB=AA=A9=ED=91=9C=EB=A7=8C=20=EC=9E=88?= =?UTF-8?q?=EB=8A=94=EA=B2=BD=EC=9A=B0,=20=EC=9D=B4=EB=B2=88=EB=8B=AC=20?= =?UTF-8?q?=EC=86=8C=EB=B9=84=EB=AA=A9=ED=91=9C=EA=B0=80=20=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20=EA=B2=BD=EC=9A=B0=EB=A1=9C=20=EB=B6=84=ED=95=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalServiceTest.java | 165 +++++++++++------- 1 file changed, 99 insertions(+), 66 deletions(-) diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java index 9528dd38..7d7bec1b 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java @@ -5,7 +5,9 @@ import java.time.LocalDate; import java.util.List; +import java.util.Random; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -22,104 +24,135 @@ import com.bbteam.budgetbuddies.domain.consumptiongoal.repository.ConsumptionGoalRepository; import com.bbteam.budgetbuddies.domain.user.entity.User; -// TODO 깨끗하게 작성하기; @DisplayName("ConsumptionGoal 테스트의 ") @ExtendWith(MockitoExtension.class) class ConsumptionGoalServiceTest { + private final LocalDate GOAL_MONTH = LocalDate.of(2024, 07, 01); + private User user; + private LocalDate goalMonth; + @InjectMocks private ConsumptionGoalService consumptionGoalService; - @Mock private CategoryRepository categoryRepository; @Mock private ConsumptionGoalRepository consumptionGoalRepository; - @Test - @DisplayName("findUserConsumptionGoal 성공") - void findUserConsumptionGoal_success() { - LocalDate goalMonth = LocalDate.of(2024, 07, 01); - - User user = Mockito.spy(User.builder() - .email("email") - .age(24) - .name("name") - .phoneNumber("010-1234-5678") - .build()); + @BeforeEach + void setUp() { + Random random = new Random(); + int randomDay = random.nextInt(30) + 1; + goalMonth = LocalDate.of(GOAL_MONTH.getYear(), GOAL_MONTH.getMonth(), randomDay); + + user = Mockito.spy(User.builder().email("email").age(24).name("name").phoneNumber("010-1234-5678").build()); given(user.getId()).willReturn(-1L); + } - Category defaultCategory = Mockito.spy(Category.builder() - .name("디폴트 카테고리") - .user(null) - .isDefault(true) - .build()); + @Test + @DisplayName("findUserConsumptionGoal : 생성된 ConsumptionGoal이 없고 카테고리만 있는 경우 목표 금액, 소비 금액 0으로 초기화") + void findUserConsumptionGoal_onlyCategory() { + // given + Category defaultCategory = Mockito.spy(Category.builder().name("디폴트 카테고리").user(null).isDefault(true).build()); given(defaultCategory.getId()).willReturn(-1L); - Category userCategory = Mockito.spy(Category.builder() - .name("유저 카테고리") - .user(user) - .isDefault(false) - .build()); + Category userCategory = Mockito.spy(Category.builder().name("유저 카테고리").user(user).isDefault(false).build()); given(userCategory.getId()).willReturn(-2L); - Category userCategory2 = Mockito.spy(Category.builder() - .name("유저 카테고리2") - .user(user) - .isDefault(false) - .build()); - given(userCategory2.getId()).willReturn(-3L); + List categoryList = List.of(defaultCategory, userCategory); - Category userCategory3 = Mockito.spy(Category.builder() - .name("유저 카테고리3") - .user(user) - .isDefault(false) - .build()); - given(userCategory3.getId()).willReturn(-4L); + given(categoryRepository.findUserCategoryByUserId(user.getId())).willReturn(categoryList); - given(categoryRepository.findUserCategoryByUserId(user.getId())) - .willReturn(List.of(defaultCategory, userCategory, userCategory2, userCategory3)); + List expected = categoryList.stream() + .map(category -> ConsumptionGoalResponseDto.initializeFromCategoryAndGoalMonth(category, GOAL_MONTH)) + .toList(); + + // when + ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoal(user.getId(), goalMonth); + + // then + assertThat(result.getConsumptionGoalList()).usingRecursiveComparison().isEqualTo(expected); + } + + @Test + @DisplayName("findUserConsumptionGoal : 한달전 ConsumptionGoal만 있을 경우 한달전으로 초기화") + void findUserConsumptionGoal_previousMonth() { + // given + Category defaultCategory = Mockito.spy(Category.builder().name("디폴트 카테고리").user(null).isDefault(true).build()); + given(defaultCategory.getId()).willReturn(-1L); + + Category userCategory = Mockito.spy(Category.builder().name("유저 카테고리").user(user).isDefault(false).build()); + given(userCategory.getId()).willReturn(-2L); - // default - ConsumptionGoal consumptionGoal1 = ConsumptionGoal.builder() - .goalAmount(1L) - .consumeAmount(1L) + given(categoryRepository.findUserCategoryByUserId(user.getId())).willReturn( + List.of(defaultCategory, userCategory)); + + ConsumptionGoal previousMonthDefaultCategoryGoal = ConsumptionGoal.builder() + .goalAmount(1_000_000L) + .consumeAmount(20_000L) .user(user) .category(defaultCategory) - .goalMonth(goalMonth) + .goalMonth(goalMonth.minusMonths(1)) .build(); - // custom - ConsumptionGoal consumptionGoal2 = ConsumptionGoal.builder() - .goalAmount(1L) - .consumeAmount(1L) + ConsumptionGoal previousMonthUserCategoryGoal = ConsumptionGoal.builder() + .goalAmount(1_000_000L) + .consumeAmount(20_000L) .user(user) - .category(userCategory2) - .goalMonth(goalMonth) + .category(userCategory) + .goalMonth(goalMonth.minusMonths(1)) .build(); - // 1달 전 - ConsumptionGoal consumptionGoal3 = ConsumptionGoal.builder() - .goalAmount(1L) - .consumeAmount(1L) + List previousGoalList = List.of(previousMonthDefaultCategoryGoal, + previousMonthUserCategoryGoal); + + given(consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(user.getId(), + GOAL_MONTH.minusMonths(1))).willReturn(previousGoalList); + + List expected = previousGoalList.stream() + .map(ConsumptionGoalResponseDto::of) + .toList(); + + // when + ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoal(user.getId(), goalMonth); + + // then + assertThat(result.getConsumptionGoalList()).usingRecursiveComparison().isEqualTo(expected); + } + + @Test + @DisplayName("findUserConsumptionGoal : 한달 전과 목표 달 ConsumptionGoal이 있을 경우 목표 달로 초기화") + void findUserConsumptionGoal_previousMonthAndGoalMonth() { + // given + Category userCategory = Mockito.spy(Category.builder().name("유저 카테고리").user(user).isDefault(false).build()); + given(userCategory.getId()).willReturn(-2L); + + ConsumptionGoal previousMonthUserCategoryGoal = ConsumptionGoal.builder() + .goalAmount(1_000_000L) + .consumeAmount(20_000L) .user(user) - .category(userCategory2) - .goalMonth(goalMonth.withMonth(1)) + .category(userCategory) + .goalMonth(goalMonth.minusMonths(1)) .build(); - given(consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(user.getId(), goalMonth)).willReturn( - List.of(consumptionGoal1, consumptionGoal2)); + ConsumptionGoal goalMonthUserCategoryGoal = ConsumptionGoal.builder() + .goalAmount(2_000_000L) + .consumeAmount(30_000L) + .user(user) + .category(userCategory) + .goalMonth(goalMonth) + .build(); - given(consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(user.getId(), goalMonth.minusMonths(1))) - .willReturn(List.of(consumptionGoal3)); + given(consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(user.getId(), + GOAL_MONTH.minusMonths(1))).willReturn(List.of(previousMonthUserCategoryGoal)); - List expected = List.of( - ConsumptionGoalResponseDto.of(consumptionGoal1), // default - ConsumptionGoalResponseDto.initializeFromCategoryAndGoalMonth(userCategory, goalMonth), // 1 - ConsumptionGoalResponseDto.of(consumptionGoal2), // 2 - ConsumptionGoalResponseDto.initializeFromCategoryAndGoalMonth(userCategory3, goalMonth)); // 3 + given(consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(user.getId(), GOAL_MONTH)).willReturn( + List.of(goalMonthUserCategoryGoal)); - ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoal(user.getId(), - goalMonth.plusDays(2)); + // when + ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoal(user.getId(), goalMonth); - assertThat(result.getConsumptionGoalList()).usingRecursiveComparison().isEqualTo(expected); + // then + assertThat(result.getConsumptionGoalList()).usingRecursiveComparison() + .isEqualTo(List.of(ConsumptionGoalResponseDto.of(goalMonthUserCategoryGoal))); } } \ No newline at end of file From 071d24de22faac8b68d7737d70bd5dfafeb8cba8 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Mon, 22 Jul 2024 20:38:21 +0900 Subject: [PATCH 057/126] =?UTF-8?q?[feat]=20=EC=A3=BC=EB=A8=B8=EB=8B=88=20?= =?UTF-8?q?=EC=BA=98=EB=A6=B0=EB=8D=94=20=EC=9C=84=ED=95=9C=20DiscountInfo?= =?UTF-8?q?Repository=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 --- .../repository/DiscountInfoRepository.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/DiscountInfoRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/DiscountInfoRepository.java index e41ffe49..8aa49237 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/DiscountInfoRepository.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/DiscountInfoRepository.java @@ -5,12 +5,22 @@ 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; import java.time.LocalDate; +import java.util.List; public interface DiscountInfoRepository extends JpaRepository { @Query("SELECT i FROM DiscountInfo i WHERE (i.startDate <= :endDate AND i.endDate >= :startDate)") Page findByDateRange(LocalDate startDate, LocalDate endDate, Pageable pageable); + @Query("SELECT i FROM DiscountInfo i WHERE ((i.startDate BETWEEN :startDate AND :endDate) OR i.endDate BETWEEN :startDate AND :endDate)") + List findByMonth(@Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate); + + @Query("SELECT i FROM DiscountInfo i WHERE ((i.startDate BETWEEN :startDate AND :endDate) OR i.endDate BETWEEN :startDate AND :endDate)" + + " ORDER BY i.likeCount DESC" + + " LIMIT 2") + List findRecommendInfoByMonth(@Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate); + } From 2768442480c1299fbf9961cb056909c3bd819997 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Mon, 22 Jul 2024 20:38:44 +0900 Subject: [PATCH 058/126] =?UTF-8?q?[test]=20=EC=B6=94=EA=B0=80=EB=90=9C=20?= =?UTF-8?q?DiscountInfoRepository=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DiscountInfoRepositoryTest.java | 181 ++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/DiscountInfoRepositoryTest.java diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/DiscountInfoRepositoryTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/DiscountInfoRepositoryTest.java new file mode 100644 index 00000000..a390d2e4 --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/DiscountInfoRepositoryTest.java @@ -0,0 +1,181 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.repository; + +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +@Transactional +class DiscountInfoRepositoryTest { + + @Autowired + DiscountInfoRepository discountInfoRepository; + + @Test + void findByMonthTest(){ + LocalDate start1 = LocalDate.of(2024, 8, 1); + LocalDate start2 = LocalDate.of(2024, 7, 20); + LocalDate start3 = LocalDate.of(2024, 8, 31); + LocalDate start4 = LocalDate.of(2024, 7, 20); + LocalDate start5 = LocalDate.of(2024, 9, 1); + + LocalDate end1 = LocalDate.of(2024, 8, 5); + LocalDate end2 = LocalDate.of(2024, 8, 3); + LocalDate end3 = LocalDate.of(2024, 9, 3); + LocalDate end4 = LocalDate.of(2024, 7, 24); + LocalDate end5 = LocalDate.of(2024, 9, 5); + + DiscountInfo info1 = DiscountInfo.builder() + .startDate(start1) + .endDate(end1) + .title("test1") + .likeCount(0) + .build(); + + DiscountInfo info2 = DiscountInfo.builder() + .startDate(start2) + .endDate(end2) + .title("test2") + .likeCount(0) + .build(); + + DiscountInfo info3 = DiscountInfo.builder() + .startDate(start3) + .endDate(end3) + .title("test3") + .likeCount(0) + .build(); + + DiscountInfo info4 = DiscountInfo.builder() + .startDate(start4) + .endDate(end4) + .title("test4") + .likeCount(0) + .build(); + + DiscountInfo info5 = DiscountInfo.builder() + .startDate(start5) + .endDate(end5) + .title("test5") + .likeCount(0) + .build(); + + discountInfoRepository.save(info1); + discountInfoRepository.save(info2); + discountInfoRepository.save(info3); + discountInfoRepository.save(info4); + discountInfoRepository.save(info5); + + LocalDate firstDay = LocalDate.of(2024, 8, 1); + LocalDate lastDay = firstDay.withDayOfMonth(firstDay.lengthOfMonth()); + + List result = discountInfoRepository.findByMonth(firstDay, lastDay); + + Assertions.assertThat(result.size()).isEqualTo(3); + Assertions.assertThat(result).containsExactly(info1, info2, info3); + } + + @Test + void findRecommendInfoByMonthTest(){ + LocalDate start1 = LocalDate.of(2024, 8, 1); + LocalDate start2 = LocalDate.of(2024, 7, 20); + LocalDate start3 = LocalDate.of(2024, 8, 31); + LocalDate start4 = LocalDate.of(2024, 7, 20); + LocalDate start5 = LocalDate.of(2024, 9, 1); + + LocalDate end1 = LocalDate.of(2024, 8, 5); + LocalDate end2 = LocalDate.of(2024, 8, 3); + LocalDate end3 = LocalDate.of(2024, 9, 3); + LocalDate end4 = LocalDate.of(2024, 7, 24); + LocalDate end5 = LocalDate.of(2024, 9, 5); + + DiscountInfo info1 = DiscountInfo.builder() + .startDate(start1) + .endDate(end1) + .title("test1") + .likeCount(0) + .build(); + + DiscountInfo info2 = DiscountInfo.builder() + .startDate(start2) + .endDate(end2) + .title("test2") + .likeCount(0) + .build(); + + DiscountInfo info3 = DiscountInfo.builder() + .startDate(start3) + .endDate(end3) + .title("test3") + .likeCount(0) + .build(); + + DiscountInfo info4 = DiscountInfo.builder() + .startDate(start4) + .endDate(end4) + .title("test4") + .likeCount(0) + .build(); + + DiscountInfo info5 = DiscountInfo.builder() + .startDate(start5) + .endDate(end5) + .title("test5") + .likeCount(0) + .build(); + + discountInfoRepository.save(info1); + discountInfoRepository.save(info2); + discountInfoRepository.save(info3); + discountInfoRepository.save(info4); + discountInfoRepository.save(info5); + + for(int i = 0; i < 3; i++){ + info1.addLikeCount(); + } + for(int i = 0; i < 4; i++){ + info2.addLikeCount(); + } + for(int i = 0; i < 5; i++){ + info3.addLikeCount(); + } + for(int i = 0; i < 6; i++){ + info4.addLikeCount(); + } + for(int i = 0; i < 7; i++){ + info5.addLikeCount(); + } + LocalDate firstDay = LocalDate.of(2024, 8, 1); + LocalDate lastDay = firstDay.withDayOfMonth(firstDay.lengthOfMonth()); + + List result = discountInfoRepository.findRecommendInfoByMonth(firstDay, lastDay); + + Assertions.assertThat(result.size()).isEqualTo(2); + Assertions.assertThat(result).containsExactly(info3, info2); + + discountInfoRepository.delete(info3); + + List result2 = discountInfoRepository.findRecommendInfoByMonth(firstDay, lastDay); + + Assertions.assertThat(result2.size()).isEqualTo(2); + Assertions.assertThat(result2).containsExactly(info2, info1); + + discountInfoRepository.delete(info2); + + List result3 = discountInfoRepository.findRecommendInfoByMonth(firstDay, lastDay); + + Assertions.assertThat(result3.size()).isEqualTo(1); + Assertions.assertThat(result3).containsExactly(info1); + + + } + +} \ No newline at end of file From e11fa77be5590142b8e62b2bba7781bdd228c3c1 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Mon, 22 Jul 2024 20:50:07 +0900 Subject: [PATCH 059/126] =?UTF-8?q?[feat]=20=EC=A3=BC=EB=A8=B8=EB=8B=88=20?= =?UTF-8?q?=EC=BA=98=EB=A6=B0=EB=8D=94=20=EC=9C=84=ED=95=9C=20SupportInfoR?= =?UTF-8?q?epository=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 --- .../supportinfo/repository/SupportInfoRepository.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepository.java index fa44e97f..4d6ba4b1 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepository.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepository.java @@ -6,12 +6,22 @@ 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; import java.time.LocalDate; +import java.util.List; public interface SupportInfoRepository extends JpaRepository { @Query("SELECT i FROM SupportInfo i WHERE (i.startDate <= :endDate AND i.endDate >= :startDate)") Page findByDateRange(LocalDate startDate, LocalDate endDate, Pageable pageable); + @Query("SELECT i FROM SupportInfo i WHERE ((i.startDate BETWEEN :startDate AND :endDate) OR i.endDate BETWEEN :startDate AND :endDate)") + List findByMonth(@Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate); + + @Query("SELECT i FROM SupportInfo i WHERE ((i.startDate BETWEEN :startDate AND :endDate) OR i.endDate BETWEEN :startDate AND :endDate)" + + " ORDER BY i.likeCount DESC" + + " LIMIT 2") + List findRecommendInfoByMonth(@Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate); + } From e58cea87207af703875ec2f56e5725bfc46e3eca Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Mon, 22 Jul 2024 20:50:24 +0900 Subject: [PATCH 060/126] =?UTF-8?q?[test]=20=EC=B6=94=EA=B0=80=EB=90=9C=20?= =?UTF-8?q?SupportInfoRepository=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/SupportInfoRepositoryTest.java | 181 ++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepositoryTest.java diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepositoryTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepositoryTest.java new file mode 100644 index 00000000..7d490ee8 --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepositoryTest.java @@ -0,0 +1,181 @@ +package com.bbteam.budgetbuddies.domain.supportinfo.repository; + +import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +@Transactional +class SupportInfoRepositoryTest { + + @Autowired + SupportInfoRepository supportInfoRepository; + + + @Test + void findByMonthTest(){ + LocalDate start1 = LocalDate.of(2024, 7, 27); + LocalDate start2 = LocalDate.of(2024, 7, 20); + LocalDate start3 = LocalDate.of(2024, 8, 31); + LocalDate start4 = LocalDate.of(2024, 7, 20); + LocalDate start5 = LocalDate.of(2024, 8, 30); + + LocalDate end1 = LocalDate.of(2024, 8, 5); + LocalDate end2 = LocalDate.of(2024, 8, 3); + LocalDate end3 = LocalDate.of(2024, 9, 3); + LocalDate end4 = LocalDate.of(2024, 7, 24); + LocalDate end5 = LocalDate.of(2024, 9, 5); + + SupportInfo info1 = SupportInfo.builder() + .startDate(start1) + .endDate(end1) + .title("test1") + .likeCount(0) + .build(); + + SupportInfo info2 = SupportInfo.builder() + .startDate(start2) + .endDate(end2) + .title("test2") + .likeCount(0) + .build(); + + SupportInfo info3 = SupportInfo.builder() + .startDate(start3) + .endDate(end3) + .title("test3") + .likeCount(0) + .build(); + + SupportInfo info4 = SupportInfo.builder() + .startDate(start4) + .endDate(end4) + .title("test4") + .likeCount(0) + .build(); + + SupportInfo info5 = SupportInfo.builder() + .startDate(start5) + .endDate(end5) + .title("test5") + .likeCount(0) + .build(); + + supportInfoRepository.save(info1); + supportInfoRepository.save(info2); + supportInfoRepository.save(info3); + supportInfoRepository.save(info4); + supportInfoRepository.save(info5); + + LocalDate firstDay = LocalDate.of(2024, 8, 1); + LocalDate lastDay = firstDay.withDayOfMonth(firstDay.lengthOfMonth()); + + List result = supportInfoRepository.findByMonth(firstDay, lastDay); + + Assertions.assertThat(result.size()).isEqualTo(4); + Assertions.assertThat(result).containsExactlyInAnyOrder(info1, info2, info3, info5); + } + + @Test + void findRecommendInfoByMonthTest(){ + LocalDate start1 = LocalDate.of(2024, 8, 1); + LocalDate start2 = LocalDate.of(2024, 7, 20); + LocalDate start3 = LocalDate.of(2024, 8, 31); + LocalDate start4 = LocalDate.of(2024, 7, 20); + LocalDate start5 = LocalDate.of(2024, 9, 1); + + LocalDate end1 = LocalDate.of(2024, 8, 5); + LocalDate end2 = LocalDate.of(2024, 8, 3); + LocalDate end3 = LocalDate.of(2024, 9, 3); + LocalDate end4 = LocalDate.of(2024, 7, 24); + LocalDate end5 = LocalDate.of(2024, 9, 5); + + SupportInfo info1 = SupportInfo.builder() + .startDate(start1) + .endDate(end1) + .title("test1") + .likeCount(0) + .build(); + + SupportInfo info2 = SupportInfo.builder() + .startDate(start2) + .endDate(end2) + .title("test2") + .likeCount(0) + .build(); + + SupportInfo info3 = SupportInfo.builder() + .startDate(start3) + .endDate(end3) + .title("test3") + .likeCount(0) + .build(); + + SupportInfo info4 = SupportInfo.builder() + .startDate(start4) + .endDate(end4) + .title("test4") + .likeCount(0) + .build(); + + SupportInfo info5 = SupportInfo.builder() + .startDate(start5) + .endDate(end5) + .title("test5") + .likeCount(0) + .build(); + + supportInfoRepository.save(info1); + supportInfoRepository.save(info2); + supportInfoRepository.save(info3); + supportInfoRepository.save(info4); + supportInfoRepository.save(info5); + + for(int i = 0; i < 10; i++){ + info1.addLikeCount(); + } + for(int i = 0; i < 9; i++){ + info2.addLikeCount(); + } + for(int i = 0; i < 8; i++){ + info3.addLikeCount(); + } + for(int i = 0; i < 11; i++){ + info4.addLikeCount(); + } + for(int i = 0; i < 12; i++){ + info5.addLikeCount(); + } + LocalDate firstDay = LocalDate.of(2024, 8, 1); + LocalDate lastDay = firstDay.withDayOfMonth(firstDay.lengthOfMonth()); + + List result = supportInfoRepository.findRecommendInfoByMonth(firstDay, lastDay); + + Assertions.assertThat(result.size()).isEqualTo(2); + Assertions.assertThat(result).containsExactly(info1, info2); + + supportInfoRepository.delete(info3); + + List result2 = supportInfoRepository.findRecommendInfoByMonth(firstDay, lastDay); + + Assertions.assertThat(result2.size()).isEqualTo(2); + Assertions.assertThat(result2).containsExactly(info1, info2); + + supportInfoRepository.delete(info1); + + List result3 = supportInfoRepository.findRecommendInfoByMonth(firstDay, lastDay); + + Assertions.assertThat(result3.size()).isEqualTo(1); + Assertions.assertThat(result3).containsExactly(info2); + + + } +} \ No newline at end of file From 9e885790d62c28ecbad9a038f84cc82b068a1c9b Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Mon, 22 Jul 2024 21:40:05 +0900 Subject: [PATCH 061/126] =?UTF-8?q?[feat]=20CalendarDto=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/calendar/dto/CalendarDto.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/calendar/dto/CalendarDto.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/dto/CalendarDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/dto/CalendarDto.java new file mode 100644 index 00000000..37950b3e --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/dto/CalendarDto.java @@ -0,0 +1,45 @@ +package com.bbteam.budgetbuddies.domain.calendar.dto; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDate; +import java.util.List; + +public class CalendarDto { + + @Getter + @Builder + public static class CalendarMonthResponseDto { + CalendarMonthInfoDto calendarMonthInfoDto; + CalendarMonthInfoDto recommendMonthInfoDto; + } + + @Getter + @Builder + public static class CalendarMonthInfoDto { + private List discountInfoDtoList; + private List supportInfoDtoList; + } + + @Getter + @Builder + public static class CalendarDiscountInfoDto { + private Long id; + private String title; + private LocalDate startDate; + private LocalDate endDate; + private Integer likeCount; + private Integer discountRate; + } + + @Getter + @Builder + public static class CalendarSupportInfoDto { + private Long id; + private String title; + private LocalDate startDate; + private LocalDate endDate; + private Integer likeCount; + } +} From 9af6fab4f04726c35f82d2191bd56da72189d2eb Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Mon, 22 Jul 2024 21:40:12 +0900 Subject: [PATCH 062/126] =?UTF-8?q?[feat]=20CalendarConverter=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 --- .../calendar/converter/CalendarConverter.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/calendar/converter/CalendarConverter.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/converter/CalendarConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/converter/CalendarConverter.java new file mode 100644 index 00000000..e62cd00b --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/converter/CalendarConverter.java @@ -0,0 +1,55 @@ +package com.bbteam.budgetbuddies.domain.calendar.converter; + +import com.bbteam.budgetbuddies.domain.calendar.dto.CalendarDto; +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; + +import java.util.List; + +public class CalendarConverter { + + public static CalendarDto.CalendarMonthResponseDto toCalendarMonthResponseDto(CalendarDto.CalendarMonthInfoDto calendarMonthInfoDto, CalendarDto.CalendarMonthInfoDto recommendMonthInfoDto){ + return CalendarDto.CalendarMonthResponseDto.builder() + .calendarMonthInfoDto(calendarMonthInfoDto) + .recommendMonthInfoDto(recommendMonthInfoDto) + .build(); + } + + public static CalendarDto.CalendarMonthInfoDto toCalendarMonthInfoDto(List discountInfoList, + List supportInfoList) { + List discountInfoDtoList = discountInfoList.stream() + .map(CalendarConverter::toCalendarDiscountInfoDto) + .toList(); + List supportInfoDtoList = supportInfoList.stream() + .map(CalendarConverter::toCalendarSupportInfoDto) + .toList(); + + return CalendarDto.CalendarMonthInfoDto.builder() + .discountInfoDtoList(discountInfoDtoList) + .supportInfoDtoList(supportInfoDtoList) + .build(); + } + + public static CalendarDto.CalendarDiscountInfoDto toCalendarDiscountInfoDto(DiscountInfo discountInfo) { + return CalendarDto.CalendarDiscountInfoDto.builder() + .id(discountInfo.getId()) + .title(discountInfo.getTitle()) + .likeCount(discountInfo.getLikeCount()) + .startDate(discountInfo.getStartDate()) + .endDate(discountInfo.getEndDate()) + .discountRate(discountInfo.getDiscountRate()) + .build(); + } + + public static CalendarDto.CalendarSupportInfoDto toCalendarSupportInfoDto(SupportInfo supportInfo) { + return CalendarDto.CalendarSupportInfoDto.builder() + .id(supportInfo.getId()) + .title(supportInfo.getTitle()) + .likeCount(supportInfo.getLikeCount()) + .startDate(supportInfo.getStartDate()) + .endDate(supportInfo.getEndDate()) + .build(); + } + + +} From 08ed539c43040d8fe9fb3851c7f0fa56d1cb6c10 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Mon, 22 Jul 2024 21:40:22 +0900 Subject: [PATCH 063/126] =?UTF-8?q?[feat]=20CalendarService=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 --- .../calendar/service/CalendarService.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarService.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarService.java b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarService.java new file mode 100644 index 00000000..bba8816c --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarService.java @@ -0,0 +1,49 @@ +package com.bbteam.budgetbuddies.domain.calendar.service; + +import com.bbteam.budgetbuddies.domain.calendar.converter.CalendarConverter; +import com.bbteam.budgetbuddies.domain.calendar.dto.CalendarDto; +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +import com.bbteam.budgetbuddies.domain.discountinfo.repository.DiscountInfoRepository; +import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; +import com.bbteam.budgetbuddies.domain.supportinfo.repository.SupportInfoRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.util.List; + +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class CalendarService { + + private final DiscountInfoRepository discountInfoRepository; + + private final SupportInfoRepository supportInfoRepository; + + public CalendarDto.CalendarMonthResponseDto find(int year, int month){ + LocalDate firstDay = LocalDate.of(year, month, 1); + LocalDate lastDay = firstDay.withDayOfMonth(firstDay.lengthOfMonth()); + CalendarDto.CalendarMonthResponseDto result = getCalendarMonthResponseDto(firstDay, lastDay); + return result; + } + + private CalendarDto.CalendarMonthResponseDto getCalendarMonthResponseDto(LocalDate firstDay, LocalDate lastDay) { + CalendarDto.CalendarMonthInfoDto calendarMonthInfoDto = getCalendarMonthInfoDto(firstDay, lastDay); + CalendarDto.CalendarMonthInfoDto recommendMonthInfoDto = getRecommendMonthInfoDto(firstDay, lastDay); + return CalendarConverter.toCalendarMonthResponseDto(calendarMonthInfoDto, recommendMonthInfoDto); + } + + private CalendarDto.CalendarMonthInfoDto getRecommendMonthInfoDto(LocalDate firstDay, LocalDate lastDay) { + List recommendDiscountInfoList = discountInfoRepository.findRecommendInfoByMonth(firstDay, lastDay); + List recommendSupportInfoList = supportInfoRepository.findRecommendInfoByMonth(firstDay, lastDay); + return CalendarConverter.toCalendarMonthInfoDto(recommendDiscountInfoList, recommendSupportInfoList); + } + + private CalendarDto.CalendarMonthInfoDto getCalendarMonthInfoDto(LocalDate firstDay, LocalDate lastDay) { + List monthDiscountInfoList = discountInfoRepository.findByMonth(firstDay, lastDay); + List monthSupportInfoList = supportInfoRepository.findByMonth(firstDay, lastDay); + return CalendarConverter.toCalendarMonthInfoDto(monthDiscountInfoList, monthSupportInfoList); + } +} From e09980b315fb77cf5534296b9c995ded9ac0f066 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Mon, 22 Jul 2024 21:40:46 +0900 Subject: [PATCH 064/126] =?UTF-8?q?[fix]=20BaseEntity=20@Getter=20?= =?UTF-8?q?=ED=95=98=EB=82=98=20=EC=A0=9C=EA=B1=B0?= 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 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java index a5839c2b..b8e40e17 100644 --- a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java +++ b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java @@ -17,7 +17,6 @@ @EntityListeners(AuditingEntityListener.class) @MappedSuperclass -@Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @SuperBuilder From 6a426959a9c9fc99a5d64f0295c0582614789e3e Mon Sep 17 00:00:00 2001 From: JunRain Date: Tue, 23 Jul 2024 11:35:31 +0900 Subject: [PATCH 065/126] =?UTF-8?q?[fix]=20BaseEntity=20=EC=A4=91=EB=B3=B5?= =?UTF-8?q?=EB=90=9C=20@Getter=20=EC=A0=9C=EA=B1=B0?= 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 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java index a5839c2b..61b80cf6 100644 --- a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java +++ b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java @@ -22,7 +22,6 @@ @AllArgsConstructor @SuperBuilder @SoftDelete // boolean 타입의 deleted 필드가 추가 -@Getter public abstract class BaseEntity { @Id From 7975c27f45ac56a296ca1935232be0102be66606 Mon Sep 17 00:00:00 2001 From: JunRain Date: Tue, 23 Jul 2024 11:36:19 +0900 Subject: [PATCH 066/126] =?UTF-8?q?[chore]=20gitignore=20Setting=20File=20?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index c2065bc2..38944b87 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,6 @@ out/ ### VS Code ### .vscode/ + +### Setting File ### +src/main/resources/** \ No newline at end of file From 59a02d64f476a019fe3f70046efca879140e8f5c Mon Sep 17 00:00:00 2001 From: JunRain Date: Tue, 23 Jul 2024 11:36:49 +0900 Subject: [PATCH 067/126] =?UTF-8?q?[chore]=20resources/**=20=EC=B6=94?= =?UTF-8?q?=EC=A0=81=20=EC=A0=9C=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yaml | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 src/main/resources/application.yaml diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml deleted file mode 100644 index d7740288..00000000 --- a/src/main/resources/application.yaml +++ /dev/null @@ -1,17 +0,0 @@ -spring: - application: - name: budgetbuddies - - jpa: - show-sql: true # sql ???? ??? ???? ??. - properties: - format_sql: true - dialect: org.hibernate.dialect.MySQL8Dialect - hibernate: - ddl-auto: create - - datasource: - url: jdbc:mysql://localhost:3306/budgetbuddies # mysql ?? ?? (?? ?? DB? ?? ? ??) - driver-class-name: com.mysql.cj.jdbc.Driver - username: root - password: root # db ???? \ No newline at end of file From 9320d10630b2fcae684a76deeede26aa74f32285 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Tue, 23 Jul 2024 14:50:33 +0900 Subject: [PATCH 068/126] =?UTF-8?q?[refactor]=20CalendarService=20?= =?UTF-8?q?=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20-=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=EC=B2=B4=20=EA=B5=AC=EC=A1=B0=EB=A1=9C=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 --- .../calendar/service/CalendarService.java | 44 +---------------- .../calendar/service/CalendarServiceImpl.java | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 42 deletions(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarServiceImpl.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarService.java b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarService.java index bba8816c..e7920701 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarService.java @@ -1,49 +1,9 @@ package com.bbteam.budgetbuddies.domain.calendar.service; -import com.bbteam.budgetbuddies.domain.calendar.converter.CalendarConverter; import com.bbteam.budgetbuddies.domain.calendar.dto.CalendarDto; -import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; -import com.bbteam.budgetbuddies.domain.discountinfo.repository.DiscountInfoRepository; -import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; -import com.bbteam.budgetbuddies.domain.supportinfo.repository.SupportInfoRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import java.time.LocalDate; -import java.util.List; +public interface CalendarService { -@Service -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class CalendarService { + public CalendarDto.CalendarMonthResponseDto find(int year, int month); - private final DiscountInfoRepository discountInfoRepository; - - private final SupportInfoRepository supportInfoRepository; - - public CalendarDto.CalendarMonthResponseDto find(int year, int month){ - LocalDate firstDay = LocalDate.of(year, month, 1); - LocalDate lastDay = firstDay.withDayOfMonth(firstDay.lengthOfMonth()); - CalendarDto.CalendarMonthResponseDto result = getCalendarMonthResponseDto(firstDay, lastDay); - return result; - } - - private CalendarDto.CalendarMonthResponseDto getCalendarMonthResponseDto(LocalDate firstDay, LocalDate lastDay) { - CalendarDto.CalendarMonthInfoDto calendarMonthInfoDto = getCalendarMonthInfoDto(firstDay, lastDay); - CalendarDto.CalendarMonthInfoDto recommendMonthInfoDto = getRecommendMonthInfoDto(firstDay, lastDay); - return CalendarConverter.toCalendarMonthResponseDto(calendarMonthInfoDto, recommendMonthInfoDto); - } - - private CalendarDto.CalendarMonthInfoDto getRecommendMonthInfoDto(LocalDate firstDay, LocalDate lastDay) { - List recommendDiscountInfoList = discountInfoRepository.findRecommendInfoByMonth(firstDay, lastDay); - List recommendSupportInfoList = supportInfoRepository.findRecommendInfoByMonth(firstDay, lastDay); - return CalendarConverter.toCalendarMonthInfoDto(recommendDiscountInfoList, recommendSupportInfoList); - } - - private CalendarDto.CalendarMonthInfoDto getCalendarMonthInfoDto(LocalDate firstDay, LocalDate lastDay) { - List monthDiscountInfoList = discountInfoRepository.findByMonth(firstDay, lastDay); - List monthSupportInfoList = supportInfoRepository.findByMonth(firstDay, lastDay); - return CalendarConverter.toCalendarMonthInfoDto(monthDiscountInfoList, monthSupportInfoList); - } } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarServiceImpl.java new file mode 100644 index 00000000..db875fc9 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarServiceImpl.java @@ -0,0 +1,49 @@ +package com.bbteam.budgetbuddies.domain.calendar.service; + +import com.bbteam.budgetbuddies.domain.calendar.converter.CalendarConverter; +import com.bbteam.budgetbuddies.domain.calendar.dto.CalendarDto; +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +import com.bbteam.budgetbuddies.domain.discountinfo.repository.DiscountInfoRepository; +import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; +import com.bbteam.budgetbuddies.domain.supportinfo.repository.SupportInfoRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.util.List; + +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class CalendarServiceImpl { + + private final DiscountInfoRepository discountInfoRepository; + + private final SupportInfoRepository supportInfoRepository; + + public CalendarDto.CalendarMonthResponseDto find(int year, int month){ + LocalDate firstDay = LocalDate.of(year, month, 1); + LocalDate lastDay = firstDay.withDayOfMonth(firstDay.lengthOfMonth()); + CalendarDto.CalendarMonthResponseDto result = getCalendarMonthResponseDto(firstDay, lastDay); + return result; + } + + private CalendarDto.CalendarMonthResponseDto getCalendarMonthResponseDto(LocalDate firstDay, LocalDate lastDay) { + CalendarDto.CalendarMonthInfoDto calendarMonthInfoDto = getCalendarMonthInfoDto(firstDay, lastDay); + CalendarDto.CalendarMonthInfoDto recommendMonthInfoDto = getRecommendMonthInfoDto(firstDay, lastDay); + return CalendarConverter.toCalendarMonthResponseDto(calendarMonthInfoDto, recommendMonthInfoDto); + } + + private CalendarDto.CalendarMonthInfoDto getCalendarMonthInfoDto(LocalDate firstDay, LocalDate lastDay) { + List monthDiscountInfoList = discountInfoRepository.findByMonth(firstDay, lastDay); + List monthSupportInfoList = supportInfoRepository.findByMonth(firstDay, lastDay); + return CalendarConverter.toCalendarMonthInfoDto(monthDiscountInfoList, monthSupportInfoList); + } + + private CalendarDto.CalendarMonthInfoDto getRecommendMonthInfoDto(LocalDate firstDay, LocalDate lastDay) { + List recommendDiscountInfoList = discountInfoRepository.findRecommendInfoByMonth(firstDay, lastDay); + List recommendSupportInfoList = supportInfoRepository.findRecommendInfoByMonth(firstDay, lastDay); + return CalendarConverter.toCalendarMonthInfoDto(recommendDiscountInfoList, recommendSupportInfoList); + } +} From ea31e7266338b3632e01ccd82fdb455d3d86549b Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Tue, 23 Jul 2024 14:56:03 +0900 Subject: [PATCH 069/126] =?UTF-8?q?[refactor]=20CalendarServiceImpl=20impl?= =?UTF-8?q?ements=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../budgetbuddies/domain/calendar/service/CalendarService.java | 2 +- .../domain/calendar/service/CalendarServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarService.java b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarService.java index e7920701..bb4383c3 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarService.java @@ -4,6 +4,6 @@ public interface CalendarService { - public CalendarDto.CalendarMonthResponseDto find(int year, int month); + CalendarDto.CalendarMonthResponseDto find(int year, int month); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarServiceImpl.java index db875fc9..bd543261 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarServiceImpl.java @@ -16,7 +16,7 @@ @Service @Transactional(readOnly = true) @RequiredArgsConstructor -public class CalendarServiceImpl { +public class CalendarServiceImpl implements CalendarService{ private final DiscountInfoRepository discountInfoRepository; From b977a4f29e38819ea8f317f60859fb3a26040ff0 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Tue, 23 Jul 2024 15:14:55 +0900 Subject: [PATCH 070/126] =?UTF-8?q?[refactor]=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=A5=BC=20=EC=9C=84=ED=95=B4=20@EqualsAndHashCode=20?= =?UTF-8?q?Annotation=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/calendar/dto/CalendarDto.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/dto/CalendarDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/dto/CalendarDto.java index 37950b3e..78f6ccf7 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/dto/CalendarDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/dto/CalendarDto.java @@ -1,6 +1,7 @@ package com.bbteam.budgetbuddies.domain.calendar.dto; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import java.time.LocalDate; @@ -24,6 +25,7 @@ public static class CalendarMonthInfoDto { @Getter @Builder + @EqualsAndHashCode public static class CalendarDiscountInfoDto { private Long id; private String title; @@ -35,6 +37,7 @@ public static class CalendarDiscountInfoDto { @Getter @Builder + @EqualsAndHashCode public static class CalendarSupportInfoDto { private Long id; private String title; From e7651f1b5e761b7b94d15679b0eda288bfeebfd5 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Tue, 23 Jul 2024 15:19:44 +0900 Subject: [PATCH 071/126] =?UTF-8?q?[test]=20CalendarService=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/service/CalendarServiceTest.java | 202 ++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarServiceTest.java diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarServiceTest.java new file mode 100644 index 00000000..ded0e299 --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/calendar/service/CalendarServiceTest.java @@ -0,0 +1,202 @@ +package com.bbteam.budgetbuddies.domain.calendar.service; + +import com.bbteam.budgetbuddies.domain.calendar.converter.CalendarConverter; +import com.bbteam.budgetbuddies.domain.calendar.dto.CalendarDto; +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +import com.bbteam.budgetbuddies.domain.discountinfo.repository.DiscountInfoRepository; +import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; +import com.bbteam.budgetbuddies.domain.supportinfo.repository.SupportInfoRepository; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.util.List; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +@Transactional +class CalendarServiceTest { + + @Autowired + CalendarService calendarService; + @Autowired + DiscountInfoRepository discountInfoRepository; + @Autowired + SupportInfoRepository supportInfoRepository; + + @Test + void findTest(){ + LocalDate discountStart1 = LocalDate.of(2024, 8, 1); + LocalDate discountStart2 = LocalDate.of(2024, 7, 20); + LocalDate discountStart3 = LocalDate.of(2024, 8, 31); + LocalDate discountStart4 = LocalDate.of(2024, 7, 20); + LocalDate discountStart5 = LocalDate.of(2024, 9, 1); + + LocalDate discountEnd1 = LocalDate.of(2024, 8, 5); + LocalDate discountEnd2 = LocalDate.of(2024, 8, 3); + LocalDate discountEnd3 = LocalDate.of(2024, 9, 3); + LocalDate discountEnd4 = LocalDate.of(2024, 7, 24); + LocalDate discountEnd5 = LocalDate.of(2024, 9, 5); + + DiscountInfo discountInfo1 = DiscountInfo.builder() + .startDate(discountStart1) + .endDate(discountEnd1) + .title("test1") + .likeCount(0) + .build(); + + DiscountInfo discountInfo2 = DiscountInfo.builder() + .startDate(discountStart2) + .endDate(discountEnd2) + .title("test2") + .likeCount(0) + .build(); + + DiscountInfo discountInfo3 = DiscountInfo.builder() + .startDate(discountStart3) + .endDate(discountEnd3) + .title("test3") + .likeCount(0) + .build(); + + DiscountInfo discountInfo4 = DiscountInfo.builder() + .startDate(discountStart4) + .endDate(discountEnd4) + .title("test4") + .likeCount(0) + .build(); + + DiscountInfo discountInfo5 = DiscountInfo.builder() + .startDate(discountStart5) + .endDate(discountEnd5) + .title("test5") + .likeCount(0) + .build(); + + discountInfoRepository.save(discountInfo1); + discountInfoRepository.save(discountInfo2); + discountInfoRepository.save(discountInfo3); + discountInfoRepository.save(discountInfo4); + discountInfoRepository.save(discountInfo5); + + for(int i = 0; i < 3; i++){ + discountInfo1.addLikeCount(); + } + for(int i = 0; i < 4; i++){ + discountInfo2.addLikeCount(); + } + for(int i = 0; i < 5; i++){ + discountInfo3.addLikeCount(); + } + for(int i = 0; i < 6; i++){ + discountInfo4.addLikeCount(); + } + for(int i = 0; i < 7; i++){ + discountInfo5.addLikeCount(); + } + + LocalDate firstDay = LocalDate.of(2024, 8, 1); + LocalDate lastDay = firstDay.withDayOfMonth(firstDay.lengthOfMonth()); + + LocalDate supportStart1 = LocalDate.of(2024, 8, 1); + LocalDate supportStart2 = LocalDate.of(2024, 7, 20); + LocalDate supportStart3 = LocalDate.of(2024, 8, 31); + LocalDate supportStart4 = LocalDate.of(2024, 7, 20); + LocalDate supportStart5 = LocalDate.of(2024, 9, 1); + + LocalDate supportEnd1 = LocalDate.of(2024, 8, 5); + LocalDate supportEnd2 = LocalDate.of(2024, 7, 23); + LocalDate supportEnd3 = LocalDate.of(2024, 9, 3); + LocalDate supportEnd4 = LocalDate.of(2024, 7, 24); + LocalDate supportEnd5 = LocalDate.of(2024, 9, 5); + + SupportInfo supportInfo1 = SupportInfo.builder() + .startDate(supportStart1) + .endDate(supportEnd1) + .title("test1") + .likeCount(0) + .build(); + + SupportInfo supportInfo2 = SupportInfo.builder() + .startDate(supportStart2) + .endDate(supportEnd2) + .title("test2") + .likeCount(0) + .build(); + + SupportInfo supportInfo3 = SupportInfo.builder() + .startDate(supportStart3) + .endDate(supportEnd3) + .title("test3") + .likeCount(0) + .build(); + + SupportInfo supportInfo4 = SupportInfo.builder() + .startDate(supportStart4) + .endDate(supportEnd4) + .title("test4") + .likeCount(0) + .build(); + + SupportInfo supportInfo5 = SupportInfo.builder() + .startDate(supportStart5) + .endDate(supportEnd5) + .title("test5") + .likeCount(0) + .build(); + + supportInfoRepository.save(supportInfo1); + supportInfoRepository.save(supportInfo2); + supportInfoRepository.save(supportInfo3); + supportInfoRepository.save(supportInfo4); + supportInfoRepository.save(supportInfo5); + + for(int i = 0; i < 10; i++){ + supportInfo1.addLikeCount(); + } + for(int i = 0; i < 9; i++){ + supportInfo2.addLikeCount(); + } + for(int i = 0; i < 8; i++){ + supportInfo3.addLikeCount(); + } + for(int i = 0; i < 11; i++){ + supportInfo4.addLikeCount(); + } + for(int i = 0; i < 12; i++){ + supportInfo5.addLikeCount(); + } + + CalendarDto.CalendarMonthResponseDto result = calendarService.find(2024, 8); + List discountInfoDtoList = result.getCalendarMonthInfoDto().getDiscountInfoDtoList(); + List supportInfoDtoList = result.getCalendarMonthInfoDto().getSupportInfoDtoList(); + + assertThat(discountInfoDtoList.size()).isEqualTo(3); + CalendarDto.CalendarDiscountInfoDto discountDto1 = CalendarConverter.toCalendarDiscountInfoDto(discountInfo1); + CalendarDto.CalendarDiscountInfoDto discountDto2 = CalendarConverter.toCalendarDiscountInfoDto(discountInfo2); + CalendarDto.CalendarDiscountInfoDto discountDto3 = CalendarConverter.toCalendarDiscountInfoDto(discountInfo3); + assertThat(discountInfoDtoList).containsExactlyInAnyOrder(discountDto1, discountDto2, discountDto3); + + assertThat(supportInfoDtoList.size()).isEqualTo(2); + CalendarDto.CalendarSupportInfoDto supportDto1 = CalendarConverter.toCalendarSupportInfoDto(supportInfo1); + CalendarDto.CalendarSupportInfoDto supportDto3 = CalendarConverter.toCalendarSupportInfoDto(supportInfo3); + assertThat(supportInfoDtoList).containsExactlyInAnyOrder(supportDto1, supportDto3); + + List recDiscountDtoList = result.getRecommendMonthInfoDto().getDiscountInfoDtoList(); + List recSupportDtoList = result.getRecommendMonthInfoDto().getSupportInfoDtoList(); + + assertThat(recDiscountDtoList.size()).isEqualTo(2); + assertThat(recDiscountDtoList).containsExactly(discountDto3, discountDto2); + + assertThat(recSupportDtoList.size()).isEqualTo(2); + assertThat(recSupportDtoList).containsExactly(supportDto1, supportDto3); + + + } + +} \ No newline at end of file From eb73433b06230c4c8bcc52396d4ae5f96e2a4d13 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Tue, 23 Jul 2024 15:24:04 +0900 Subject: [PATCH 072/126] =?UTF-8?q?[feat]=20CalendarController=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/CalendarController.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/calendar/controller/CalendarController.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/controller/CalendarController.java b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/controller/CalendarController.java new file mode 100644 index 00000000..c5c8d951 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/controller/CalendarController.java @@ -0,0 +1,26 @@ +package com.bbteam.budgetbuddies.domain.calendar.controller; + +import com.bbteam.budgetbuddies.domain.calendar.dto.CalendarDto; +import com.bbteam.budgetbuddies.domain.calendar.service.CalendarService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/calendar") +public class CalendarController { + + private final CalendarService calendarService; + + @GetMapping("/") + public ResponseEntity request( + @RequestParam("year") Integer year, @RequestParam("month") Integer month + ) { + CalendarDto.CalendarMonthResponseDto result = calendarService.find(year, month); + return ResponseEntity.ok(result); + } +} From 0c95864df2dd055ffc33874463a2098739666fb8 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Tue, 23 Jul 2024 15:38:05 +0900 Subject: [PATCH 073/126] =?UTF-8?q?[refactor]=20DiscountInfoRepositoryTest?= =?UTF-8?q?=20=EC=88=9C=EC=84=9C=20=EC=83=81=EA=B4=80=EC=97=86=EC=9D=B4=20?= =?UTF-8?q?=ED=86=B5=EA=B3=BC=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 --- .../discountinfo/repository/DiscountInfoRepositoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/DiscountInfoRepositoryTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/DiscountInfoRepositoryTest.java index a390d2e4..a7b00d9f 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/DiscountInfoRepositoryTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/DiscountInfoRepositoryTest.java @@ -80,7 +80,7 @@ void findByMonthTest(){ List result = discountInfoRepository.findByMonth(firstDay, lastDay); Assertions.assertThat(result.size()).isEqualTo(3); - Assertions.assertThat(result).containsExactly(info1, info2, info3); + Assertions.assertThat(result).containsExactlyInAnyOrder(info1, info2, info3); } @Test From 71f6078abaf36d823bb99508b9886cb38606da1e Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Tue, 23 Jul 2024 15:53:40 +0900 Subject: [PATCH 074/126] =?UTF-8?q?[feat]=20CalendarController=20Swagger?= =?UTF-8?q?=20=EA=B4=80=EB=A0=A8=20Annotation=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/controller/CalendarController.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/controller/CalendarController.java b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/controller/CalendarController.java index c5c8d951..bc98ff3f 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/controller/CalendarController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/controller/CalendarController.java @@ -2,6 +2,10 @@ import com.bbteam.budgetbuddies.domain.calendar.dto.CalendarDto; import com.bbteam.budgetbuddies.domain.calendar.service.CalendarService; +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.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -15,7 +19,14 @@ public class CalendarController { private final CalendarService calendarService; - + @Operation(summary = "[User] 주머니 캘린더 API", description = "주머니 캘린더 화면에 필요한 API를 호출합니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "year", description = "호출할 연도입니다."), + @Parameter(name = "month", description = "호출할 연도의 월입니다."), + }) @GetMapping("/") public ResponseEntity request( @RequestParam("year") Integer year, @RequestParam("month") Integer month From 6acce8080d9c8dff7b77107ee31f5f057cd7fe2c Mon Sep 17 00:00:00 2001 From: MJJ Date: Tue, 23 Jul 2024 18:02:35 +0900 Subject: [PATCH 075/126] =?UTF-8?q?[fix]=20ConsumptionGoalController=20swa?= =?UTF-8?q?gger=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ConsumptionGoalController.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java index 180a6b37..6b70c8aa 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java @@ -27,7 +27,12 @@ public class ConsumptionGoalController { @Operation(summary = "또래들이 가장 큰 계획을 세운 카테고리 조회 API", description = "특정 사용자의 소비 목표 카테고리별 소비 목표 금액을 조회하는 API 입니다.") @ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")}) - @Parameters({@Parameter(name = "top", description = "가장 큰 목표를 세운 카테고리의 개수를 지정합니다. (기본값은 5입니다)")}) + @Parameters({ + @Parameter(name = "top", description = "가장 큰 목표를 세운 카테고리의 개수를 지정합니다. (기본값은 5입니다)"), + @Parameter(name = "userId", description = "로그인 한 유저 아이디"), + @Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"), + @Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"), + @Parameter(name = "peerGender", description = "또래 성별")}) @GetMapping("/top-categories") public ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaultValue = "5") int top, @RequestParam(name = "userId") Long userId, From 1440072ba06db80c349ac91630fa8f9b067721a4 Mon Sep 17 00:00:00 2001 From: MJJ Date: Tue, 23 Jul 2024 18:04:04 +0900 Subject: [PATCH 076/126] =?UTF-8?q?[fix]=20ConsumptionGoalServiceImpl=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalServiceImpl.java | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java index 023b57b7..fbc9531e 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java @@ -17,69 +17,69 @@ import com.bbteam.budgetbuddies.enums.Gender; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; @Service @RequiredArgsConstructor public class ConsumptionGoalServiceImpl implements ConsumptionGoalService { private final ConsumptionGoalRepository consumptionGoalRepository; - private final TopCategoryConverter topCategoryConverter; private final UserRepository userRepository; - private int peerAgeStartByUser; - private int peerAgeEndByUser; + private int peerAgeStart; + private int peerAgeEnd; + private Gender peerGender; @Override @Transactional(readOnly = true) - public List getTopGoalCategories(int top, Long userId, int peerAgeStart, int peerAgeEnd, - String peerGender) { + public List getTopGoalCategories(int top, Long userId, int peerAgeS, int peerAgeE, + String peerG) { - Gender gender = convertToGender(peerGender); + User user = findUserById(userId); + checkPeerInfo(user, peerAgeS, peerAgeE, peerG); + + List topGoals = consumptionGoalRepository.findTopCategoriesAndGoalAmount(top, peerAgeStart, + peerAgeEnd, peerGender); + return topGoals.stream().map(TopCategoryConverter::fromEntity).collect(Collectors.toList()); + } + + private User findUserById(Long userId) { Optional user = userRepository.findById(userId); if (user.isEmpty()) { throw new NoSuchElementException("유저를 찾을 수 없습니다."); } - if (peerAgeStart == 0 || peerAgeEnd == 0 || gender == Gender.NONE) { + return user.get(); + } - gender = user.get().getGender(); - setAgeGroupByUser(user.get().getAge()); + private void checkPeerInfo(User user, int peerAgeS, int peerAgeE, String peerG) { - } else { - peerAgeStartByUser = peerAgeStart; - peerAgeEndByUser = peerAgeEnd; - } - - List topGoals = consumptionGoalRepository.findTopCategoriesAndGoalAmount(top, - peerAgeStartByUser, peerAgeEndByUser, gender); - return topGoals.stream()// 여기서 top 개수만큼 제한 - .map(topCategoryConverter::fromEntity).collect(Collectors.toList()); - } + Gender gender = Gender.valueOf(peerG.toUpperCase()); - private Gender convertToGender(String genderString) { - try { - return Gender.valueOf(genderString.toUpperCase()); - } catch (IllegalArgumentException e) { - return Gender.NONE; // default or invalid value + if (peerAgeS == 0 || peerAgeE == 0 || gender == Gender.NONE) { + peerGender = user.getGender(); + setAgeGroupByUser(user.getAge()); + } else { + peerAgeStart = peerAgeS; + peerAgeEnd = peerAgeE; + peerGender = gender; } } private void setAgeGroupByUser(int userAge) { if (userAge >= 20 && userAge <= 22) { - peerAgeStartByUser = 20; - peerAgeEndByUser = 22; + peerAgeStart = 20; + peerAgeEnd = 22; } else if (userAge >= 23 && userAge <= 25) { - peerAgeStartByUser = 23; - peerAgeEndByUser = 25; + peerAgeStart = 23; + peerAgeEnd = 25; } else if (userAge >= 26 && userAge <= 28) { - peerAgeStartByUser = 26; - peerAgeEndByUser = 28; + peerAgeStart = 26; + peerAgeEnd = 28; } else if (userAge >= 29) { - peerAgeStartByUser = 29; - peerAgeEndByUser = 100; + peerAgeStart = 29; + peerAgeEnd = 100; } } } From 837cfe90cba30deb90e1640f9e56fb568063d655 Mon Sep 17 00:00:00 2001 From: MJJ Date: Tue, 23 Jul 2024 18:22:14 +0900 Subject: [PATCH 077/126] =?UTF-8?q?[fix]=20TopCategoryConverter=20static?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=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 --- .../domain/consumptiongoal/converter/TopCategoryConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopCategoryConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopCategoryConverter.java index 458d42a5..239dc8da 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopCategoryConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopCategoryConverter.java @@ -8,7 +8,7 @@ @Component public class TopCategoryConverter { - public TopGoalCategoryResponseDTO fromEntity(ConsumptionGoal consumptionGoal) { + public static TopGoalCategoryResponseDTO fromEntity(ConsumptionGoal consumptionGoal) { if (consumptionGoal == null || consumptionGoal.getCategory() == null) { return null; } From c31d5d1c55240394c6cc211ddeb55593da73bec0 Mon Sep 17 00:00:00 2001 From: MJJ Date: Tue, 23 Jul 2024 18:39:48 +0900 Subject: [PATCH 078/126] =?UTF-8?q?[fix]=20category=20import=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 --- .../consumptiongoal/service/ConsumptionGoalServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java index b2ac9066..ebaff195 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.bbteam.budgetbuddies.domain.category.entity.Category; import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.TopCategoryConverter; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseDto; From 94d430a5fe1731e39bf2fb21f7a62f14776e84f7 Mon Sep 17 00:00:00 2001 From: MJJ Date: Tue, 23 Jul 2024 18:40:04 +0900 Subject: [PATCH 079/126] =?UTF-8?q?[fix]=20application.yaml=20ignore=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 38944b87..7dbfa83c 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,4 @@ out/ .vscode/ ### Setting File ### -src/main/resources/** \ No newline at end of file +src/main/resources/application.yml \ No newline at end of file From 1b5b4a9f07fe2d5f5b55a033be7fa502f3618844 Mon Sep 17 00:00:00 2001 From: MJJ Date: Tue, 23 Jul 2024 23:07:22 +0900 Subject: [PATCH 080/126] =?UTF-8?q?[feat]=20=EB=98=90=EB=9E=98=20=EB=82=98?= =?UTF-8?q?=EC=9D=B4=EC=99=80=20=EC=84=B1=EB=B3=84=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?controller=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ConsumptionGoalController.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java index a821a4ea..1d7e59e9 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RestController; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.PeerInfoResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.service.ConsumptionGoalService; @@ -56,4 +57,21 @@ public ResponseEntity findUserConsumptionGoal( return ResponseEntity.ok(response); } + + @Operation(summary = "또래나이와 성별 조회 API", description = "또래나이와 성별을 조회하는 API 입니다.") + @ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")}) + @Parameters({ + @Parameter(name = "userId", description = "로그인 한 유저 아이디"), + @Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"), + @Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"), + @Parameter(name = "peerGender", description = "또래 성별")}) + @GetMapping("/peer-info") + public ResponseEntity getPeerInfo(@RequestParam(name = "userId") Long userId, + @RequestParam(name = "peerAgeStart", defaultValue = "0") int peerAgeStart, + @RequestParam(name = "peerAgeEnd", defaultValue = "0") int peerAgeEnd, + @RequestParam(name = "peerGender", defaultValue = "none") String peerGender) { + PeerInfoResponseDTO response = consumptionGoalService.getPeerInfo(userId, peerAgeStart, peerAgeEnd, peerGender); + return ResponseEntity.ok(response); + } + } \ No newline at end of file From d2ce4b2f3023c03a96a2dab9d1fe5d7cdfc7f5ba Mon Sep 17 00:00:00 2001 From: MJJ Date: Tue, 23 Jul 2024 23:07:58 +0900 Subject: [PATCH 081/126] =?UTF-8?q?[feat]=20=EB=98=90=EB=9E=98=20=EB=82=98?= =?UTF-8?q?=EC=9D=B4=EC=99=80=20=EC=84=B1=EB=B3=84=20responseDTO=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/PeerInfoResponseDTO.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/PeerInfoResponseDTO.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/PeerInfoResponseDTO.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/PeerInfoResponseDTO.java new file mode 100644 index 00000000..3ac0d041 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/PeerInfoResponseDTO.java @@ -0,0 +1,19 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PeerInfoResponseDTO { + + private int peerAgeStart; + + private int peerAgeEnd; + + private String peerGender; +} From ca02ce3cc1c2b2781caaa699c70c7b4705816d97 Mon Sep 17 00:00:00 2001 From: MJJ Date: Tue, 23 Jul 2024 23:08:10 +0900 Subject: [PATCH 082/126] =?UTF-8?q?[feat]=20=EB=98=90=EB=9E=98=20=EB=82=98?= =?UTF-8?q?=EC=9D=B4=EC=99=80=20=EC=84=B1=EB=B3=84=20converter=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/PeerInfoConverter.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/PeerInfoConverter.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/PeerInfoConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/PeerInfoConverter.java new file mode 100644 index 00000000..d6c3eb24 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/PeerInfoConverter.java @@ -0,0 +1,16 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.converter; + +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.PeerInfoResponseDTO; +import com.bbteam.budgetbuddies.enums.Gender; + +public class PeerInfoConverter { + + public static PeerInfoResponseDTO fromEntity(int peerAgeStart, int peerAgeEnd, Gender peerGender) { + + return PeerInfoResponseDTO.builder() + .peerAgeStart(peerAgeStart) + .peerAgeEnd(peerAgeEnd) + .peerGender(peerGender.name()) + .build(); + } +} From ed9dcf3dc722afdf3a640a081b4089674d2c1f41 Mon Sep 17 00:00:00 2001 From: MJJ Date: Tue, 23 Jul 2024 23:08:29 +0900 Subject: [PATCH 083/126] =?UTF-8?q?[feat]=20=EB=98=90=EB=9E=98=20=EB=82=98?= =?UTF-8?q?=EC=9D=B4=EC=99=80=20=EC=84=B1=EB=B3=84=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?service=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalService.java | 3 +++ .../service/ConsumptionGoalServiceImpl.java | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java index b39ea519..5cafba0c 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java @@ -6,6 +6,7 @@ import org.springframework.stereotype.Service; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.PeerInfoResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; @Service @@ -15,4 +16,6 @@ List getTopGoalCategories(int top, Long userId, int String peerGender); ConsumptionGoalResponseListDto findUserConsumptionGoal(Long userId, LocalDate date); + + PeerInfoResponseDTO getPeerInfo(Long userId, int peerAgeStart, int peerAgeEnd, String peerGender); } \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java index ebaff195..1c7195d5 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java @@ -13,9 +13,11 @@ import com.bbteam.budgetbuddies.domain.category.entity.Category; import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; +import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.PeerInfoConverter; import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.TopCategoryConverter; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.PeerInfoResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; import com.bbteam.budgetbuddies.domain.consumptiongoal.repository.ConsumptionGoalRepository; @@ -62,6 +64,17 @@ public ConsumptionGoalResponseListDto findUserConsumptionGoal(Long userId, Local return new ConsumptionGoalResponseListDto(new ArrayList<>(goalMap.values())); } + @Override + @Transactional(readOnly = true) + public PeerInfoResponseDTO getPeerInfo(Long userId, int peerAgeS, int peerAgeE, String peerG) { + + User user = findUserById(userId); + + checkPeerInfo(user, peerAgeS, peerAgeE, peerG); + + return PeerInfoConverter.fromEntity(peerAgeStart, peerAgeEnd, peerGender); + } + private User findUserById(Long userId) { Optional user = userRepository.findById(userId); From c2aa6f72b28486cf43ef0ed0d3ed440bd6ea3efc Mon Sep 17 00:00:00 2001 From: MJJ Date: Tue, 23 Jul 2024 23:15:50 +0900 Subject: [PATCH 084/126] =?UTF-8?q?[fix]=20=EC=9C=A0=EC=A0=80=20=EB=B3=84?= =?UTF-8?q?=20=EB=98=90=EB=9E=98=20=EB=82=98=EC=9D=B4=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumptiongoal/service/ConsumptionGoalServiceImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java index 1c7195d5..f9722314 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java @@ -111,7 +111,10 @@ private void setAgeGroupByUser(int userAge) { peerAgeEnd = 28; } else if (userAge >= 29) { peerAgeStart = 29; - peerAgeEnd = 100; + peerAgeEnd = 99; + }else{ + peerAgeStart = 0; + peerAgeEnd = 19; } } From 6ee4dee9e2d1ac2b7c7c9d2f248efa661b35ed59 Mon Sep 17 00:00:00 2001 From: JunRain Date: Wed, 24 Jul 2024 19:09:59 +0900 Subject: [PATCH 085/126] =?UTF-8?q?[fix]=20ConsumptionGoalResponse?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EA=B0=99=EC=9D=80=20=EA=B0=92=EC=9D=84=20?= =?UTF-8?q?=EA=B0=99=EB=8A=94=20=ED=95=84=EB=93=9C=EB=A5=BC=20ConsumptionG?= =?UTF-8?q?oalResponseList=EB=A1=9C=20=EC=B6=94=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/ConsumptionGoalResponseDto.java | 31 +------------------ .../dto/ConsumptionGoalResponseListDto.java | 7 +++-- 2 files changed, 6 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseDto.java index 304e83a5..bd8aca1b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseDto.java @@ -1,10 +1,5 @@ package com.bbteam.budgetbuddies.domain.consumptiongoal.dto; -import java.time.LocalDate; - -import com.bbteam.budgetbuddies.domain.category.entity.Category; -import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; - import lombok.Builder; import lombok.Getter; @@ -14,36 +9,12 @@ public class ConsumptionGoalResponseDto { private Long categoryId; private Long goalAmount; private Long consumeAmount; - private LocalDate goalMonth; @Builder - public ConsumptionGoalResponseDto(String categoryName, Long categoryId, Long goalAmount, Long consumeAmount, - LocalDate goalMonth) { + public ConsumptionGoalResponseDto(String categoryName, Long categoryId, Long goalAmount, Long consumeAmount) { this.categoryName = categoryName; this.categoryId = categoryId; this.goalAmount = goalAmount; this.consumeAmount = consumeAmount; - this.goalMonth = goalMonth; - } - - public static ConsumptionGoalResponseDto initializeFromCategoryAndGoalMonth(Category category, - LocalDate goalMonth) { - return ConsumptionGoalResponseDto.builder() - .categoryName(category.getName()) - .categoryId(category.getId()) - .goalAmount(0L) - .consumeAmount(0L) - .goalMonth(goalMonth) - .build(); - } - - public static ConsumptionGoalResponseDto of(ConsumptionGoal consumptionGoal) { - return ConsumptionGoalResponseDto.builder() - .categoryName(consumptionGoal.getCategory().getName()) - .categoryId(consumptionGoal.getCategory().getId()) - .goalAmount(consumptionGoal.getGoalAmount()) - .consumeAmount(consumptionGoal.getConsumeAmount()) - .goalMonth(consumptionGoal.getGoalMonth()) - .build(); } } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseListDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseListDto.java index a4f9f5b3..e7f5a54e 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseListDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalResponseListDto.java @@ -1,5 +1,6 @@ package com.bbteam.budgetbuddies.domain.consumptiongoal.dto; +import java.time.LocalDate; import java.util.List; import lombok.AccessLevel; @@ -9,9 +10,11 @@ @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) public class ConsumptionGoalResponseListDto { + private LocalDate goalMonth; private List consumptionGoalList; - public ConsumptionGoalResponseListDto(List consumptionGoalResponseDtoList) { - this.consumptionGoalList = consumptionGoalResponseDtoList; + public ConsumptionGoalResponseListDto(LocalDate goalMonth, List consumptionGoalList) { + this.goalMonth = goalMonth; + this.consumptionGoalList = consumptionGoalList; } } From 90093d93966bd61e9a31bf8fea49ecf7ee5c0f99 Mon Sep 17 00:00:00 2001 From: JunRain Date: Wed, 24 Jul 2024 19:10:37 +0900 Subject: [PATCH 086/126] =?UTF-8?q?[feat]=20ConsumptionGoalResponse?= =?UTF-8?q?=EC=9D=98=20Converter=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/ConsumptionGoalConverter.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionGoalConverter.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionGoalConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionGoalConverter.java new file mode 100644 index 00000000..a2c835cc --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionGoalConverter.java @@ -0,0 +1,28 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.converter; + +import org.springframework.stereotype.Component; + +import com.bbteam.budgetbuddies.domain.category.entity.Category; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseDto; +import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; + +@Component +public class ConsumptionGoalConverter { + public ConsumptionGoalResponseDto toConsumptionGoalResponseDto(Category category) { + return ConsumptionGoalResponseDto.builder() + .categoryName(category.getName()) + .categoryId(category.getId()) + .goalAmount(0L) + .consumeAmount(0L) + .build(); + } + + public ConsumptionGoalResponseDto toConsumptionGoalResponseDto(ConsumptionGoal consumptionGoal) { + return ConsumptionGoalResponseDto.builder() + .categoryName(consumptionGoal.getCategory().getName()) + .categoryId(consumptionGoal.getCategory().getId()) + .goalAmount(consumptionGoal.getGoalAmount()) + .consumeAmount(consumptionGoal.getConsumeAmount()) + .build(); + } +} From a38c4beaf363d4f0f45135179dd6b4943cfc8366 Mon Sep 17 00:00:00 2001 From: JunRain Date: Wed, 24 Jul 2024 19:11:07 +0900 Subject: [PATCH 087/126] =?UTF-8?q?[feat]=20ConsumptionGoalService?= =?UTF-8?q?=EC=97=90=20ConusmptionGoalConverter=EC=9D=98=EC=A1=B4=EC=84=B1?= =?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 --- .../service/ConsumptionGoalServiceImpl.java | 35 ++++++++++--------- .../service/ConsumptionGoalServiceTest.java | 19 ++++++---- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java index f9722314..4612b5bb 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java @@ -13,6 +13,7 @@ import com.bbteam.budgetbuddies.domain.category.entity.Category; import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; +import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.ConsumptionGoalConverter; import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.PeerInfoConverter; import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.TopCategoryConverter; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseDto; @@ -35,6 +36,8 @@ public class ConsumptionGoalServiceImpl implements ConsumptionGoalService { private final CategoryRepository categoryRepository; private final UserRepository userRepository; + private final ConsumptionGoalConverter consumptionGoalConverter; + private int peerAgeStart; private int peerAgeEnd; private Gender peerGender; @@ -53,17 +56,6 @@ public List getTopGoalCategories(int top, Long userI return topGoals.stream().map(TopCategoryConverter::fromEntity).collect(Collectors.toList()); } - @Override - public ConsumptionGoalResponseListDto findUserConsumptionGoal(Long userId, LocalDate date) { - LocalDate goalMonth = date.withDayOfMonth(1); - Map goalMap = initializeGoalMap(userId, goalMonth); - - updateGoalMapWithPreviousMonth(userId, goalMonth, goalMap); - updateGoalMapWithCurrentMonth(userId, goalMonth, goalMap); - - return new ConsumptionGoalResponseListDto(new ArrayList<>(goalMap.values())); - } - @Override @Transactional(readOnly = true) public PeerInfoResponseDTO getPeerInfo(Long userId, int peerAgeS, int peerAgeE, String peerG) { @@ -112,19 +104,28 @@ private void setAgeGroupByUser(int userAge) { } else if (userAge >= 29) { peerAgeStart = 29; peerAgeEnd = 99; - }else{ + } else { peerAgeStart = 0; peerAgeEnd = 19; } } + @Override + public ConsumptionGoalResponseListDto findUserConsumptionGoal(Long userId, LocalDate date) { + LocalDate goalMonth = date.withDayOfMonth(1); + Map goalMap = initializeGoalMap(userId, goalMonth); + + updateGoalMapWithPreviousMonth(userId, goalMonth, goalMap); + updateGoalMapWithCurrentMonth(userId, goalMonth, goalMap); + + return new ConsumptionGoalResponseListDto(goalMonth, new ArrayList<>(goalMap.values())); + } + private Map initializeGoalMap(Long userId, LocalDate goalMonth) { return categoryRepository.findUserCategoryByUserId(userId) .stream() - .collect(Collectors.toMap( - Category::getId, - category -> ConsumptionGoalResponseDto.initializeFromCategoryAndGoalMonth(category, goalMonth) - )); + .collect(Collectors.toMap(Category::getId, + category -> consumptionGoalConverter.toConsumptionGoalResponseDto(category))); } private void updateGoalMapWithPreviousMonth(Long userId, LocalDate goalMonth, @@ -140,7 +141,7 @@ private void updateGoalMapWithCurrentMonth(Long userId, LocalDate goalMonth, private void updateGoalMap(Long userId, LocalDate month, Map goalMap) { consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(userId, month) .stream() - .map(ConsumptionGoalResponseDto::of) + .map(consumptionGoalConverter::toConsumptionGoalResponseDto) .forEach(goal -> goalMap.put(goal.getCategoryId(), goal)); } } diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java index 7d7bec1b..07de6b8c 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java @@ -14,17 +14,20 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import com.bbteam.budgetbuddies.domain.category.entity.Category; import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; +import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.ConsumptionGoalConverter; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; import com.bbteam.budgetbuddies.domain.consumptiongoal.repository.ConsumptionGoalRepository; import com.bbteam.budgetbuddies.domain.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; -@DisplayName("ConsumptionGoal 테스트의 ") +@DisplayName("ConsumptionGoalImpl 서비스 테스트의 ") @ExtendWith(MockitoExtension.class) class ConsumptionGoalServiceTest { private final LocalDate GOAL_MONTH = LocalDate.of(2024, 07, 01); @@ -32,11 +35,15 @@ class ConsumptionGoalServiceTest { private LocalDate goalMonth; @InjectMocks - private ConsumptionGoalService consumptionGoalService; + private ConsumptionGoalServiceImpl consumptionGoalService; + @Mock + private ConsumptionGoalRepository consumptionGoalRepository; @Mock private CategoryRepository categoryRepository; @Mock - private ConsumptionGoalRepository consumptionGoalRepository; + private UserRepository userRepository; + @Spy + private ConsumptionGoalConverter consumptionGoalConverter; @BeforeEach void setUp() { @@ -63,7 +70,7 @@ void findUserConsumptionGoal_onlyCategory() { given(categoryRepository.findUserCategoryByUserId(user.getId())).willReturn(categoryList); List expected = categoryList.stream() - .map(category -> ConsumptionGoalResponseDto.initializeFromCategoryAndGoalMonth(category, GOAL_MONTH)) + .map(category -> consumptionGoalConverter.toConsumptionGoalResponseDto(category)) .toList(); // when @@ -109,7 +116,7 @@ void findUserConsumptionGoal_previousMonth() { GOAL_MONTH.minusMonths(1))).willReturn(previousGoalList); List expected = previousGoalList.stream() - .map(ConsumptionGoalResponseDto::of) + .map(consumptionGoalConverter::toConsumptionGoalResponseDto) .toList(); // when @@ -153,6 +160,6 @@ void findUserConsumptionGoal_previousMonthAndGoalMonth() { // then assertThat(result.getConsumptionGoalList()).usingRecursiveComparison() - .isEqualTo(List.of(ConsumptionGoalResponseDto.of(goalMonthUserCategoryGoal))); + .isEqualTo(List.of(consumptionGoalConverter.toConsumptionGoalResponseDto(goalMonthUserCategoryGoal))); } } \ No newline at end of file From 2acaf0bae044b67a45f77054295c9037ddb4ef11 Mon Sep 17 00:00:00 2001 From: ggamD00 Date: Thu, 25 Jul 2024 00:17:41 +0900 Subject: [PATCH 088/126] =?UTF-8?q?[fix]=20DockerFile=20=EB=B0=A9=EC=8B=9D?= =?UTF-8?q?=EC=97=90=EC=84=9C=20jib=20=EB=B0=A9=EC=8B=9D=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DockerFile | 11 ----------- build.gradle | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) delete mode 100644 DockerFile diff --git a/DockerFile b/DockerFile deleted file mode 100644 index b48c1483..00000000 --- a/DockerFile +++ /dev/null @@ -1,11 +0,0 @@ -# open jdk 17 버전의 환경을 구성한다. -FROM openjdk:17-alpine - -# build가 될 때 JAR_FILE이라는 변수 명에 build/libs/*.jar 선언 -# build/libs - gradle로 빌드했을 때 jar 파일이 생성되는 경로임 -ARG JAR_FILE=build/libs/*.jar - -# JAR_FILE을 agaproject.jar로 복사 (이 부분(.jar)은 개발환경에 따라 다름) -COPY ${JAR_FILE} app.jar - -ENTRYPOINT ["java", "-jar", "/app.jar"] \ No newline at end of file diff --git a/build.gradle b/build.gradle index 7c2d02cc..d219111f 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id 'java' id 'org.springframework.boot' version '3.2.7' id 'io.spring.dependency-management' version '1.1.5' + id 'com.google.cloud.tools.jib' version '3.4.1' } group = 'com.bbteam' @@ -38,3 +39,21 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + +jib { + from { + image = 'openjdk:17-alpine' + platforms { + platform { + architecture = 'amd64' + os = 'linux' + } + } + } + to { + image = 'binjumeoniz/binjumeoniz:latest' + } + container { + jvmFlags = ['-Dspring.profiles.active=dev'] + } +} From 75a0b9ca7a679237c2c87aa7f56a04cb7a342b45 Mon Sep 17 00:00:00 2001 From: ggamD00 Date: Thu, 25 Jul 2024 00:19:04 +0900 Subject: [PATCH 089/126] =?UTF-8?q?[fix]=20cicd=20workflow=20=EA=B0=84?= =?UTF-8?q?=EC=86=8C=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/gradle.yml | 140 +++++++++-------------------------- 1 file changed, 33 insertions(+), 107 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 4f1c13a1..7982d5eb 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -1,117 +1,43 @@ -name: CI/CD +name: server + -# 동작 조건 설정: release 브랜치에 push나 pull_request가 발생할 경우 동작한다. on: push: - branches: [ "dev" ] - pull_request: - branches: [ "dev" ] + branches: + - dev permissions: contents: read jobs: - CI-CD: + build: runs-on: ubuntu-latest - steps: - # JDK setting - github actions에서 사용할 JDK 설정 (aws 과 project의 java 버전과 별도로 관리) - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - - ## gradle caching (빌드 시간 줄이기) - - name: Gradle Caching - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- - - # 환경별 yml 파일 생성(1) - dev - - name: make application-dev.yml - if: contains(github.ref, 'develop') - run: | - cd ./src/main/resources - touch ./application.yml - echo "${{ secrets.YML }}" > ./application.yml - shell: bash - - # 환경별 yml 파일 생성(2) - prod - - name: make application-prod.yml - if: contains(github.ref, 'main') - run: | - cd ./src/main/resources - touch ./application.yml - echo "${{ secrets.YML }}" > ./application.yml - shell: bash - - # gradle chmod - - name: Grant execute permission for gradlew - run: chmod +x gradlew - # gradle build - - name: Build with Gradle - run: ./gradlew clean build -x test - - # docker login - - name: Docker Hub Login - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - # docker build & push to production - - name: Docker build & push to prod - if: contains(github.ref, 'main') - run: | - docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }}/binjumeoniz . - docker push ${{ secrets.DOCKER_REPO }}/binjumeoniz - - # docker build & push to develop - - name: Docker build & push to dev - if: contains(github.ref, 'develop') - run: | - docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }}/binjumeoniz . - docker push ${{ secrets.DOCKER_REPO }}/binjumeoniz - - ## deploy to production - - name: Deploy to prod - uses: appleboy/ssh-action@master - id: deploy-prod - if: contains(github.ref, 'main') - with: - host: ${{ secrets.HOST_PROD }} # EC2 퍼블릭 IPv4 DNS - username: ubuntu - key: ${{ secrets.PRIVATE_KEY }} - envs: GITHUB_SHA - script: | - sudo docker ps - sudo docker rm -f $(docker ps -qa) - sudo docker pull ${{ secrets.DOCKER_REPO }}/binjumeoniz - sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_REPO }}/binjumeoniz - sudo docker image prune -f -## ## sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_REPO }}/binjumeoniz - - ## deploy to develop - - name: Deploy to dev - uses: appleboy/ssh-action@master - id: deploy-dev - if: contains(github.ref, 'develop') - with: - host: ${{ secrets.HOST_DEV }} # EC2 퍼블릭 IPv4 DNS - username: ${{ secrets.USERNAME }} # ubuntu - password: ${{ secrets.PASSWORD }} - port: 22 - key: ${{ secrets.PRIVATE_KEY }} - script: | - sudo docker ps - sudo docker rm -f $(docker ps -qa) - sudo docker pull ${{ secrets.DOCKER_REPO }}/binjumeoniz - sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_REPO }}/binjumeoniz - sudo docker image prune -f + steps: + - uses: actions/checkoutc + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 17 + + - name : injection-yml + run : echo -E "${{ secrets.YML }}" > ./src/main/resources/application.yml + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Execute Gradle build and analyze + run: ./gradlew jib + + - name: Run scripts in server + uses: appleboy/ssh-action@master + with: + key: ${{ secrets.PRIVATE_KEY }} + host: ${{ secrets.HOST_DEV }} + username: ${{ secrets.USERNAME }} + script: ${{ secrets.SCRIPT }} From 1b278ad3183ff8fce008086f6d7efd30f047b10e Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 25 Jul 2024 01:27:01 +0900 Subject: [PATCH 090/126] =?UTF-8?q?[feat]=20=EB=AA=A9=ED=91=9C=20=EC=86=8C?= =?UTF-8?q?=EB=B9=84=EB=A5=BC=20=EC=88=98=EC=A0=95=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20RequestDto=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/ConsumptionGoalListRequestDto.java | 15 +++++++++++++++ .../dto/ConsumptionGoalRequestDto.java | 14 ++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalListRequestDto.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalRequestDto.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalListRequestDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalListRequestDto.java new file mode 100644 index 00000000..a74c986f --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalListRequestDto.java @@ -0,0 +1,15 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.dto; + +import java.util.List; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor +public class ConsumptionGoalListRequestDto { + List consumptionGoalList; +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalRequestDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalRequestDto.java new file mode 100644 index 00000000..da0463d7 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionGoalRequestDto.java @@ -0,0 +1,14 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.dto; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor +public class ConsumptionGoalRequestDto { + private Long categoryId; + private Long goalAmount; +} From 6bd28c2458abd8bb4807694604626b9d4671a2fb Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 25 Jul 2024 01:27:46 +0900 Subject: [PATCH 091/126] =?UTF-8?q?[feat]=20ConsumptionGoalRepository=20?= =?UTF-8?q?=EC=97=90=EC=84=9C=20user=20=EC=99=80=20category=EC=99=80=20loc?= =?UTF-8?q?aldate=EB=A1=9C=20Consumption=20=EC=A1=B0=ED=9A=8C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ConsumptionGoalRepository.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java index ea2b26b4..34220a0b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java @@ -2,13 +2,16 @@ import java.time.LocalDate; import java.util.List; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import com.bbteam.budgetbuddies.domain.category.entity.Category; import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; +import com.bbteam.budgetbuddies.domain.user.entity.User; import com.bbteam.budgetbuddies.enums.Gender; @Repository @@ -27,4 +30,7 @@ List findTopCategoriesAndGoalAmount( @Query(value = "SELECT cg FROM ConsumptionGoal AS cg WHERE cg.user.id = :userId AND cg.goalMonth = :goalMonth") List findConsumptionGoalByUserIdAndGoalMonth(Long userId, LocalDate goalMonth); + + Optional findConsumptionGoalByUserAndCategoryAndGoalMonth(User user, Category category, + LocalDate goalMonth); } \ No newline at end of file From 097e04b3527c7775fbf9b44decc40469adf6816d Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 25 Jul 2024 01:28:39 +0900 Subject: [PATCH 092/126] =?UTF-8?q?[feat]=20ConsumptionService=20=EC=86=8C?= =?UTF-8?q?=EB=B9=84=20=EB=AA=A9=ED=91=9C=EA=B0=80=20=EC=A1=B4=EC=9E=AC?= =?UTF-8?q?=ED=95=98=EB=A9=B4=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20?= =?UTF-8?q?=EC=A1=B4=EC=9E=AC=ED=95=98=EC=A7=80=20=EC=95=8A=EC=9C=BC?= =?UTF-8?q?=EB=A9=B4=20=EC=83=88=EB=A1=9C=20=EC=83=9D=EC=84=B1=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/ConsumptionGoal.java | 3 ++ .../service/ConsumptionGoalService.java | 4 ++ .../service/ConsumptionGoalServiceImpl.java | 44 +++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java index 70b6b434..dcbfa2b9 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java @@ -44,4 +44,7 @@ public class ConsumptionGoal extends BaseEntity { @JoinColumn(name = "category_id") private Category category; + public void updateGoalAmount(Long goalAmount) { + this.goalAmount = goalAmount; + } } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java index 5cafba0c..e647a0ec 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalService.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Service; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalListRequestDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.PeerInfoResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; @@ -18,4 +19,7 @@ List getTopGoalCategories(int top, Long userId, int ConsumptionGoalResponseListDto findUserConsumptionGoal(Long userId, LocalDate date); PeerInfoResponseDTO getPeerInfo(Long userId, int peerAgeStart, int peerAgeEnd, String peerGender); + + ConsumptionGoalResponseListDto updateConsumptionGoals(Long userId, + ConsumptionGoalListRequestDto consumptionGoalListRequestDto); } \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java index 4612b5bb..553bb514 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java @@ -16,6 +16,8 @@ import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.ConsumptionGoalConverter; import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.PeerInfoConverter; import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.TopCategoryConverter; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalListRequestDto; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalRequestDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.PeerInfoResponseDTO; @@ -111,6 +113,7 @@ private void setAgeGroupByUser(int userAge) { } @Override + @Transactional(readOnly = true) public ConsumptionGoalResponseListDto findUserConsumptionGoal(Long userId, LocalDate date) { LocalDate goalMonth = date.withDayOfMonth(1); Map goalMap = initializeGoalMap(userId, goalMonth); @@ -144,4 +147,45 @@ private void updateGoalMap(Long userId, LocalDate month, Map goalMap.put(goal.getCategoryId(), goal)); } + + @Override + @Transactional + public ConsumptionGoalResponseListDto updateConsumptionGoals(Long userId, + ConsumptionGoalListRequestDto consumptionGoalListRequestDto) { + LocalDate thisMonth = LocalDate.now().withDayOfMonth(1); + User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("Not found user")); + + List updatedConsumptionGoal = consumptionGoalListRequestDto.getConsumptionGoalList() + .stream() + .map(c -> updateConsumptionGoalWithRequestDto(user, c, thisMonth)) + .toList(); + + List response = consumptionGoalRepository.saveAll(updatedConsumptionGoal) + .stream() + .map(consumptionGoalConverter::toConsumptionGoalResponseDto) + .toList(); + + return new ConsumptionGoalResponseListDto(thisMonth, response); + } + + private ConsumptionGoal updateConsumptionGoalWithRequestDto(User user, + ConsumptionGoalRequestDto consumptionGoalRequestDto, LocalDate goalMonth) { + + Category category = categoryRepository.findById(consumptionGoalRequestDto.getCategoryId()) + .orElseThrow(() -> new IllegalArgumentException("Not found Category")); + + ConsumptionGoal consumptionGoal = findOrElseGenerateConsumptionGoal(user, category, goalMonth); + consumptionGoal.updateGoalAmount(consumptionGoalRequestDto.getGoalAmount()); + + return consumptionGoal; + } + + private ConsumptionGoal findOrElseGenerateConsumptionGoal(User user, Category category, LocalDate goalMonth) { + return consumptionGoalRepository.findConsumptionGoalByUserAndCategoryAndGoalMonth(user, category, goalMonth) + .orElseGet(() -> generateConsumptionGoal(user, category, goalMonth)); + } + + private ConsumptionGoal generateConsumptionGoal(User user, Category category, LocalDate goalMonth) { + return ConsumptionGoal.builder().goalMonth(goalMonth).user(user).category(category).consumeAmount(0L).build(); + } } From 5365ce7490286ed88411525879e18ca4c09b9d03 Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 25 Jul 2024 01:28:59 +0900 Subject: [PATCH 093/126] =?UTF-8?q?[feat]=20ConsumptionServiceTest=20?= =?UTF-8?q?=EC=86=8C=EB=B9=84=20=EB=AA=A9=ED=91=9C=EA=B0=80=20=EC=A1=B4?= =?UTF-8?q?=EC=9E=AC=ED=95=98=EB=A9=B4=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EC=A1=B4=EC=9E=AC=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=9C=BC=EB=A9=B4=20=EC=83=88=EB=A1=9C=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalServiceTest.java | 84 +++++++++++++++++-- 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java index 07de6b8c..261e25f9 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java @@ -5,6 +5,7 @@ import java.time.LocalDate; import java.util.List; +import java.util.Optional; import java.util.Random; import org.junit.jupiter.api.BeforeEach; @@ -20,6 +21,8 @@ import com.bbteam.budgetbuddies.domain.category.entity.Category; import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.ConsumptionGoalConverter; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalListRequestDto; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalRequestDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; @@ -32,7 +35,7 @@ class ConsumptionGoalServiceTest { private final LocalDate GOAL_MONTH = LocalDate.of(2024, 07, 01); private User user; - private LocalDate goalMonth; + private LocalDate goalMonthRandomDay; @InjectMocks private ConsumptionGoalServiceImpl consumptionGoalService; @@ -49,10 +52,11 @@ class ConsumptionGoalServiceTest { void setUp() { Random random = new Random(); int randomDay = random.nextInt(30) + 1; - goalMonth = LocalDate.of(GOAL_MONTH.getYear(), GOAL_MONTH.getMonth(), randomDay); + goalMonthRandomDay = LocalDate.of(GOAL_MONTH.getYear(), GOAL_MONTH.getMonth(), randomDay); user = Mockito.spy(User.builder().email("email").age(24).name("name").phoneNumber("010-1234-5678").build()); given(user.getId()).willReturn(-1L); + given(userRepository.findById(user.getId())).willReturn(Optional.ofNullable(user)); } @Test @@ -74,7 +78,8 @@ void findUserConsumptionGoal_onlyCategory() { .toList(); // when - ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoal(user.getId(), goalMonth); + ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoal(user.getId(), + goalMonthRandomDay); // then assertThat(result.getConsumptionGoalList()).usingRecursiveComparison().isEqualTo(expected); @@ -98,7 +103,7 @@ void findUserConsumptionGoal_previousMonth() { .consumeAmount(20_000L) .user(user) .category(defaultCategory) - .goalMonth(goalMonth.minusMonths(1)) + .goalMonth(goalMonthRandomDay.minusMonths(1)) .build(); ConsumptionGoal previousMonthUserCategoryGoal = ConsumptionGoal.builder() @@ -106,7 +111,7 @@ void findUserConsumptionGoal_previousMonth() { .consumeAmount(20_000L) .user(user) .category(userCategory) - .goalMonth(goalMonth.minusMonths(1)) + .goalMonth(goalMonthRandomDay.minusMonths(1)) .build(); List previousGoalList = List.of(previousMonthDefaultCategoryGoal, @@ -120,7 +125,8 @@ void findUserConsumptionGoal_previousMonth() { .toList(); // when - ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoal(user.getId(), goalMonth); + ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoal(user.getId(), + goalMonthRandomDay); // then assertThat(result.getConsumptionGoalList()).usingRecursiveComparison().isEqualTo(expected); @@ -138,7 +144,7 @@ void findUserConsumptionGoal_previousMonthAndGoalMonth() { .consumeAmount(20_000L) .user(user) .category(userCategory) - .goalMonth(goalMonth.minusMonths(1)) + .goalMonth(goalMonthRandomDay.minusMonths(1)) .build(); ConsumptionGoal goalMonthUserCategoryGoal = ConsumptionGoal.builder() @@ -146,7 +152,7 @@ void findUserConsumptionGoal_previousMonthAndGoalMonth() { .consumeAmount(30_000L) .user(user) .category(userCategory) - .goalMonth(goalMonth) + .goalMonth(goalMonthRandomDay) .build(); given(consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(user.getId(), @@ -156,10 +162,70 @@ void findUserConsumptionGoal_previousMonthAndGoalMonth() { List.of(goalMonthUserCategoryGoal)); // when - ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoal(user.getId(), goalMonth); + ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoal(user.getId(), + goalMonthRandomDay); // then assertThat(result.getConsumptionGoalList()).usingRecursiveComparison() .isEqualTo(List.of(consumptionGoalConverter.toConsumptionGoalResponseDto(goalMonthUserCategoryGoal))); } + + @Test + @DisplayName("updateConsumptionGoal : 이번달 목표가 있는 경우(defaultCategory)와 목표가 없는 경우(userCategory)") + void updateConsumptionGoal_Success() { + // given + Long defaultGoalAmount = 100L; + Long userGoalAmount = 200L; + + ConsumptionGoalListRequestDto request = new ConsumptionGoalListRequestDto( + List.of(new ConsumptionGoalRequestDto(-1L, defaultGoalAmount), + new ConsumptionGoalRequestDto(-2L, userGoalAmount))); + + Category defaultCategory = Mockito.spy(Category.builder().name("디폴트 카테고리").user(null).isDefault(true).build()); + given(defaultCategory.getId()).willReturn(-1L); + given(categoryRepository.findById(defaultCategory.getId())).willReturn(Optional.of(defaultCategory)); + + Category userCategory = Mockito.spy(Category.builder().name("유저 카테고리").user(user).isDefault(false).build()); + given(userCategory.getId()).willReturn(-2L); + given(categoryRepository.findById(userCategory.getId())).willReturn(Optional.of(userCategory)); + + ConsumptionGoal defaultCategoryGoal = ConsumptionGoal.builder() + .goalAmount(1_000_000L) + .consumeAmount(20_000L) + .user(user) + .category(defaultCategory) + .goalMonth(GOAL_MONTH) + .build(); + given(consumptionGoalRepository.findConsumptionGoalByUserAndCategoryAndGoalMonth(user, defaultCategory, + GOAL_MONTH)).willReturn(Optional.ofNullable(defaultCategoryGoal)); + + given(consumptionGoalRepository.findConsumptionGoalByUserAndCategoryAndGoalMonth(user, userCategory, + GOAL_MONTH)).willReturn(Optional.ofNullable(null)); + + when(consumptionGoalRepository.saveAll(any())).thenAnswer(invocation -> { + List goalsToSave = invocation.getArgument(0); + return goalsToSave; + }); + + List expected = List.of( + ConsumptionGoalResponseDto.builder() + .goalAmount(defaultGoalAmount) + .consumeAmount(defaultCategoryGoal.getConsumeAmount()) + .categoryName(defaultCategory.getName()) + .categoryId(defaultCategory.getId()) + .build(), + ConsumptionGoalResponseDto.builder() + .goalAmount(userGoalAmount) + .consumeAmount(0L) + .categoryName(userCategory.getName()) + .categoryId(userCategory.getId()) + .build() + ); + + // when + ConsumptionGoalResponseListDto result = consumptionGoalService.updateConsumptionGoals(user.getId(), request); + + // then + assertThat(result.getConsumptionGoalList()).usingRecursiveComparison().isEqualTo(expected); + } } \ No newline at end of file From 0e778a0919911c713802c4fff0d5f01e096aeb65 Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 25 Jul 2024 01:29:30 +0900 Subject: [PATCH 094/126] =?UTF-8?q?[feat]=20ConsumptionController=20?= =?UTF-8?q?=EC=86=8C=EB=B9=84=20=EB=AA=A9=ED=91=9C=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ConsumptionGoalController.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java index 1d7e59e9..0e1120a9 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java @@ -7,10 +7,13 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalListRequestDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.PeerInfoResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; @@ -32,8 +35,7 @@ public class ConsumptionGoalController { @Operation(summary = "또래들이 가장 큰 계획을 세운 카테고리 조회 API", description = "특정 사용자의 소비 목표 카테고리별 소비 목표 금액을 조회하는 API 입니다.") @ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")}) - @Parameters({ - @Parameter(name = "top", description = "가장 큰 목표를 세운 카테고리의 개수를 지정합니다. (기본값은 5입니다)"), + @Parameters({@Parameter(name = "top", description = "가장 큰 목표를 세운 카테고리의 개수를 지정합니다. (기본값은 5입니다)"), @Parameter(name = "userId", description = "로그인 한 유저 아이디"), @Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"), @Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"), @@ -60,8 +62,7 @@ public ResponseEntity findUserConsumptionGoal( @Operation(summary = "또래나이와 성별 조회 API", description = "또래나이와 성별을 조회하는 API 입니다.") @ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")}) - @Parameters({ - @Parameter(name = "userId", description = "로그인 한 유저 아이디"), + @Parameters({@Parameter(name = "userId", description = "로그인 한 유저 아이디"), @Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"), @Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"), @Parameter(name = "peerGender", description = "또래 성별")}) @@ -74,4 +75,11 @@ public ResponseEntity getPeerInfo(@RequestParam(name = "userId") Long userId, return ResponseEntity.ok(response); } + @PostMapping("/{userId}") + public ResponseEntity updateOrElseGenerateConsumptionGoal(@PathVariable Long userId, + @RequestBody ConsumptionGoalListRequestDto consumptionGoalListRequestDto) { + + return ResponseEntity.ok() + .body(consumptionGoalService.updateConsumptionGoals(userId, consumptionGoalListRequestDto)); + } } \ No newline at end of file From 40d9462eafd31ea778a56762074c6be732b3d738 Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 25 Jul 2024 01:54:24 +0900 Subject: [PATCH 095/126] =?UTF-8?q?[fix]=20ConsumptionGoalEntity=200=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EA=B8=88=EC=A7=80=20=EC=A0=9C=EC=95=BD?= =?UTF-8?q?=EC=A1=B0=EA=B1=B4=20=EC=9D=8C=EC=88=98=EB=A7=8C=20=EC=95=88?= =?UTF-8?q?=EB=90=98=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/consumptiongoal/entity/ConsumptionGoal.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java index dcbfa2b9..a0df97bc 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java @@ -26,11 +26,11 @@ public class ConsumptionGoal extends BaseEntity { @Column(nullable = false) - @Min(value = 1, message = "0 또는 음수의 목표금액을 설정할 수 없습니다.") + @Min(value = 0, message = "음수의 목표금액을 설정할 수 없습니다.") private Long goalAmount; @Column(nullable = false) - @Min(value = 1, message = "0 또는 음수의 소비금액을 설정할 수 없습니다.") + @Min(value = 0, message = "음수의 소비금액을 설정할 수 없습니다.") private Long consumeAmount; @Column(nullable = false) From 82a6c74c2615d7aef8a9d85ed87a211e58b67111 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 11:51:59 +0900 Subject: [PATCH 096/126] =?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 097/126] =?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 098/126] =?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 099/126] =?UTF-8?q?[feat]=20CommentService=20paging=20meth?= =?UTF-8?q?od=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 100/126] =?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 101/126] =?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 102/126] =?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 103/126] =?UTF-8?q?[refactor]=20CommentConverter=20anonymo?= =?UTF-8?q?us=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=A5=B8=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=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 --- .../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 104/126] =?UTF-8?q?[refactor]=20anonymousNumber=20type=20L?= =?UTF-8?q?ong=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 105/126] =?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 2a125413d79ef08202d75223977b35b2ee5d49a8 Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 25 Jul 2024 14:09:17 +0900 Subject: [PATCH 106/126] =?UTF-8?q?ConsumptionGoalController=EC=9D=98=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=EA=B3=BC=20Swagger=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=EC=9D=84=20=EC=9D=B8=ED=84=B0=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ConsumptionGoalApi.java | 43 +++++++++++++++++++ .../controller/ConsumptionGoalController.java | 20 +-------- 2 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalApi.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalApi.java new file mode 100644 index 00000000..c13498b5 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalApi.java @@ -0,0 +1,43 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.controller; + +import java.time.LocalDate; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestParam; + +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalListRequestDto; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; + +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.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; + +public interface ConsumptionGoalApi { + @Operation(summary = "또래들이 가장 큰 계획을 세운 카테고리 조회 API", description = "특정 사용자의 소비 목표 카테고리별 소비 목표 금액을 조회하는 API 입니다.") + @ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")}) + @Parameters({@Parameter(name = "top", description = "가장 큰 목표를 세운 카테고리의 개수를 지정합니다. (기본값은 5입니다)"), + @Parameter(name = "userId", description = "로그인 한 유저 아이디"), + @Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"), + @Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"), + @Parameter(name = "peerGender", description = "또래 성별")}) + ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaultValue = "5") int top, Long userId, + int peerAgeStart, int peerAgeEnd, String peerGender); + + @Operation(summary = "소비 목표 조회 API", description = "date={yyyy-MM-dd} 형식의 query string을 통해서 사용자의 목표 달을 조회하는 API 입니다.") + @Parameters({@Parameter(name = "date", description = "yyyy-MM-dd 형식으로 목표 달의 소비를 조회")}) + ResponseEntity findUserConsumptionGoal(LocalDate date, Long userId); + + @Operation(summary = "또래나이와 성별 조회 API", description = "또래나이와 성별을 조회하는 API 입니다.") + @ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")}) + @Parameters({@Parameter(name = "userId", description = "로그인 한 유저 아이디"), + @Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"), + @Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"), + @Parameter(name = "peerGender", description = "또래 성별")}) + ResponseEntity getPeerInfo(Long userId, int peerAgeStart, int peerAgeEnd, String peerGender); + + @Operation(summary = "이번 달 소비 목표 수정 API", description = "다른 달의 소비 목표를 업데이트하는 것은 불가능하고 오직 이번 달의 소비 목표만 업데이트 하는 API 입니다.") + ResponseEntity updateOrElseGenerateConsumptionGoal(Long userId, + ConsumptionGoalListRequestDto consumptionGoalListRequestDto); +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java index 0e1120a9..53c9330f 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalController.java @@ -19,27 +19,15 @@ import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.service.ConsumptionGoalService; -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.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import lombok.RequiredArgsConstructor; @RestController @RequiredArgsConstructor @RequestMapping("/consumption-goal") -public class ConsumptionGoalController { +public class ConsumptionGoalController implements ConsumptionGoalApi { private final ConsumptionGoalService consumptionGoalService; - @Operation(summary = "또래들이 가장 큰 계획을 세운 카테고리 조회 API", description = "특정 사용자의 소비 목표 카테고리별 소비 목표 금액을 조회하는 API 입니다.") - @ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")}) - @Parameters({@Parameter(name = "top", description = "가장 큰 목표를 세운 카테고리의 개수를 지정합니다. (기본값은 5입니다)"), - @Parameter(name = "userId", description = "로그인 한 유저 아이디"), - @Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"), - @Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"), - @Parameter(name = "peerGender", description = "또래 성별")}) @GetMapping("/top-categories") public ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaultValue = "5") int top, @RequestParam(name = "userId") Long userId, @@ -60,12 +48,6 @@ public ResponseEntity findUserConsumptionGoal( return ResponseEntity.ok(response); } - @Operation(summary = "또래나이와 성별 조회 API", description = "또래나이와 성별을 조회하는 API 입니다.") - @ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")}) - @Parameters({@Parameter(name = "userId", description = "로그인 한 유저 아이디"), - @Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"), - @Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"), - @Parameter(name = "peerGender", description = "또래 성별")}) @GetMapping("/peer-info") public ResponseEntity getPeerInfo(@RequestParam(name = "userId") Long userId, @RequestParam(name = "peerAgeStart", defaultValue = "0") int peerAgeStart, From 66ee00944e4e5a304fcbf6ac832f6032953f47e3 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 14:36:33 +0900 Subject: [PATCH 107/126] =?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 108/126] =?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 109/126] =?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 110/126] =?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 111/126] =?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 112/126] =?UTF-8?q?[refactor]=20Dto=EA=B0=80=20commentId?= =?UTF-8?q?=20=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 d2211b527ce41fc2a6dec9da8e74b3c6edac11b3 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Thu, 25 Jul 2024 18:36:04 +0900 Subject: [PATCH 113/126] =?UTF-8?q?[refactor]=20BaseEntity=EC=97=90=20@Get?= =?UTF-8?q?ter=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..912b0a22 100644 --- a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java +++ b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java @@ -19,6 +19,7 @@ @MappedSuperclass @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor +@Getter @SuperBuilder @SoftDelete // boolean 타입의 deleted 필드가 추가 public abstract class BaseEntity { From 71fe910b47ef1f27f0bf2978f2bf708dc0a291d6 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Thu, 25 Jul 2024 18:36:21 +0900 Subject: [PATCH 114/126] =?UTF-8?q?[feat]=20Dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/expense/dto/ExpenseRequestDto.java | 20 ++++++++++++++++++ .../expense/dto/ExpenseResponseDto.java | 21 +++++++++++++++++++ .../domain/expense/dto/package-info.java | 1 - 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseRequestDto.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseResponseDto.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/package-info.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseRequestDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseRequestDto.java new file mode 100644 index 00000000..680be344 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseRequestDto.java @@ -0,0 +1,20 @@ +package com.bbteam.budgetbuddies.domain.expense.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ExpenseRequestDto { + private Long userId; + private Long categoryId; + private Long amount; + private String description; + private LocalDateTime expenseDate; +} \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseResponseDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseResponseDto.java new file mode 100644 index 00000000..79b74cf6 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseResponseDto.java @@ -0,0 +1,21 @@ +package com.bbteam.budgetbuddies.domain.expense.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ExpenseResponseDto { + private Long expenseId; + private Long userId; + private Long categoryId; + private Long amount; + private String description; + private LocalDateTime expenseDate; +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/package-info.java deleted file mode 100644 index cd54ca0d..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.expense.dto; \ No newline at end of file From 0cbb506a57822936fc6922bb143d2ebe6aa9c129 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Thu, 25 Jul 2024 18:37:03 +0900 Subject: [PATCH 115/126] =?UTF-8?q?[feat]=20ExpenseService=20=EC=9D=B8?= =?UTF-8?q?=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/expense/service/ExpenseService.java | 8 ++++++++ .../domain/expense/service/package-info.java | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseService.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/service/package-info.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseService.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseService.java new file mode 100644 index 00000000..7eaacf94 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseService.java @@ -0,0 +1,8 @@ +package com.bbteam.budgetbuddies.domain.expense.service; + +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseRequestDto; +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; + +public interface ExpenseService { + ExpenseResponseDto createExpense(ExpenseRequestDto expenseRequestDto); +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/package-info.java deleted file mode 100644 index ece79aae..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.expense.service; \ No newline at end of file From a25036752511af21be33ce1c2155e721621433e5 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Thu, 25 Jul 2024 19:20:35 +0900 Subject: [PATCH 116/126] =?UTF-8?q?[feat]=20ExpenseRepository=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 --- .../expense/repository/ExpenseRepository.java | 16 ++++++++++++++++ .../domain/expense/repository/package-info.java | 1 - 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/repository/ExpenseRepository.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/repository/package-info.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/repository/ExpenseRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/repository/ExpenseRepository.java new file mode 100644 index 00000000..9799aaaa --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/repository/ExpenseRepository.java @@ -0,0 +1,16 @@ +package com.bbteam.budgetbuddies.domain.expense.repository; + +import com.bbteam.budgetbuddies.domain.expense.entity.Expense; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; + +public interface ExpenseRepository extends JpaRepository { + @Query("SELECT e FROM Expense e WHERE e.user.id = :userId AND e.category.id = :categoryId") + List findByUserIdAndCategoryId(@Param("userId") Long userId, @Param("categoryId") Long categoryId); + + @Query("SELECT e FROM Expense e WHERE e.user.id = :userId") + List findByUserId(@Param("userId") Long userId); +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/repository/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/repository/package-info.java deleted file mode 100644 index c5184ef7..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/repository/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.expense.repository; \ No newline at end of file From ac9973714c99903a2051a02d298167ce5143ce3f Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Thu, 25 Jul 2024 19:21:15 +0900 Subject: [PATCH 117/126] =?UTF-8?q?[feat]=20ExpenseConverter=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 --- .../expense/converter/ExpenseConverter.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/converter/ExpenseConverter.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/converter/ExpenseConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/converter/ExpenseConverter.java new file mode 100644 index 00000000..ac88217c --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/converter/ExpenseConverter.java @@ -0,0 +1,34 @@ +package com.bbteam.budgetbuddies.domain.expense.converter; + +import com.bbteam.budgetbuddies.domain.category.entity.Category; +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseRequestDto; +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; +import com.bbteam.budgetbuddies.domain.expense.entity.Expense; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import org.springframework.stereotype.Component; + +@Component +public class ExpenseConverter { + + public Expense toExpenseEntity(ExpenseRequestDto expenseRequestDto, User user, Category category) { + return Expense.builder() + .user(user) + .category(category) + .amount(expenseRequestDto.getAmount()) + .description(expenseRequestDto.getDescription()) + .expenseDate(expenseRequestDto.getExpenseDate()) + .build(); + } + + public ExpenseResponseDto toExpenseResponseDto(Expense expense) { + return ExpenseResponseDto.builder() + .expenseId(expense.getId()) + .userId(expense.getUser().getId()) + .categoryId(expense.getCategory().getId()) + .amount(expense.getAmount()) + .description(expense.getDescription()) + .expenseDate(expense.getExpenseDate()) + .build(); + } +} + From a735f2c79f204f90a5147eb5e54e9127c8ea7274 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Thu, 25 Jul 2024 19:23:18 +0900 Subject: [PATCH 118/126] =?UTF-8?q?[docs]=20ExpenseRepository=20=EC=A3=BC?= =?UTF-8?q?=EC=84=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/expense/repository/ExpenseRepository.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/repository/ExpenseRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/repository/ExpenseRepository.java index 9799aaaa..c846f92e 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/repository/ExpenseRepository.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/repository/ExpenseRepository.java @@ -8,6 +8,8 @@ import java.util.List; public interface ExpenseRepository extends JpaRepository { + + // 추후 적용 예정 @Query("SELECT e FROM Expense e WHERE e.user.id = :userId AND e.category.id = :categoryId") List findByUserIdAndCategoryId(@Param("userId") Long userId, @Param("categoryId") Long categoryId); From 4c2ece0b78a971f33228cbf286754f18fb6546b0 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Thu, 25 Jul 2024 19:27:15 +0900 Subject: [PATCH 119/126] =?UTF-8?q?[feat]=20ExpenseController=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 --- .../expense/controller/ExpenseController.java | 37 +++++++++++++++++++ .../expense/controller/package-info.java | 1 - 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/package-info.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java new file mode 100644 index 00000000..159c6fc9 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java @@ -0,0 +1,37 @@ +package com.bbteam.budgetbuddies.domain.expense.controller; + +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseRequestDto; +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; +import com.bbteam.budgetbuddies.domain.expense.service.ExpenseService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/expenses") +public class ExpenseController { + + private final ExpenseService expenseService; + + @Operation(summary = "소비 내역 추가", description = "사용자가 소비 내역을 추가합니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) + }) + @PostMapping("/add") + public ResponseEntity createExpense( + @Parameter(description = "user_id, category_id, amount, description, expenseDate") + @RequestBody ExpenseRequestDto expenseRequestDto) { + ExpenseResponseDto response = expenseService.createExpense(expenseRequestDto); + return ResponseEntity.ok(response); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/package-info.java deleted file mode 100644 index cd648f5a..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.expense.controller; \ No newline at end of file From b3b7fe499c68a18b7c641d6e312b29f61a29f6b1 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Thu, 25 Jul 2024 19:27:41 +0900 Subject: [PATCH 120/126] =?UTF-8?q?[feat]=20ExpenseService,=20Impl=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../expense/service/ExpenseService.java | 3 ++ .../expense/service/ExpenseServiceImpl.java | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseService.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseService.java index 7eaacf94..cbcddb72 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseService.java @@ -2,6 +2,9 @@ import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseRequestDto; import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; +import com.bbteam.budgetbuddies.domain.category.dto.CategoryResponseDTO; + +import java.util.List; public interface ExpenseService { ExpenseResponseDto createExpense(ExpenseRequestDto expenseRequestDto); diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java new file mode 100644 index 00000000..b4675ebe --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java @@ -0,0 +1,36 @@ +package com.bbteam.budgetbuddies.domain.expense.service; + +import com.bbteam.budgetbuddies.domain.category.entity.Category; +import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; +import com.bbteam.budgetbuddies.domain.expense.converter.ExpenseConverter; +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseRequestDto; +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; +import com.bbteam.budgetbuddies.domain.expense.entity.Expense; +import com.bbteam.budgetbuddies.domain.expense.repository.ExpenseRepository; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ExpenseServiceImpl implements ExpenseService { + + private final ExpenseRepository expenseRepository; + private final UserRepository userRepository; + private final CategoryRepository categoryRepository; + private final ExpenseConverter expenseConverter; + + @Override + public ExpenseResponseDto createExpense(ExpenseRequestDto expenseRequestDto) { + User user = userRepository.findById(expenseRequestDto.getUserId()) + .orElseThrow(() -> new IllegalArgumentException("Invalid user ID")); + Category category = categoryRepository.findById(expenseRequestDto.getCategoryId()) + .orElseThrow(() -> new IllegalArgumentException("Invalid category ID")); + + Expense expense = expenseConverter.toExpenseEntity(expenseRequestDto, user, category); + expenseRepository.save(expense); + + return expenseConverter.toExpenseResponseDto(expense); + } +} From ffde7fb1e9e04176af93345dead09575204f736f Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 25 Jul 2024 21:56:01 +0900 Subject: [PATCH 121/126] =?UTF-8?q?[refactor]=20CommentController=20Interf?= =?UTF-8?q?ace=20=EB=B6=84=EB=A6=AC=EB=A1=9C=20Swagger=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=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 122/126] =?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 123/126] =?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 124/126] =?UTF-8?q?[refactor]=20=ED=95=84=EC=97=AC?= =?UTF-8?q?=EC=97=86=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; From f3842efb8b0c70c024eeacaf26747f20ce85b98d Mon Sep 17 00:00:00 2001 From: ggamD00 Date: Thu, 25 Jul 2024 22:45:08 +0900 Subject: [PATCH 125/126] =?UTF-8?q?[fix]=20jib,=20=EB=8F=84=EC=BB=A4?= =?UTF-8?q?=ED=97=88=EB=B8=8C=20userName=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index d219111f..f2596c13 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'java' id 'org.springframework.boot' version '3.2.7' id 'io.spring.dependency-management' version '1.1.5' - id 'com.google.cloud.tools.jib' version '3.4.1' + id 'com.google.cloud.tools.jib' version '3.4.3' } group = 'com.bbteam' @@ -51,7 +51,7 @@ jib { } } to { - image = 'binjumeoniz/binjumeoniz:latest' + image = 'binjumeoniz1/binjumeoniz:latest' } container { jvmFlags = ['-Dspring.profiles.active=dev'] From 8c9c1ce8ca89df1d63765b834bfaa2502bd27f6d Mon Sep 17 00:00:00 2001 From: ggamD00 Date: Thu, 25 Jul 2024 22:45:51 +0900 Subject: [PATCH 126/126] =?UTF-8?q?[feat]=20application.yml=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80=20=EB=B0=8F?= =?UTF-8?q?=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/gradle.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 7982d5eb..d6b47f1f 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkoutc + - uses: actions/checkout@v2 - name: Set up JDK 17 uses: actions/setup-java@v3 @@ -22,6 +22,9 @@ jobs: distribution: temurin java-version: 17 + - name: Ensure resource directory exists + run: mkdir -p ./src/main/resources + - name : injection-yml run : echo -E "${{ secrets.YML }}" > ./src/main/resources/application.yml @@ -40,4 +43,4 @@ jobs: key: ${{ secrets.PRIVATE_KEY }} host: ${{ secrets.HOST_DEV }} username: ${{ secrets.USERNAME }} - script: ${{ secrets.SCRIPT }} + script: ${{ secrets.SCRIPT }} \ No newline at end of file