From c0e18df6b2ccdc80bc3594ee541cd7028921a790 Mon Sep 17 00:00:00 2001 From: JeongJun Min <41982054+m3k0813@users.noreply.github.com> Date: Sun, 14 Jul 2024 15:23:53 +0900 Subject: [PATCH 001/307] [chore] Update issue templates Update issue templates --- .github/ISSUE_TEMPLATE/bugfix.md | 19 +++++++++++++++++++ .github/ISSUE_TEMPLATE/feature.md | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bugfix.md create mode 100644 .github/ISSUE_TEMPLATE/feature.md diff --git a/.github/ISSUE_TEMPLATE/bugfix.md b/.github/ISSUE_TEMPLATE/bugfix.md new file mode 100644 index 00000000..6a2eee51 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bugfix.md @@ -0,0 +1,19 @@ +--- +name: BugFix +about: 오류 해결 과정 기록 +title: '' +labels: ":hammer_and_wrench: fix" +assignees: '' + +--- + +## 💡Description +> description + +## ✅ To Do List +- [ ] todo1 +- [ ] todo2 +- [ ] todo3 + +## Etc +> etc diff --git a/.github/ISSUE_TEMPLATE/feature.md b/.github/ISSUE_TEMPLATE/feature.md new file mode 100644 index 00000000..a0185ef2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature.md @@ -0,0 +1,19 @@ +--- +name: Feature +about: 기능구현, 리팩토링, 환경설정 등을 포함한 기본 템플릿 +title: '' +labels: '' +assignees: '' + +--- + +## 💡Description +> description + +## ✅ To Do List +- [ ] todo1 +- [ ] todo2 +- [ ] todo3 + +## Etc +> etc From 0834f82d9432913b637a7895e61fd8eda91ab7b5 Mon Sep 17 00:00:00 2001 From: MJJ Date: Sun, 14 Jul 2024 15:32:36 +0900 Subject: [PATCH 002/307] [chore] Update pull request templates --- .github/pull_request_template.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..5100ca11 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,22 @@ +## 개요 + + +## PR +어떤 변경 사항이 있나요? + +- [ ] 새로운 기능 추가 +- [ ] 버그 수정 +- [ ] 문서 수정 +- [ ] 코드 포맷 변경, 세미콜론 누락, 코드 수정이 없는경우 +- [ ] 코드 리팩토링 +- [ ] 테스트 추가, 테스트 리팩토링 +- [ ] 빌드 수정, 패키지 매니저 수정 +- [ ] 파일, 폴더명 수정 +- [ ] 파일, 폴더 삭제 + +## Checklist + +- [ ] 커밋 메시지 컨벤션에 맞게 작성했습니다. +- [ ] 변경 사항에 대한 테스트를 했습니다. +- [ ] 필요 없는 import문이나 setter 등을 삭제했습니다. +- [ ] 기존의 코드에 영향이 없는 것을 확인했습니다. From 443fd27fbb02b1a5b3bb0b31ce14d65b6157cb8e Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:54:45 +0900 Subject: [PATCH 003/307] =?UTF-8?q?[feat]=20Validation=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 04faf557..aaccf0ac 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,7 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-validation' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' From 3b8d08d0281577b3e89a94cdf628c05145476c9f Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:55:05 +0900 Subject: [PATCH 004/307] =?UTF-8?q?[feat]=20@EnableJpaAuditing=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 --- .../java/com/bbteam/budgetbuddies/BudgetbuddiesApplication.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/BudgetbuddiesApplication.java b/src/main/java/com/bbteam/budgetbuddies/BudgetbuddiesApplication.java index d8af9893..42ea116f 100644 --- a/src/main/java/com/bbteam/budgetbuddies/BudgetbuddiesApplication.java +++ b/src/main/java/com/bbteam/budgetbuddies/BudgetbuddiesApplication.java @@ -2,8 +2,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @SpringBootApplication +@EnableJpaAuditing public class BudgetbuddiesApplication { public static void main(String[] args) { From b697ed7c7fe54d6c3c9f18370ea914956b88ad35 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:55:46 +0900 Subject: [PATCH 005/307] =?UTF-8?q?[feat]=20DB=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 각자 로컬에 DB 서버 생성 후 매핑 --- src/main/resources/application.properties | 1 - src/main/resources/application.yaml | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) delete mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/application.yaml diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 47d8feca..00000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=budgetbuddies diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml new file mode 100644 index 00000000..d7740288 --- /dev/null +++ b/src/main/resources/application.yaml @@ -0,0 +1,17 @@ +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 7351a0a08c8655461ce65862a2004810d5d688b3 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:56:51 +0900 Subject: [PATCH 006/307] =?UTF-8?q?[feat]=20BaseEntity=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 id, createdAt, updatedAt, deleted 공통 사용 --- .../budgetbuddies/common/BaseEntity.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java diff --git a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java new file mode 100644 index 00000000..e743a0e2 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java @@ -0,0 +1,35 @@ +package com.bbteam.budgetbuddies.common; + +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.SoftDelete; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.LocalDateTime; + +@EntityListeners(AuditingEntityListener.class) +@MappedSuperclass +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@SuperBuilder +@SoftDelete // boolean 타입의 deleted 필드가 추가 +public abstract class BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @CreatedDate + @Column(name = "created_at") + private LocalDateTime createdAt; + + @LastModifiedDate + @Column(name = "updated_at") + private LocalDateTime updatedAt; + +} From 03f0ca848a1278272ef9ce27eb53970c8b109853 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:57:10 +0900 Subject: [PATCH 007/307] =?UTF-8?q?[feat]=20Category=20Entity=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 --- .../domain/category/entity/Category.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/entity/Category.java 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 new file mode 100644 index 00000000..15d36054 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/entity/Category.java @@ -0,0 +1,16 @@ +package com.bbteam.budgetbuddies.domain.category.entity; + +import com.bbteam.budgetbuddies.common.BaseEntity; +import jakarta.persistence.*; + +@Entity +public class Category { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String name; + +} From c71b28e7a8603c413ce939d6c20731e6086bf5f9 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:57:16 +0900 Subject: [PATCH 008/307] =?UTF-8?q?[feat]=20Comment=20Entity=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 --- .../domain/comment/entity/Comment.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java 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 new file mode 100644 index 00000000..43918096 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/entity/Comment.java @@ -0,0 +1,36 @@ +package com.bbteam.budgetbuddies.domain.comment.entity; + +import com.bbteam.budgetbuddies.common.BaseEntity; +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 jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@SuperBuilder +public class Comment extends BaseEntity { + + @Column(nullable = false, length = 1000) + private String content; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "discount_info_id") + private DiscountInfo discountInfo; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "support_info_id") + private SupportInfo supportInfo; + +} From 5f28bfc1fd491bde5bb30e6db2b6835188ce10d3 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:57:23 +0900 Subject: [PATCH 009/307] =?UTF-8?q?[feat]=20ConsumptionGoal=20Entity=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 --- .../entity/ConsumptionGoal.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java 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 new file mode 100644 index 00000000..932a9bf4 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/entity/ConsumptionGoal.java @@ -0,0 +1,42 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.entity; + +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.validation.constraints.Min; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.time.LocalDate; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@SuperBuilder +public class ConsumptionGoal extends BaseEntity { + + @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) + private LocalDate goalMonth; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "category_id") + private Category category; + +} From c13ba8301d6577d68246649d61865cf6a07c43ff Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:57:29 +0900 Subject: [PATCH 010/307] =?UTF-8?q?[feat]=20DiscountInfo=20Entity=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 --- .../discountinfo/entity/DiscountInfo.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/entity/DiscountInfo.java 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 new file mode 100644 index 00000000..fb2e4c18 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/entity/DiscountInfo.java @@ -0,0 +1,37 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.entity; + +import com.bbteam.budgetbuddies.common.BaseEntity; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.ColumnDefault; + +import java.time.LocalDate; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@SuperBuilder +public class DiscountInfo extends BaseEntity { + + @Column(nullable = false, length = 100) + private String title; + + private LocalDate startDate; + + private LocalDate endDate; + + @ColumnDefault("0") + private Integer likeCount; + + private Integer discountRate; + + @Column(length = 1000) + private String siteUrl; + +} From 4426b587d2b3971dc28bdaaa5d98a5ec3d1bd181 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:57:33 +0900 Subject: [PATCH 011/307] =?UTF-8?q?[feat]=20DiscountInfoLike=20Entity=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 --- .../entity/DiscountInfoLike.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/entity/DiscountInfoLike.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/entity/DiscountInfoLike.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/entity/DiscountInfoLike.java new file mode 100644 index 00000000..76da4f97 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/entity/DiscountInfoLike.java @@ -0,0 +1,32 @@ +package com.bbteam.budgetbuddies.domain.discountinfolike.entity; + +import com.bbteam.budgetbuddies.common.BaseEntity; +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 jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@SuperBuilder +public class DiscountInfoLike extends BaseEntity { + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "discount_info_id") + private DiscountInfo discountInfo; + +} From e41f946b808594dd0aa6579d9160be20740a74d5 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:57:39 +0900 Subject: [PATCH 012/307] =?UTF-8?q?[feat]=20Expense=20Entity=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 --- .../domain/expense/entity/Expense.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/entity/Expense.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/entity/Expense.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/entity/Expense.java new file mode 100644 index 00000000..0d94c760 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/entity/Expense.java @@ -0,0 +1,39 @@ +package com.bbteam.budgetbuddies.domain.expense.entity; + +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.validation.constraints.Min; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.time.LocalDateTime; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@SuperBuilder +public class Expense extends BaseEntity { + + @Column(nullable = false) + @Min(value = 1, message = "0 또는 음수의 비용을 지출할 수 없습니다.") + private Long amount; + + private String description; + + private LocalDateTime expenseDate; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "category_id") + private Category category; + +} From c5661f21dd2d262ac8bb6c0413414a8a1d9f9503 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:57:49 +0900 Subject: [PATCH 013/307] =?UTF-8?q?[feat]=20SupportInfo=20Entity=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 --- .../supportinfo/entity/SupportInfo.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/entity/SupportInfo.java 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 new file mode 100644 index 00000000..78ffa7ca --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/entity/SupportInfo.java @@ -0,0 +1,35 @@ +package com.bbteam.budgetbuddies.domain.supportinfo.entity; + +import com.bbteam.budgetbuddies.common.BaseEntity; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.ColumnDefault; + +import java.time.LocalDate; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@SuperBuilder +public class SupportInfo extends BaseEntity { + + @Column(nullable = false, length = 100) + private String title; + + private LocalDate startDate; + + private LocalDate endDate; + + @ColumnDefault("0") + private Integer likeCount; + + @Column(length = 1000) + private String siteUrl; + +} From 291abce918ffe49e0b644af3396a8488bdae27fd Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:57:54 +0900 Subject: [PATCH 014/307] =?UTF-8?q?[feat]=20SupportInfoLike=20Entity=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 --- .../entity/SupportInfoLike.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/entity/SupportInfoLike.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/entity/SupportInfoLike.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/entity/SupportInfoLike.java new file mode 100644 index 00000000..1be0154f --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/entity/SupportInfoLike.java @@ -0,0 +1,31 @@ +package com.bbteam.budgetbuddies.domain.supportinfolike.entity; + +import com.bbteam.budgetbuddies.common.BaseEntity; +import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@SuperBuilder +public class SupportInfoLike extends BaseEntity { + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "support_info_id") + private SupportInfo supportInfo; + +} From 8335ca8458af670a6b0940ef8695e41565d228b5 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:57:58 +0900 Subject: [PATCH 015/307] =?UTF-8?q?[feat]=20User=20Entity=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 --- .../domain/user/entity/User.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/entity/User.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/entity/User.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/entity/User.java new file mode 100644 index 00000000..c41f790c --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/user/entity/User.java @@ -0,0 +1,46 @@ +package com.bbteam.budgetbuddies.domain.user.entity; + +import com.bbteam.budgetbuddies.common.BaseEntity; +import com.bbteam.budgetbuddies.enums.Gender; +import jakarta.persistence.*; +import jakarta.validation.constraints.Min; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.time.LocalDateTime; + + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@SuperBuilder +public class User extends BaseEntity { + + @Column(nullable = false, unique = true) + private String phoneNumber; + + @Column(nullable = false, length = 20) + private String name; + + @Min(value = 1, message = "나이는 0또는 음수가 될 수 없습니다.") + private Integer age; + + @Enumerated(EnumType.STRING) + @Column(columnDefinition = "varchar(20)") + private Gender gender; + + @Column(nullable = false, length = 50, unique = true) + private String email; + + @Column(length = 1000) + private String photoUrl; + + private String consumptionPattern; + + private LocalDateTime lastLoginAt; + +} From 2d3fe8350683fb448e925f42e1fe7594754eba7e Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:58:03 +0900 Subject: [PATCH 016/307] =?UTF-8?q?[feat]=20UserCategory=20Entity=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 --- .../usercategory/entity/UserCategory.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/usercategory/entity/UserCategory.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/usercategory/entity/UserCategory.java b/src/main/java/com/bbteam/budgetbuddies/domain/usercategory/entity/UserCategory.java new file mode 100644 index 00000000..10ced391 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/usercategory/entity/UserCategory.java @@ -0,0 +1,32 @@ +package com.bbteam.budgetbuddies.domain.usercategory.entity; + +import com.bbteam.budgetbuddies.common.BaseEntity; +import com.bbteam.budgetbuddies.domain.category.entity.Category; +import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@SuperBuilder +public class UserCategory extends BaseEntity { + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "category_id") + private Category category; + +} From d4754e628802ff972b88c0ecede79d489f9dbedd Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:58:12 +0900 Subject: [PATCH 017/307] =?UTF-8?q?[feat]=20Gender=20Enum=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 --- src/main/java/com/bbteam/budgetbuddies/enums/Gender.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/enums/Gender.java diff --git a/src/main/java/com/bbteam/budgetbuddies/enums/Gender.java b/src/main/java/com/bbteam/budgetbuddies/enums/Gender.java new file mode 100644 index 00000000..d1be5b4b --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/enums/Gender.java @@ -0,0 +1,5 @@ +package com.bbteam.budgetbuddies.enums; + +public enum Gender { + MALE, FEMALE, NONE +} From cd10a5ec6130f3d9b51089030c81d6f7f2375fb0 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 14 Jul 2024 21:58:57 +0900 Subject: [PATCH 018/307] =?UTF-8?q?[feat]=20=ED=94=84=EB=A1=9C=EC=A0=9D?= =?UTF-8?q?=ED=8A=B8=20=EA=B5=AC=EC=A1=B0=20=EC=84=A4=EC=A0=95=20(?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1=20=EC=8B=9C=20?= =?UTF-8?q?=EA=B8=B0=EC=A1=B4=20package-info.java=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=ED=9B=84=20=EC=9E=91=EC=97=85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../budgetbuddies/domain/category/controller/package-info.java | 1 + .../bbteam/budgetbuddies/domain/category/dto/package-info.java | 1 + .../budgetbuddies/domain/category/repository/package-info.java | 1 + .../budgetbuddies/domain/category/service/package-info.java | 1 + .../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 + .../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 + .../domain/discountinfo/controller/package-info.java | 1 + .../budgetbuddies/domain/discountinfo/dto/package-info.java | 1 + .../domain/discountinfo/repository/package-info.java | 1 + .../budgetbuddies/domain/discountinfo/service/package-info.java | 1 + .../budgetbuddies/domain/expense/controller/package-info.java | 1 + .../bbteam/budgetbuddies/domain/expense/dto/package-info.java | 1 + .../budgetbuddies/domain/expense/repository/package-info.java | 1 + .../budgetbuddies/domain/expense/service/package-info.java | 1 + .../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 + .../budgetbuddies/domain/user/controller/package-info.java | 1 + .../com/bbteam/budgetbuddies/domain/user/dto/package-info.java | 1 + .../budgetbuddies/domain/user/repository/package-info.java | 1 + .../bbteam/budgetbuddies/domain/user/service/package-info.java | 1 + 28 files changed, 28 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/controller/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/dto/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/repository/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/service/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/package-info.java create 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/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/repository/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/service/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/controller/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/dto/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/repository/package-info.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/service/package-info.java 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 new file mode 100644 index 00000000..3ed2cb13 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/controller/package-info.java @@ -0,0 +1 @@ +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 new file mode 100644 index 00000000..54a5f6c4 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/dto/package-info.java @@ -0,0 +1 @@ +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/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/package-info.java new file mode 100644 index 00000000..995bc7a0 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/repository/package-info.java @@ -0,0 +1 @@ +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/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/service/package-info.java new file mode 100644 index 00000000..69cdabf3 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/service/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.category.service; \ No newline at end of file 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 new file mode 100644 index 00000000..6a816c5b --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/package-info.java @@ -0,0 +1 @@ +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 new file mode 100644 index 00000000..da2cf08a --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/dto/package-info.java @@ -0,0 +1 @@ +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 new file mode 100644 index 00000000..4d31a705 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/repository/package-info.java @@ -0,0 +1 @@ +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 new file mode 100644 index 00000000..4ffc9ed9 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.comment.service; \ No newline at end of file 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 new file mode 100644 index 00000000..c4780977 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/package-info.java @@ -0,0 +1 @@ +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 new file mode 100644 index 00000000..65ea60a1 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/package-info.java @@ -0,0 +1 @@ +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 new file mode 100644 index 00000000..ce8587a8 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/package-info.java @@ -0,0 +1 @@ +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 new file mode 100644 index 00000000..95d9a924 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.service; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/package-info.java new file mode 100644 index 00000000..2fac91d0 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.controller; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/package-info.java new file mode 100644 index 00000000..a1af1214 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.dto; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/package-info.java new file mode 100644 index 00000000..5bc91ad9 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.repository; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/package-info.java new file mode 100644 index 00000000..c975e0b2 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.service; \ No newline at end of file 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 new file mode 100644 index 00000000..cd648f5a --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.expense.controller; \ No newline at end of file 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 new file mode 100644 index 00000000..cd54ca0d --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.expense.dto; \ No newline at end of file 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 new file mode 100644 index 00000000..c5184ef7 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/repository/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.expense.repository; \ No newline at end of file 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 new file mode 100644 index 00000000..ece79aae --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.expense.service; \ No newline at end of file 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 new file mode 100644 index 00000000..a4bccaf4 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/package-info.java @@ -0,0 +1 @@ +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 new file mode 100644 index 00000000..7137c5b3 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/package-info.java @@ -0,0 +1 @@ +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 new file mode 100644 index 00000000..8a76d616 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/package-info.java @@ -0,0 +1 @@ +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 new file mode 100644 index 00000000..ceaba27e --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.supportinfo.service; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/controller/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/controller/package-info.java new file mode 100644 index 00000000..f734f3e8 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/user/controller/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.user.controller; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/dto/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/dto/package-info.java new file mode 100644 index 00000000..dc7d64bd --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/user/dto/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.user.dto; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/repository/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/repository/package-info.java new file mode 100644 index 00000000..10df5a90 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/user/repository/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.user.repository; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/service/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/service/package-info.java new file mode 100644 index 00000000..ddb7edf6 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/user/service/package-info.java @@ -0,0 +1 @@ +package com.bbteam.budgetbuddies.domain.user.service; \ No newline at end of file From f382a68bb8abde6ee771a38e971ca4aeb28302cb Mon Sep 17 00:00:00 2001 From: MJJ Date: Sun, 14 Jul 2024 23:54:32 +0900 Subject: [PATCH 019/307] =?UTF-8?q?[feat]=20Swagger=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index aaccf0ac..7c2d02cc 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' //Swagger compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' From 17e6a63032f17682dfa2948d01f5538fda2b673d Mon Sep 17 00:00:00 2001 From: MJJ Date: Sun, 14 Jul 2024 23:55:06 +0900 Subject: [PATCH 020/307] =?UTF-8?q?[feat]=20Swagger=20Global=20Config=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 --- .../global/config/SwaggerConfig.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/global/config/SwaggerConfig.java diff --git a/src/main/java/com/bbteam/budgetbuddies/global/config/SwaggerConfig.java b/src/main/java/com/bbteam/budgetbuddies/global/config/SwaggerConfig.java new file mode 100644 index 00000000..36a72988 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/global/config/SwaggerConfig.java @@ -0,0 +1,26 @@ +package com.bbteam.budgetbuddies.global.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; + +@Configuration +public class SwaggerConfig { + + @Bean + public OpenAPI openAPI() { + return new OpenAPI() + .components(new Components()) + .info(apiInfo()); + } + + private Info apiInfo() { + return new Info() + .title("Budgetbuddies Swagger") + .description("Budgetbuddies REST API") + .version("1.0.0"); + } +} From abfeb3610638e0778ea8f5866801df55af8ce41c Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Mon, 15 Jul 2024 21:45:06 +0900 Subject: [PATCH 021/307] =?UTF-8?q?[fix]=20UserCategory=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usercategory/entity/UserCategory.java | 32 ------------------- 1 file changed, 32 deletions(-) delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/usercategory/entity/UserCategory.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/usercategory/entity/UserCategory.java b/src/main/java/com/bbteam/budgetbuddies/domain/usercategory/entity/UserCategory.java deleted file mode 100644 index 10ced391..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/usercategory/entity/UserCategory.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.bbteam.budgetbuddies.domain.usercategory.entity; - -import com.bbteam.budgetbuddies.common.BaseEntity; -import com.bbteam.budgetbuddies.domain.category.entity.Category; -import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; -import com.bbteam.budgetbuddies.domain.user.entity.User; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -@Entity -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor -@SuperBuilder -public class UserCategory extends BaseEntity { - - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "user_id") - private User user; - - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "category_id") - private Category category; - -} From d04ea99789bf0a42f08aa5d319e0b874c3d3e1f7 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Mon, 15 Jul 2024 21:45:34 +0900 Subject: [PATCH 022/307] =?UTF-8?q?[fix]=20User=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EB=A7=A4=ED=95=91=20=EB=B0=8F=20isDefault=20?= =?UTF-8?q?=ED=95=84=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/domain/category/entity/Category.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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 15d36054..366167ef 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,7 +1,9 @@ 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 org.hibernate.annotations.ColumnDefault; @Entity public class Category { @@ -13,4 +15,11 @@ public class Category { @Column(nullable = false) private String name; + @ColumnDefault("1") + private Boolean isDefault; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "user_id") + private User user; + } From 3ea71f57e9bf74f729a61bc44428e9c3ba413bb8 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Tue, 16 Jul 2024 22:51:54 +0900 Subject: [PATCH 023/307] =?UTF-8?q?[feat]=20DiscountRequestDto=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 --- .../discountinfo/dto/DiscountRequestDto.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java new file mode 100644 index 00000000..01d4d231 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java @@ -0,0 +1,26 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DiscountRequestDto { + + private String title; + + private LocalDate startDate; + + private LocalDate endDate; + + private Integer discountRate; + + private String siteUrl; + +} From 3b7dfec6c8154a88fe3fb6c49fdc1cb8f653ce49 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Tue, 16 Jul 2024 22:52:11 +0900 Subject: [PATCH 024/307] =?UTF-8?q?[feat]=20DiscountResponseDto=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 --- .../discountinfo/dto/DiscountResponseDto.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java new file mode 100644 index 00000000..9e257a5a --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java @@ -0,0 +1,30 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DiscountResponseDto { + + private Long id; + + private String title; + + private LocalDate startDate; + + private LocalDate endDate; + + private Integer discountRate; + + private Integer likeCount; + + private String siteUrl; + +} From 62dc887890ad771cb957157e25864f0d6c79ef33 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Wed, 17 Jul 2024 23:10:43 +0900 Subject: [PATCH 025/307] =?UTF-8?q?[fix]=20=ED=8C=A8=ED=82=A4=EC=A7=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bbteam/budgetbuddies/domain/comment/dto/package-info.java | 1 - .../domain/discountinfo/controller/package-info.java | 1 - .../budgetbuddies/domain/discountinfo/dto/package-info.java | 1 - .../domain/discountinfo/repository/package-info.java | 1 - .../budgetbuddies/domain/discountinfo/service/package-info.java | 1 - .../budgetbuddies/domain/user/repository/package-info.java | 1 - 6 files changed, 6 deletions(-) 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/discountinfo/controller/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/package-info.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/repository/package-info.java 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/discountinfo/controller/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/package-info.java deleted file mode 100644 index 2fac91d0..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.discountinfo.controller; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/package-info.java deleted file mode 100644 index a1af1214..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.discountinfo.dto; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/package-info.java deleted file mode 100644 index 5bc91ad9..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.discountinfo.repository; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/package-info.java deleted file mode 100644 index c975e0b2..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.discountinfo.service; \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/repository/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/repository/package-info.java deleted file mode 100644 index 10df5a90..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/user/repository/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.user.repository; \ No newline at end of file From cd7c15d52a8ffba47c61d15cbc9fc8c430bddae1 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Wed, 17 Jul 2024 23:11:19 +0900 Subject: [PATCH 026/307] =?UTF-8?q?[feat]=20DiscountInfoConverter=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. requestDto -> entity 2. entity -> responseDto --- .../converter/DiscountInfoConverter.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java new file mode 100644 index 00000000..a360b7c9 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java @@ -0,0 +1,44 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.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 org.springframework.stereotype.Service; + +@Service +public class DiscountInfoConverter { + + /** + * @param entity + * @return responseDto + */ + public DiscountResponseDto toDto(DiscountInfo entity) { + + return DiscountResponseDto.builder() + .id(entity.getId()) + .title(entity.getTitle()) + .startDate(entity.getStartDate()) + .endDate(entity.getEndDate()) + .discountRate(entity.getDiscountRate()) + .likeCount(entity.getLikeCount()) + .siteUrl(entity.getSiteUrl()) + .build(); + } + + /** + * + * @param requestDto + * @return entity + */ + public DiscountInfo toEntity(DiscountRequestDto requestDto) { + + return DiscountInfo.builder() + .title(requestDto.getTitle()) + .startDate(requestDto.getStartDate()) + .endDate(requestDto.getEndDate()) + .discountRate(requestDto.getDiscountRate()) + .siteUrl(requestDto.getSiteUrl()) + .build(); + } + +} From c2452799325bb0c010903e2ae1f13008ea30c36f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=B1=EC=95=84?= Date: Thu, 18 Jul 2024 03:13:58 +0900 Subject: [PATCH 027/307] Update README.md --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a0a129db..580d57db 100644 --- a/README.md +++ b/README.md @@ -1 +1,12 @@ -# BackEnd +
+ +# 빈주머니즈_Spring + + + + ![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 +||||||| +|:-:|:-:|:-:|:-:|:-:|:-:| +|JeongJun Min
[@m3k0813](https://github.com/m3k0813)|SeungMin Kang
[@SoulTree-Lovers](https://github.com/SoulTree-Lovers)|류효경
[@ryogaeng](https://github.com/ryogaeng)|강재혁
[@ggamD00](https://github.com/ggamD00)|[@JunRain2](https://github.com/JunRain2)|이창준
[@wnd01jun](https://github.com/wnd01jun)| From 09c5c86673c5ba9b1f58930c2b35d97f6ebb674f Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 18 Jul 2024 16:32:08 +0900 Subject: [PATCH 028/307] =?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 029/307] =?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 fea1c3d96902d2a1267de1896a333c41bdaa74c3 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 18 Jul 2024 20:05:01 +0900 Subject: [PATCH 030/307] =?UTF-8?q?[feat]=20@Setter=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20=EB=B0=8F=20likeCount,=20anonymousNumber=200=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=B4=88=EA=B8=B0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/discountinfo/entity/DiscountInfo.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 fb2e4c18..e13f897d 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 @@ -3,10 +3,7 @@ import com.bbteam.budgetbuddies.common.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import lombok.experimental.SuperBuilder; import org.hibernate.annotations.ColumnDefault; @@ -14,6 +11,7 @@ @Entity @Getter +@Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @SuperBuilder @@ -27,7 +25,10 @@ public class DiscountInfo extends BaseEntity { private LocalDate endDate; @ColumnDefault("0") - private Integer likeCount; + private Integer likeCount = 0; + + @ColumnDefault("0") + private Integer anonymousNumber = 0; private Integer discountRate; From f8b9285f4207bfa4def7bf6b32a6e7e32dde9f75 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 18 Jul 2024 20:06:32 +0900 Subject: [PATCH 031/307] =?UTF-8?q?[feat]=20Converter=20Class=20=EB=88=84?= =?UTF-8?q?=EB=9D=BD=EB=90=9C=20=EB=B6=80=EB=B6=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - toDto(): anonymousNumber 응답 DTO에 추가 - toEntity(): anonymousNumber과 likeCount 0으로 설정 --- .../domain/discountinfo/converter/DiscountInfoConverter.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java index a360b7c9..66793215 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java @@ -19,6 +19,7 @@ public DiscountResponseDto toDto(DiscountInfo entity) { .title(entity.getTitle()) .startDate(entity.getStartDate()) .endDate(entity.getEndDate()) + .anonymousNumber(entity.getAnonymousNumber()) .discountRate(entity.getDiscountRate()) .likeCount(entity.getLikeCount()) .siteUrl(entity.getSiteUrl()) @@ -36,7 +37,9 @@ public DiscountInfo toEntity(DiscountRequestDto requestDto) { .title(requestDto.getTitle()) .startDate(requestDto.getStartDate()) .endDate(requestDto.getEndDate()) + .anonymousNumber(0) .discountRate(requestDto.getDiscountRate()) + .likeCount(0) .siteUrl(requestDto.getSiteUrl()) .build(); } From f0a6f3c1db6f451a6631b13d66fab8740b06a2cc Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 18 Jul 2024 20:09:27 +0900 Subject: [PATCH 032/307] =?UTF-8?q?[fix]=20@Data=20->=20@Getter=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=20(=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EC=9D=BC=EA=B4=80=EC=84=B1=EC=9D=84=20=EC=9C=84=ED=95=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + response DTO에 anonymousNumber 필드 추가 --- .../domain/discountinfo/dto/DiscountRequestDto.java | 7 ++----- .../domain/discountinfo/dto/DiscountResponseDto.java | 9 ++++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java index 01d4d231..894f6b3b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java @@ -1,13 +1,10 @@ package com.bbteam.budgetbuddies.domain.discountinfo.dto; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import java.time.LocalDate; -@Data +@Getter @Builder @NoArgsConstructor @AllArgsConstructor diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java index 9e257a5a..3cd64ff4 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java @@ -1,13 +1,10 @@ package com.bbteam.budgetbuddies.domain.discountinfo.dto; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import java.time.LocalDate; -@Data +@Getter @Builder @NoArgsConstructor @AllArgsConstructor @@ -21,6 +18,8 @@ public class DiscountResponseDto { private LocalDate endDate; + private Integer anonymousNumber; + private Integer discountRate; private Integer likeCount; From 5ff6c2e325af89b810db39681fd40ea063608fcc Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 18 Jul 2024 20:10:39 +0900 Subject: [PATCH 033/307] =?UTF-8?q?[feat]=20DiscountInfoRepository=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 특정 년, 월에 속하는 데이터 가져오는 메소드 구현 --- .../repository/DiscountInfoRepository.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/DiscountInfoRepository.java 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 new file mode 100644 index 00000000..e41ffe49 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/DiscountInfoRepository.java @@ -0,0 +1,16 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.repository; + +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +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 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); + +} From 527971df7569ba66a791763a4eda9a168104697e Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 18 Jul 2024 20:11:56 +0900 Subject: [PATCH 034/307] =?UTF-8?q?[feat]=20DiscountInfoService=20?= =?UTF-8?q?=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 - getDiscountsByYearAndMonth(): 특정 년, 월을 기준으로 할인정보를 가져오는 메소드 - registerDiscountInfo(): 할인정보를 등록하는 메소드 - toggleLike(): 할인정보의 좋아요를 누르는 메소드 --- .../service/DiscountInfoService.java | 20 ++++ .../service/DiscountInfoServiceImpl.java | 111 ++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java new file mode 100644 index 00000000..5be85054 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java @@ -0,0 +1,20 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.service; + +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; +import org.springframework.data.domain.Page; + +public interface DiscountInfoService { + Page getDiscountsByYearAndMonth( + Integer year, + Integer month, + Integer page, + Integer size + ); + + DiscountResponseDto registerDiscountInfo(DiscountRequestDto discountRequestDto); + + DiscountResponseDto toggleLike(Long userId, Long discountInfoId); + + +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java new file mode 100644 index 00000000..0f5945d8 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java @@ -0,0 +1,111 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.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.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 DiscountInfoServiceImpl implements DiscountInfoService { + + private final DiscountInfoRepository discountInfoRepository; + + private final DiscountInfoLikeRepository discountInfoLikeRepository; + + private final DiscountInfoConverter discountInfoConverter; + + private final UserRepository userRepository; + + + @Transactional + @Override + public Page getDiscountsByYearAndMonth(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 discountInfoPage = discountInfoRepository.findByDateRange(startDate, endDate, pageable); + + return discountInfoPage.map(discountInfoConverter::toDto); + } + + @Transactional + @Override + public DiscountResponseDto registerDiscountInfo(DiscountRequestDto discountRequestDto) { + /** + * 1. RequestDto -> Entity로 변환 + * 2. Entity 저장 + * 3. Entity -> ResponseDto로 변환 후 리턴 + */ + DiscountInfo entity = discountInfoConverter.toEntity(discountRequestDto); + + discountInfoRepository.save(entity); + + return discountInfoConverter.toDto(entity); + } + + @Transactional + @Override + public DiscountResponseDto toggleLike(Long userId, Long discountInfoId) { + /** + * 1. 사용자 조회 -> 없으면 에러 + * 2. 할인정보 조회 -> 없으면 에러 + * 3. 사용자가 특정 할인정보에 좋아요를 눌렀는지 확인 (DiscountInfoLike 테이블에서 userId로부터 데이터 가져오기) + * 4. 누르지 않은 상태라면, + * 4-1. DiscountInfo의 likeCount 1 증가 + * 4-2. DiscountInfoLike의 + * 5. 이미 누른 상태라면, + * 5-1. DiscountInfo의 likeCount 1 감소 + */ + + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + + DiscountInfo discountInfo = discountInfoRepository.findById(discountInfoId) + .orElseThrow(() -> new IllegalArgumentException("DiscountInfo not found")); + + Optional existingLike = discountInfoLikeRepository.findByUserAndDiscountInfo(user, discountInfo); + + if (existingLike.isPresent()) { + // 이미 좋아요를 누른 상태라면 + discountInfoLikeRepository.delete(existingLike.get()); + discountInfo.setLikeCount(discountInfo.getLikeCount() - 1); + } else { + // 아직 좋아요를 누르지 않은 상태라면 + DiscountInfoLike newLike = DiscountInfoLike.builder() + .user(user) + .discountInfo(discountInfo) + .build(); + discountInfoLikeRepository.save(newLike); + discountInfo.setLikeCount(discountInfo.getLikeCount() + 1); + } + + DiscountInfo savedEntity = discountInfoRepository.save(discountInfo); + + return discountInfoConverter.toDto(savedEntity); + } + + +} From 634f4f487d856f08452cf541146f1ac8cc09ee62 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 18 Jul 2024 20:12:55 +0900 Subject: [PATCH 035/307] =?UTF-8?q?[feat]=20DiscountInfoController=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20=EB=B0=8F=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DiscountInfoController.java | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java new file mode 100644 index 00000000..711671e1 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java @@ -0,0 +1,108 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.controller; + +import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; +import com.bbteam.budgetbuddies.domain.discountinfo.service.DiscountInfoService; +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.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +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.*; + +import java.util.List; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/discounts") +public class DiscountInfoController { + + private final DiscountInfoService discountInfoService; + + @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> getDiscountsByYearAndMonth( + @RequestParam Integer year, + @RequestParam Integer month, + @RequestParam(defaultValue = "0") Integer page, + @RequestParam(defaultValue = "10") Integer size + ) { + Page discounts = discountInfoService.getDiscountsByYearAndMonth(year, month, page, size); + + return ResponseEntity.ok(discounts); + } + + @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 DiscountRequestDto discountRequestDto + ) { + DiscountResponseDto discountResponseDto = discountInfoService.registerDiscountInfo(discountRequestDto); + + return ResponseEntity.ok(discountResponseDto); + } + + @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 = "discountInfoId", description = "좋아요를 누를 할인정보의 id입니다."), + }) + @PostMapping("/{discountInfoId}/likes") + public ResponseEntity likeDiscountInfo( + @RequestParam Long userId, + @PathVariable Long discountInfoId + ) { + DiscountResponseDto discountResponseDto = discountInfoService.toggleLike(userId, discountInfoId); + + return ResponseEntity.ok(discountResponseDto); + } + +// @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 = "discountInfoId", description = "댓글을 작성할 할인정보의 id입니다."), +// }) +// @GetMapping("/{discountInfoId}/comments") +// public List getComments( +// @RequestParam Long userId, +// @PathVariable Long discountInfoId +// ) { +// return null; +// } + +} From 916595554f836699ed43ca3bc6aafcaa7894b2ee Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 18 Jul 2024 20:13:40 +0900 Subject: [PATCH 036/307] =?UTF-8?q?[feat]=20DiscountInfoLikeRepository=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 - findByUserAndDiscountInfo(): 특정 유저의 아이디와 할인정보를 바탕으로 좋아요 클릭 메소드 구현 --- .../repository/DiscountInfoLikeRepository.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/repository/DiscountInfoLikeRepository.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/repository/DiscountInfoLikeRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/repository/DiscountInfoLikeRepository.java new file mode 100644 index 00000000..3a55285d --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/repository/DiscountInfoLikeRepository.java @@ -0,0 +1,14 @@ +package com.bbteam.budgetbuddies.domain.discountinfolike.repository; + +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +import com.bbteam.budgetbuddies.domain.discountinfolike.entity.DiscountInfoLike; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface DiscountInfoLikeRepository extends JpaRepository { + + Optional findByUserAndDiscountInfo(User user, DiscountInfo discountInfo); + +} From c31021e26756fcebd2df872b87fd414ae973fdd6 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 18 Jul 2024 20:13:57 +0900 Subject: [PATCH 037/307] =?UTF-8?q?[feat]=20UserRepository=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20(=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/repository/UserRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/repository/UserRepository.java 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 new file mode 100644 index 00000000..3495835a --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/user/repository/UserRepository.java @@ -0,0 +1,8 @@ +package com.bbteam.budgetbuddies.domain.user.repository; + +import com.bbteam.budgetbuddies.domain.user.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserRepository extends JpaRepository { + +} From f3d3fb8173dbfa2c9b76f4712f017ae68774367d Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 18 Jul 2024 20:14:24 +0900 Subject: [PATCH 038/307] =?UTF-8?q?[feat]=20UserRepositoryTest=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20(=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 테스트용 User Entity 1개 생성하는 테스트 코드 구현 --- .../user/repository/UserRepositoryTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/user/repository/UserRepositoryTest.java diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/user/repository/UserRepositoryTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/user/repository/UserRepositoryTest.java new file mode 100644 index 00000000..f89b41ba --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/user/repository/UserRepositoryTest.java @@ -0,0 +1,43 @@ +package com.bbteam.budgetbuddies.domain.user.repository; + +import com.bbteam.budgetbuddies.domain.user.entity.User; +import com.bbteam.budgetbuddies.enums.Gender; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +class UserRepositoryTest { + + @Autowired + private UserRepository userRepository; + + + + @Test + @DisplayName("테스트용 User Entity 1개 생성") + void saveUser() { + User user = User.builder() + .id(1L) + .phoneNumber("010-1234-1234") + .name("홍길동") + .age(25) + .gender(Gender.MALE) + .email("hong@naver.com") + .photoUrl("abc") + .consumptionPattern("TypeA") + .lastLoginAt(LocalDateTime.now()) + .createdAt(LocalDateTime.now()) + .updatedAt(LocalDateTime.now()) + .build(); + + userRepository.save(user); + } + +} \ No newline at end of file From f1c804e66a4269171006cc57992eba7f07f3f300 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 18 Jul 2024 20:16:16 +0900 Subject: [PATCH 039/307] =?UTF-8?q?[feat]=20@Getter=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20(DTO=20=EC=83=9D=EC=84=B1=EC=97=90=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/bbteam/budgetbuddies/common/BaseEntity.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java index e743a0e2..7a9756c1 100644 --- a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java +++ b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java @@ -1,9 +1,7 @@ package com.bbteam.budgetbuddies.common; import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; +import lombok.*; import lombok.experimental.SuperBuilder; import org.hibernate.annotations.SoftDelete; import org.springframework.data.annotation.CreatedDate; @@ -16,6 +14,7 @@ @MappedSuperclass @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor +@Getter @SuperBuilder @SoftDelete // boolean 타입의 deleted 필드가 추가 public abstract class BaseEntity { From 8fc9f3595c5d89b87a4cacb3731f2a6ec4d2d78b Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 18 Jul 2024 21:24:26 +0900 Subject: [PATCH 040/307] =?UTF-8?q?[fix]=20=ED=8A=B8=EB=9E=9C=EC=9E=AD?= =?UTF-8?q?=EC=85=98=20=EC=84=B1=EB=8A=A5=20=ED=96=A5=EC=83=81=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4=20readOnly=20=3D=20true=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/discountinfo/service/DiscountInfoServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java index 0f5945d8..76e986ec 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java @@ -32,7 +32,7 @@ public class DiscountInfoServiceImpl implements DiscountInfoService { private final UserRepository userRepository; - @Transactional + @Transactional(readOnly = true) @Override public Page getDiscountsByYearAndMonth(Integer year, Integer month, Integer page, Integer size) { /** From 8ec52363ae7a4e0f23ddaf31b7dc4e9e872cc152 Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 18 Jul 2024 22:19:07 +0900 Subject: [PATCH 041/307] =?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 042/307] =?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 002b3ee46c728d4dd5fd1c56c44f01372ccede33 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 18 Jul 2024 22:51:43 +0900 Subject: [PATCH 043/307] =?UTF-8?q?[fix]=20DiscountInfo=EC=9D=98=20@Setter?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C=20=ED=9B=84=20likeCount=20setter=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=EB=94=B0=EB=A1=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/discountinfo/entity/DiscountInfo.java | 9 ++++++++- .../discountinfo/service/DiscountInfoServiceImpl.java | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) 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 e13f897d..5caf45b3 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 @@ -11,7 +11,6 @@ @Entity @Getter -@Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @SuperBuilder @@ -35,4 +34,12 @@ public class DiscountInfo extends BaseEntity { @Column(length = 1000) private String siteUrl; + public void addLikeCount() { + this.likeCount++; + } + + public void subLikeCount() { + this.likeCount--; + } + } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java index 76e986ec..624cf7f5 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java @@ -91,7 +91,7 @@ public DiscountResponseDto toggleLike(Long userId, Long discountInfoId) { if (existingLike.isPresent()) { // 이미 좋아요를 누른 상태라면 discountInfoLikeRepository.delete(existingLike.get()); - discountInfo.setLikeCount(discountInfo.getLikeCount() - 1); + discountInfo.subLikeCount(); } else { // 아직 좋아요를 누르지 않은 상태라면 DiscountInfoLike newLike = DiscountInfoLike.builder() @@ -99,7 +99,7 @@ public DiscountResponseDto toggleLike(Long userId, Long discountInfoId) { .discountInfo(discountInfo) .build(); discountInfoLikeRepository.save(newLike); - discountInfo.setLikeCount(discountInfo.getLikeCount() + 1); + discountInfo.addLikeCount(); } DiscountInfo savedEntity = discountInfoRepository.save(discountInfo); From b44813eb60ae9caf105158106d3de0241f901074 Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 18 Jul 2024 23:43:21 +0900 Subject: [PATCH 044/307] =?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 045/307] =?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 046/307] =?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 047/307] =?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 048/307] =?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 049/307] =?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 050/307] =?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 051/307] =?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 052/307] =?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 053/307] 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 054/307] 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 055/307] =?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 056/307] =?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 057/307] =?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 058/307] =?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 059/307] =?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 060/307] =?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 061/307] =?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 062/307] =?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 063/307] =?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 064/307] =?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 065/307] =?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 066/307] =?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 067/307] =?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 068/307] =?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 069/307] =?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 070/307] =?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 071/307] =?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 072/307] =?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 073/307] =?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 074/307] =?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 075/307] =?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 076/307] =?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 077/307] =?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 078/307] =?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 079/307] =?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 080/307] 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 081/307] =?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 082/307] =?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 083/307] =?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 084/307] =?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 085/307] =?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 086/307] =?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 087/307] =?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 088/307] =?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 089/307] =?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 090/307] =?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 091/307] =?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 092/307] =?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 093/307] =?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 094/307] =?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 095/307] =?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 096/307] =?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 097/307] =?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 098/307] =?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 099/307] =?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 100/307] =?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 101/307] =?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 102/307] =?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 103/307] =?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 104/307] =?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 105/307] =?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 106/307] =?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 107/307] =?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 108/307] =?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 109/307] =?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 110/307] =?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 111/307] =?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 112/307] =?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 113/307] =?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 114/307] =?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 115/307] =?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 116/307] =?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 117/307] =?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 118/307] =?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 119/307] =?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 120/307] =?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 121/307] =?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 122/307] =?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 123/307] =?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 124/307] =?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 125/307] =?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 126/307] =?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 9f9b1d3fb584caaecd8d35c37dfff9c53db4bbff Mon Sep 17 00:00:00 2001 From: MJJ Date: Wed, 24 Jul 2024 23:18:20 +0900 Subject: [PATCH 127/307] =?UTF-8?q?[feat]=20=EC=86=8C=EB=B9=84=20=EB=B6=84?= =?UTF-8?q?=EC=84=9D=20converter=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/ConsumptionAnalysisConverter.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionAnalysisConverter.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionAnalysisConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionAnalysisConverter.java new file mode 100644 index 00000000..2211d8f6 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionAnalysisConverter.java @@ -0,0 +1,16 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.converter; + +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionAnalysisResponseDTO; +import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; + +public class ConsumptionAnalysisConverter { + + public static ConsumptionAnalysisResponseDTO fromEntity(ConsumptionGoal consumptionGoal, + String topAmount) { + + return ConsumptionAnalysisResponseDTO.builder() + .goalCategory(consumptionGoal.getCategory().getName()) + .consumptionCategory(topAmount) + .build(); + } +} From 1331c9217209695da61fe47bde8317e79cd1a4e6 Mon Sep 17 00:00:00 2001 From: MJJ Date: Wed, 24 Jul 2024 23:18:39 +0900 Subject: [PATCH 128/307] =?UTF-8?q?[feat]=20=EC=86=8C=EB=B9=84=20=EB=B6=84?= =?UTF-8?q?=EC=84=9D=20responseDTO=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/ConsumptionAnalysisResponseDTO.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionAnalysisResponseDTO.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionAnalysisResponseDTO.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionAnalysisResponseDTO.java new file mode 100644 index 00000000..81eed6df --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionAnalysisResponseDTO.java @@ -0,0 +1,17 @@ +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 ConsumptionAnalysisResponseDTO { + + private String goalCategory; + + private String consumptionCategory; +} From fc70b5558781e03fadc96b0e56485d616cb60bee Mon Sep 17 00:00:00 2001 From: MJJ Date: Wed, 24 Jul 2024 23:19:01 +0900 Subject: [PATCH 129/307] =?UTF-8?q?[feat]=20=EC=86=8C=EB=B9=84=20=EB=B6=84?= =?UTF-8?q?=EC=84=9D=20controller=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 | 15 +++++++++++---- 1 file changed, 11 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..c9d3df9b 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,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionAnalysisResponseDTO; 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 +33,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 +60,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 +73,12 @@ public ResponseEntity getPeerInfo(@RequestParam(name = "userId") Long userId, return ResponseEntity.ok(response); } + @Operation(summary = "또래가 가장 큰 계획을 세운 카테고리와 이번 주 사용한 금액 조회 API", description = "로그인 한 유저의 또래 중 가장 큰 소비 목표 금액을 가진 카테고리와 이번 주 사용한 금액을 조회하는 API 입니다") + @ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")}) + @Parameters({@Parameter(name = "userId", description = "로그인 한 유저 아이디")}) + @GetMapping("/top-category") + public ResponseEntity getTopGoalCategory(@RequestParam(name = "userId") Long userId) { + ConsumptionAnalysisResponseDTO response = consumptionGoalService.getTopCategoryAndConsumptionAmount(userId); + return ResponseEntity.ok(response); + } } \ 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 130/307] =?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 131/307] =?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 c09fc7f550ccdfadecda224c3e3d72e856f36d68 Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 25 Jul 2024 00:59:59 +0900 Subject: [PATCH 132/307] =?UTF-8?q?[fix]=20responseDTO=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumptiongoal/dto/ConsumptionAnalysisResponseDTO.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionAnalysisResponseDTO.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionAnalysisResponseDTO.java index 81eed6df..10c505be 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionAnalysisResponseDTO.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/ConsumptionAnalysisResponseDTO.java @@ -13,5 +13,5 @@ public class ConsumptionAnalysisResponseDTO { private String goalCategory; - private String consumptionCategory; + private Long currentWeekConsumptionAmount; } From 0f45acb04aa117e8fbc2954c7a905b7eca88391e Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 25 Jul 2024 01:00:27 +0900 Subject: [PATCH 133/307] =?UTF-8?q?[fix]=20converter=20=EB=B3=80=EC=88=98?= =?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 --- .../converter/ConsumptionAnalysisConverter.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionAnalysisConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionAnalysisConverter.java index 2211d8f6..27b34819 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionAnalysisConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionAnalysisConverter.java @@ -5,12 +5,11 @@ public class ConsumptionAnalysisConverter { - public static ConsumptionAnalysisResponseDTO fromEntity(ConsumptionGoal consumptionGoal, - String topAmount) { + public static ConsumptionAnalysisResponseDTO fromEntity(ConsumptionGoal consumptionGoal, Long topAmount) { return ConsumptionAnalysisResponseDTO.builder() .goalCategory(consumptionGoal.getCategory().getName()) - .consumptionCategory(topAmount) + .currentWeekConsumptionAmount(topAmount) .build(); } } From 1b278ad3183ff8fce008086f6d7efd30f047b10e Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 25 Jul 2024 01:27:01 +0900 Subject: [PATCH 134/307] =?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 135/307] =?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 136/307] =?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 137/307] =?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 138/307] =?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 139/307] =?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 140/307] =?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 141/307] =?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 142/307] =?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 143/307] =?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 144/307] =?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 145/307] =?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 146/307] =?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 147/307] =?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 148/307] =?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 149/307] =?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 fdfdfc43dd7a72ff1b92317b0f8ba0eb9d968e29 Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 25 Jul 2024 14:05:45 +0900 Subject: [PATCH 150/307] =?UTF-8?q?[feat]=20=ED=8A=B9=EC=A0=95=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=A4=91=20=EC=9D=B4=EB=B2=88=20?= =?UTF-8?q?=EC=A3=BC=20=EC=86=8C=EB=B9=84=20=EA=B8=88=EC=95=A1=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20repository=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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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..3c113493 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,6 +2,7 @@ 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; @@ -27,4 +28,8 @@ 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); -} \ No newline at end of file + + @Query("SELECT cg FROM ConsumptionGoal cg JOIN cg.category c WHERE c.id = :categoryId AND cg.goalMonth BETWEEN :startOfWeek AND :endOfWeek ORDER BY cg.consumeAmount DESC") + Optional findTopConsumptionByCategoryIdAndCurrentWeek(@Param("categoryId") Long categoryId, + @Param("startOfWeek") LocalDate startOfWeek, @Param("endOfWeek") LocalDate endOfWeek); +} From b8674dbed993a03f8b958ec8166d5149c1e4d42e Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 25 Jul 2024 14:05:58 +0900 Subject: [PATCH 151/307] =?UTF-8?q?[feat]=20=ED=8A=B9=EC=A0=95=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=A4=91=20=EC=9D=B4=EB=B2=88=20?= =?UTF-8?q?=EC=A3=BC=20=EC=86=8C=EB=B9=84=20=EA=B8=88=EC=95=A1=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20service=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 | 41 ++++++++++++++++--- 2 files changed, 39 insertions(+), 5 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 5cafba0c..4dc59292 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.ConsumptionAnalysisResponseDTO; 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,6 @@ List getTopGoalCategories(int top, Long userId, int ConsumptionGoalResponseListDto findUserConsumptionGoal(Long userId, LocalDate date); PeerInfoResponseDTO getPeerInfo(Long userId, int peerAgeStart, int peerAgeEnd, String peerGender); + + ConsumptionAnalysisResponseDTO getTopCategoryAndConsumptionAmount(Long userId); } \ 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 f9722314..49aa8d34 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.time.DayOfWeek; import java.time.LocalDate; +import java.time.temporal.TemporalAdjusters; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -13,8 +15,10 @@ import com.bbteam.budgetbuddies.domain.category.entity.Category; import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; +import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.ConsumptionAnalysisConverter; import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.PeerInfoConverter; import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.TopCategoryConverter; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionAnalysisResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.PeerInfoResponseDTO; @@ -75,6 +79,35 @@ public PeerInfoResponseDTO getPeerInfo(Long userId, int peerAgeS, int peerAgeE, return PeerInfoConverter.fromEntity(peerAgeStart, peerAgeEnd, peerGender); } + @Override + @Transactional(readOnly = true) + public ConsumptionAnalysisResponseDTO getTopCategoryAndConsumptionAmount(Long userId) { + + User user = findUserById(userId); + + checkPeerInfo(user, 0, 0, "none"); + + ConsumptionGoal topConsumptionGoal = consumptionGoalRepository.findTopCategoriesAndGoalAmount(1, peerAgeStart, + peerAgeEnd, peerGender).get(0); + + LocalDate today = LocalDate.now(); + LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); + LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY)); + + Optional currentWeekConsumptionAmount = consumptionGoalRepository.findTopConsumptionByCategoryIdAndCurrentWeek( + topConsumptionGoal.getCategory().getId(), startOfWeek, endOfWeek); + + if (currentWeekConsumptionAmount.isEmpty()) { + throw new NoSuchElementException("이번 주 소비 내역을 찾을 수 없습니다."); + } + + Long totalConsumptionAmountForCurrentWeek = currentWeekConsumptionAmount.stream() + .mapToLong(ConsumptionGoal::getConsumeAmount) + .sum(); + + return ConsumptionAnalysisConverter.fromEntity(topConsumptionGoal, totalConsumptionAmountForCurrentWeek); + } + private User findUserById(Long userId) { Optional user = userRepository.findById(userId); @@ -112,7 +145,7 @@ private void setAgeGroupByUser(int userAge) { } else if (userAge >= 29) { peerAgeStart = 29; peerAgeEnd = 99; - }else{ + } else { peerAgeStart = 0; peerAgeEnd = 19; } @@ -121,10 +154,8 @@ private void setAgeGroupByUser(int userAge) { 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 -> ConsumptionGoalResponseDto.initializeFromCategoryAndGoalMonth(category, goalMonth))); } private void updateGoalMapWithPreviousMonth(Long userId, LocalDate goalMonth, From c374a752d399af9a8347f8d4f2a0fb4dff828276 Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 25 Jul 2024 14:07:39 +0900 Subject: [PATCH 152/307] =?UTF-8?q?[fix]=20ConsumptionGoalRepository=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=ED=8F=AC=EB=A7=B7=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ConsumptionGoalRepository.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 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 3c113493..2d6b58d1 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 @@ -15,21 +15,17 @@ @Repository public interface ConsumptionGoalRepository extends JpaRepository { - @Query("SELECT cg FROM ConsumptionGoal cg " - + "WHERE cg.category.isDefault = true " - + "AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " - + "AND cg.user.gender = :peerGender " + @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 limit :top") - List findTopCategoriesAndGoalAmount( - @Param("top") int top, - @Param("peerAgeStart") int peerAgeStart, - @Param("peerAgeEnd") int peerAgeEnd, - @Param("peerGender") Gender peerGender); + List findTopCategoriesAndGoalAmount(@Param("top") int top, @Param("peerAgeStart") int peerAgeStart, + @Param("peerAgeEnd") int peerAgeEnd, @Param("peerGender") Gender peerGender); @Query(value = "SELECT cg FROM ConsumptionGoal AS cg WHERE cg.user.id = :userId AND cg.goalMonth = :goalMonth") List findConsumptionGoalByUserIdAndGoalMonth(Long userId, LocalDate goalMonth); - @Query("SELECT cg FROM ConsumptionGoal cg JOIN cg.category c WHERE c.id = :categoryId AND cg.goalMonth BETWEEN :startOfWeek AND :endOfWeek ORDER BY cg.consumeAmount DESC") + @Query("SELECT cg FROM ConsumptionGoal cg JOIN cg.category c WHERE c.id = :categoryId AND cg.goalMonth " + + "BETWEEN :startOfWeek AND :endOfWeek ORDER BY cg.consumeAmount DESC") Optional findTopConsumptionByCategoryIdAndCurrentWeek(@Param("categoryId") Long categoryId, @Param("startOfWeek") LocalDate startOfWeek, @Param("endOfWeek") LocalDate endOfWeek); } From 2a125413d79ef08202d75223977b35b2ee5d49a8 Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 25 Jul 2024 14:09:17 +0900 Subject: [PATCH 153/307] =?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 154/307] =?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 155/307] =?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 156/307] =?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 157/307] =?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 158/307] =?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 159/307] =?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 160/307] =?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 161/307] =?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 162/307] =?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 163/307] =?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 164/307] =?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 165/307] =?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 166/307] =?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 167/307] =?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 168/307] =?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 169/307] =?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 170/307] =?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 171/307] =?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 63f4e3f84ae9feb7eee2c0598147f4f499767e56 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 25 Jul 2024 22:21:06 +0900 Subject: [PATCH 172/307] =?UTF-8?q?[fix]=20@ColumnDefault("0")=EB=A5=BC=20?= =?UTF-8?q?@Builder.Default=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/discountinfo/entity/DiscountInfo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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..69908cd0 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 @@ -23,10 +23,10 @@ public class DiscountInfo extends BaseEntity { private LocalDate endDate; - @ColumnDefault("0") + @Builder.Default private Integer likeCount = 0; - @ColumnDefault("0") + @Builder.Default private Integer anonymousNumber = 0; private Integer discountRate; From 2d9238562702b4b3575b42777297f07cf02581f0 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 25 Jul 2024 22:21:42 +0900 Subject: [PATCH 173/307] =?UTF-8?q?[feat]=20isLike=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20toggleLike()=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=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 --- .../discountinfolike/entity/DiscountInfoLike.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/entity/DiscountInfoLike.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/entity/DiscountInfoLike.java index 76da4f97..bb3fda22 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/entity/DiscountInfoLike.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/entity/DiscountInfoLike.java @@ -8,10 +8,7 @@ import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import lombok.experimental.SuperBuilder; @Entity @@ -29,4 +26,10 @@ public class DiscountInfoLike extends BaseEntity { @JoinColumn(name = "discount_info_id") private DiscountInfo discountInfo; + @Builder.Default + private Boolean isLike = false; + + public void toggleLike() { + isLike = !isLike; + } } From f48cdd4b7587b652e5e9ccc7902bedac4c6bc432 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 25 Jul 2024 22:22:44 +0900 Subject: [PATCH 174/307] =?UTF-8?q?[refactor]=20isLike=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/DiscountInfoServiceImpl.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java index 624cf7f5..a1ef0604 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java @@ -89,14 +89,22 @@ public DiscountResponseDto toggleLike(Long userId, Long discountInfoId) { Optional existingLike = discountInfoLikeRepository.findByUserAndDiscountInfo(user, discountInfo); if (existingLike.isPresent()) { - // 이미 좋아요를 누른 상태라면 - discountInfoLikeRepository.delete(existingLike.get()); - discountInfo.subLikeCount(); + // 이미 객체가 존재한다면 + if (existingLike.get().getIsLike()) { + // 좋아요를 누른 상태라면 + existingLike.get().toggleLike(); + discountInfo.subLikeCount(); + } else { + // 좋아요를 누르지 않은 상태라면 + existingLike.get().toggleLike(); + discountInfo.addLikeCount(); + } } else { - // 아직 좋아요를 누르지 않은 상태라면 + // 처음 객체를 생성한다면 DiscountInfoLike newLike = DiscountInfoLike.builder() .user(user) .discountInfo(discountInfo) + .isLike(true) .build(); discountInfoLikeRepository.save(newLike); discountInfo.addLikeCount(); From 3ca9978238db4870c7b08b16f8909e49e0aa3c21 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 25 Jul 2024 22:23:40 +0900 Subject: [PATCH 175/307] =?UTF-8?q?[test]=20DiscountInfoRepository=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 특정 년월에 속하는 할인 정보 데이터 조회 성공 테스트 - 특정 년월에 속하는 할인 정보 데이터 조회 실패 테스트 --- .../DiscountInfoRepositoryTest.java | 73 +++++++++++++++++++ 1 file changed, 73 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..22348c61 --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/repository/DiscountInfoRepositoryTest.java @@ -0,0 +1,73 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.repository; + +import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; +import jakarta.transaction.Transactional; +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 org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; + +import java.time.LocalDate; + +import static org.assertj.core.api.Assertions.assertThat; + +@DataJpaTest +@Transactional +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) +class DiscountInfoRepositoryTest { + + @Autowired + private DiscountInfoRepository discountInfoRepository; + + @Test + @DisplayName("특정 년월에 속하는 할인 정보 데이터 조회 성공") + void findByDateRangeSuccess() { + // given + DiscountInfo discount1 = DiscountInfo.builder() + .title("할인정보1") + .startDate(LocalDate.of(2024, 7, 1)) + .endDate(LocalDate.of(2024, 7, 21)) + .discountRate(40) + .siteUrl("http://example1.com") + .build(); + discountInfoRepository.save(discount1); + + // when + Page results = discountInfoRepository.findByDateRange( + LocalDate.of(2024, 7, 1), + LocalDate.of(2024, 7, 31), + PageRequest.of(0, 10) + ); + + // then + assertThat(results).hasSize(1); + assertThat(results.getContent().get(0).getTitle()).isEqualTo("할인정보1"); + } + + @Test + @DisplayName("특정 년월에 속하는 할인 정보 데이터 조회 실패") + void findByDateRangeFailure() { + // given + DiscountInfo discount1 = DiscountInfo.builder() + .title("할인정보1") + .startDate(LocalDate.of(2024, 6, 1)) + .endDate(LocalDate.of(2024, 6, 21)) + .discountRate(40) + .siteUrl("http://example1.com") + .build(); + discountInfoRepository.save(discount1); + + // when + Page results = discountInfoRepository.findByDateRange( + LocalDate.of(2024, 7, 1), + LocalDate.of(2024, 7, 31), + PageRequest.of(0, 10) + ); + + // then + assertThat(results).hasSize(0); + } +} \ No newline at end of file From 517cbd8ea2af020f4d851bbd24543bb1dfdbe9db Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 25 Jul 2024 22:24:20 +0900 Subject: [PATCH 176/307] =?UTF-8?q?[test]=20DiscountInfoService=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 할인 정보 2개를 등록한 뒤, 호출했을 때 2개가 정상적으로 반환되는지 검증 - 할인 정보 등록이 정상적으로 되는지 검증 - 좋아요를 처음 눌렀을 때 1을 반환하는지 검증 --- .../service/DiscountInfoServiceTest.java | 219 ++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceTest.java diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceTest.java new file mode 100644 index 00000000..3733a825 --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceTest.java @@ -0,0 +1,219 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.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.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; +import com.bbteam.budgetbuddies.enums.Gender; +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.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + +@Transactional +@ExtendWith(MockitoExtension.class) +class DiscountInfoServiceTest { + + @Mock + private DiscountInfoRepository discountInfoRepository; + + @Mock + private DiscountInfoLikeRepository discountInfoLikeRepository; + + @Mock + private DiscountInfoConverter discountInfoConverter; + + @Mock + private UserRepository userRepository; + + @InjectMocks + private DiscountInfoServiceImpl discountInfoService; + + @Test + @DisplayName("할인 정보 2개를 등록한 뒤, 호출했을 때 2개가 정상적으로 반환되는지 검증") + void getDiscountsByYearAndMonthTest() { + // given + LocalDate startDate = LocalDate.of(2024, 7, 1); + LocalDate endDate = LocalDate.of(2024, 7, 31); + Pageable pageable = PageRequest.of(0, 10); + + DiscountInfo discount1 = DiscountInfo.builder() + .title("Discount 1") + .startDate(startDate) + .endDate(endDate) + .discountRate(20) + .siteUrl("http://example1.com") + .build(); + + DiscountInfo discount2 = DiscountInfo.builder() + .title("Discount 2") + .startDate(startDate) + .endDate(endDate) + .discountRate(30) + .siteUrl("http://example2.com") + .build(); + + List discounts = List.of(discount1, discount2); + Page discountPage = new PageImpl<>(discounts, pageable, discounts.size()); + + DiscountResponseDto dto1 = new DiscountResponseDto(); + DiscountResponseDto dto2 = new DiscountResponseDto(); + + when(discountInfoRepository.findByDateRange(startDate, endDate, pageable)).thenReturn(discountPage); + when(discountInfoConverter.toDto(discount1)).thenReturn(dto1); + when(discountInfoConverter.toDto(discount2)).thenReturn(dto2); + + // when + Page result = discountInfoService.getDiscountsByYearAndMonth(2024, 7, 0, 10); + + // then + // 1. 데이터가 2개인지 검증 + // 2. 각 데이터 내용이 일치하는지 검증 + assertThat(result.getContent()).hasSize(2); + assertThat(result.getContent().get(0)).isEqualTo(dto1); + assertThat(result.getContent().get(1)).isEqualTo(dto2); + + // 3. 각 메소드가 1번씩만 호출되었는지 검증 + verify(discountInfoRepository, times(1)).findByDateRange(startDate, endDate, pageable); + verify(discountInfoConverter, times(1)).toDto(discount1); + verify(discountInfoConverter, times(1)).toDto(discount2); + } + + @Test + @DisplayName("할인 정보 등록이 정상적으로 되는지 검증") + void registerDiscountInfoTest() { + // given + DiscountRequestDto requestDto = DiscountRequestDto.builder() + .title("할인 정보 제목") + .startDate(LocalDate.of(2024, 7, 1)) + .endDate(LocalDate.of(2024, 7, 21)) + .discountRate(30) + .siteUrl("http://example.com") + .build(); + + DiscountInfo entity = DiscountInfo.builder() + .title("할인 정보 제목") + .startDate(LocalDate.of(2024, 7, 1)) + .endDate(LocalDate.of(2024, 7, 21)) + .discountRate(30) + .siteUrl("http://example.com") + .build(); + + DiscountResponseDto responseDto = DiscountResponseDto.builder() + .id(1L) + .title("할인 정보 제목") + .startDate(LocalDate.of(2024, 7, 1)) + .endDate(LocalDate.of(2024, 7, 21)) + .discountRate(30) + .siteUrl("http://example.com") + .likeCount(0) + .anonymousNumber(0) + .build(); + + when(discountInfoConverter.toEntity(requestDto)).thenReturn(entity); + when(discountInfoRepository.save(entity)).thenReturn(entity); + when(discountInfoConverter.toDto(entity)).thenReturn(responseDto); + + // when + DiscountResponseDto result = discountInfoService.registerDiscountInfo(requestDto); + + // then + // 1. 데이터 내용이 일치하는지 검증 + assertThat(result).isEqualTo(responseDto); + + // 2. 각 메소드가 1번씩만 호출되었는지 검증 + verify(discountInfoConverter, times(1)).toEntity(requestDto); + verify(discountInfoRepository, times(1)).save(entity); + verify(discountInfoConverter, times(1)).toDto(entity); + } + + @Test + @DisplayName("좋아요를 처음 눌렀을 때 1을 반환하는지 검증") + void toggleLikeTest() { + // given + User user = User.builder() + .id(1L) + .phoneNumber("010-1234-5678") + .name("John Doe") + .age(30) + .gender(Gender.MALE) + .email("john.doe@example.com") + .photoUrl("http://example.com/photo.jpg") + .consumptionPattern("Regular") + .lastLoginAt(LocalDateTime.now()) + .build(); + + DiscountInfo discountInfo = DiscountInfo.builder() + .id(1L) + .title("Discount on electronics") + .startDate(LocalDate.of(2024, 7, 20)) + .endDate(LocalDate.of(2024, 7, 30)) + .likeCount(0) + .anonymousNumber(0) + .discountRate(50) + .siteUrl("http://example.com") + .build(); + + DiscountInfoLike discountInfoLike = DiscountInfoLike.builder() + .id(1L) + .user(user) + .discountInfo(discountInfo) + .isLike(false) + .build(); + + DiscountResponseDto responseDto = DiscountResponseDto.builder() + .id(1L) + .title("Discount on electronics") + .startDate(LocalDate.of(2024, 7, 20)) + .endDate(LocalDate.of(2024, 7, 30)) + .likeCount(1) + .anonymousNumber(0) + .discountRate(50) + .siteUrl("http://example.com") + .build(); + + when(discountInfoRepository.save(any(DiscountInfo.class))).thenReturn(discountInfo); + when(userRepository.findById(anyLong())).thenReturn(Optional.of(user)); + when(discountInfoRepository.findById(anyLong())).thenReturn(Optional.of(discountInfo)); + when(discountInfoLikeRepository.findByUserAndDiscountInfo(user, discountInfo)).thenReturn(Optional.of(discountInfoLike)); + when(discountInfoConverter.toDto(any(DiscountInfo.class))).thenReturn(responseDto); + + // when + DiscountResponseDto result = discountInfoService.toggleLike(1L, 1L); + + // then + // 1. 결과 객체 비교 검증 + assertThat(result).isEqualTo(responseDto); + + // 2. 좋아요 개수 0 -> 1로 증가했는지 검증 + assertThat(discountInfo.getLikeCount()).isEqualTo(1); + + // 3. 각 메소드가 1번씩만 호출되었는지 검증 + verify(discountInfoRepository, times(1)).findById(1L); + verify(discountInfoRepository, times(1)).save(discountInfo); + verify(discountInfoConverter, times(1)).toDto(discountInfo); + } + + + +} \ No newline at end of file From f3842efb8b0c70c024eeacaf26747f20ce85b98d Mon Sep 17 00:00:00 2001 From: ggamD00 Date: Thu, 25 Jul 2024 22:45:08 +0900 Subject: [PATCH 177/307] =?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 178/307] =?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 From e976a7c49f84221973e353f30886459472313aa5 Mon Sep 17 00:00:00 2001 From: MJJ Date: Fri, 26 Jul 2024 00:35:36 +0900 Subject: [PATCH 179/307] =?UTF-8?q?[fix]=20Optional=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalServiceImpl.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 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 49aa8d34..77d0104e 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 @@ -94,16 +94,11 @@ public ConsumptionAnalysisResponseDTO getTopCategoryAndConsumptionAmount(Long us LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY)); - Optional currentWeekConsumptionAmount = consumptionGoalRepository.findTopConsumptionByCategoryIdAndCurrentWeek( - topConsumptionGoal.getCategory().getId(), startOfWeek, endOfWeek); + ConsumptionGoal currentWeekConsumptionAmount = consumptionGoalRepository.findTopConsumptionByCategoryIdAndCurrentWeek( + topConsumptionGoal.getCategory().getId(), startOfWeek, endOfWeek) + .orElseThrow(IllegalArgumentException::new); - if (currentWeekConsumptionAmount.isEmpty()) { - throw new NoSuchElementException("이번 주 소비 내역을 찾을 수 없습니다."); - } - - Long totalConsumptionAmountForCurrentWeek = currentWeekConsumptionAmount.stream() - .mapToLong(ConsumptionGoal::getConsumeAmount) - .sum(); + Long totalConsumptionAmountForCurrentWeek = currentWeekConsumptionAmount.getConsumeAmount(); return ConsumptionAnalysisConverter.fromEntity(topConsumptionGoal, totalConsumptionAmountForCurrentWeek); } From 5bbf8a21782d8f12b90ed3a14107edd93208a783 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Fri, 26 Jul 2024 11:39:29 +0900 Subject: [PATCH 180/307] =?UTF-8?q?[refactor]=20=EA=B0=81=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EA=B2=8C=EC=8B=9C=EB=AC=BC=EC=9D=B4=20=EC=A2=8B?= =?UTF-8?q?=EC=95=84=EC=9A=94=EC=88=9C=EC=9C=BC=EB=A1=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=EB=90=98=EC=96=B4=20=EB=82=98=EC=98=A4=EB=8F=84?= =?UTF-8?q?=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 --- .../domain/discountinfo/repository/DiscountInfoRepository.java | 3 ++- .../domain/supportinfo/repository/SupportInfoRepository.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) 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 8aa49237..fd935c54 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 @@ -12,7 +12,8 @@ public interface DiscountInfoRepository extends JpaRepository { - @Query("SELECT i FROM DiscountInfo i WHERE (i.startDate <= :endDate AND i.endDate >= :startDate)") + @Query("SELECT i FROM DiscountInfo i WHERE (i.startDate <= :endDate AND i.endDate >= :startDate)" + + " ORDER BY i.likeCount DESC") 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)") 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 4d6ba4b1..36488132 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 @@ -13,7 +13,8 @@ public interface SupportInfoRepository extends JpaRepository { - @Query("SELECT i FROM SupportInfo i WHERE (i.startDate <= :endDate AND i.endDate >= :startDate)") + @Query("SELECT i FROM SupportInfo i WHERE (i.startDate <= :endDate AND i.endDate >= :startDate)" + + " ORDER BY i.likeCount DESC") 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)") From ade576b25d1a39a9430dde19df2f2028c7375268 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Fri, 26 Jul 2024 11:40:31 +0900 Subject: [PATCH 181/307] =?UTF-8?q?[refactor]=20Calendar=20API=20siteUrl?= =?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 --- .../domain/calendar/converter/CalendarConverter.java | 2 ++ .../bbteam/budgetbuddies/domain/calendar/dto/CalendarDto.java | 2 ++ 2 files changed, 4 insertions(+) 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 index e62cd00b..c05f111e 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/calendar/converter/CalendarConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/calendar/converter/CalendarConverter.java @@ -38,6 +38,7 @@ public static CalendarDto.CalendarDiscountInfoDto toCalendarDiscountInfoDto(Disc .startDate(discountInfo.getStartDate()) .endDate(discountInfo.getEndDate()) .discountRate(discountInfo.getDiscountRate()) + .siteUrl(discountInfo.getSiteUrl()) .build(); } @@ -48,6 +49,7 @@ public static CalendarDto.CalendarSupportInfoDto toCalendarSupportInfoDto(Suppor .likeCount(supportInfo.getLikeCount()) .startDate(supportInfo.getStartDate()) .endDate(supportInfo.getEndDate()) + .siteUrl(supportInfo.getSiteUrl()) .build(); } 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 78f6ccf7..3d919f19 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 @@ -33,6 +33,7 @@ public static class CalendarDiscountInfoDto { private LocalDate endDate; private Integer likeCount; private Integer discountRate; + private String siteUrl; } @Getter @@ -44,5 +45,6 @@ public static class CalendarSupportInfoDto { private LocalDate startDate; private LocalDate endDate; private Integer likeCount; + private String siteUrl; } } From 2dcb186ea842cbe9e6197ca97c2b0c148865476c Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Fri, 26 Jul 2024 12:08:50 +0900 Subject: [PATCH 182/307] =?UTF-8?q?[fix]=20=EC=A4=91=EB=B3=B5=20Getter=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 --- 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 21800f97..b8e40e17 100644 --- a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java +++ b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java @@ -19,7 +19,6 @@ @MappedSuperclass @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor -@Getter @SuperBuilder @SoftDelete // boolean 타입의 deleted 필드가 추가 @Getter From cfc673d9fce1fd5a74b9571c1aeb98359c6c722b Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Fri, 26 Jul 2024 12:09:16 +0900 Subject: [PATCH 183/307] =?UTF-8?q?[feat]=20MainPageService=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 --- .../mainpage/service/MainPageService.java | 8 ++++ .../mainpage/service/MainPageServiceImpl.java | 48 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/mainpage/service/MainPageService.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/mainpage/service/MainPageServiceImpl.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/service/MainPageService.java b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/service/MainPageService.java new file mode 100644 index 00000000..5af247fc --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/service/MainPageService.java @@ -0,0 +1,8 @@ +package com.bbteam.budgetbuddies.domain.mainpage.service; + +import com.bbteam.budgetbuddies.domain.mainpage.dto.MainPageResponseDto; + +public interface MainPageService { + + MainPageResponseDto getMainPage(Long userId); +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/service/MainPageServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/service/MainPageServiceImpl.java new file mode 100644 index 00000000..15752357 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/service/MainPageServiceImpl.java @@ -0,0 +1,48 @@ +package com.bbteam.budgetbuddies.domain.mainpage.service; + + +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; +import com.bbteam.budgetbuddies.domain.consumptiongoal.service.ConsumptionGoalService; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; +import com.bbteam.budgetbuddies.domain.discountinfo.service.DiscountInfoService; +import com.bbteam.budgetbuddies.domain.mainpage.converter.MainPageConverter; +import com.bbteam.budgetbuddies.domain.mainpage.dto.MainPageResponseDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; +import com.bbteam.budgetbuddies.domain.supportinfo.service.SupportInfoService; +import com.bbteam.budgetbuddies.enums.Gender; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.time.LocalDate; +import java.util.List; +import java.util.NoSuchElementException; + +@Service +@RequiredArgsConstructor +public class MainPageServiceImpl implements MainPageService{ + private final DiscountInfoService discountInfoService; + private final SupportInfoService supportInfoService; + private final ConsumptionGoalService consumptionGoalService; + + @Override + public MainPageResponseDto getMainPage(Long userId) { + LocalDate now = LocalDate.now(); + + List discountResponseDtoList = discountInfoService.getDiscountsByYearAndMonth(now.getYear(), now.getMonthValue(), 0, 2) + .getContent(); + List supportResponseDtoList = supportInfoService.getSupportsByYearAndMonth(now.getYear(), now.getMonthValue(), 0, 2) + .getContent(); + + List topGoalCategoryResponseDTOList = consumptionGoalService.getTopGoalCategories(1, userId, 0, 0, "NONE"); + if(topGoalCategoryResponseDTOList.size() == 0){ + throw new NoSuchElementException("Category xx"); + } + TopGoalCategoryResponseDTO topGoalCategoryResponseDTO = topGoalCategoryResponseDTOList.get(0); + + ConsumptionGoalResponseListDto userConsumptionGoal = consumptionGoalService.findUserConsumptionGoal(userId, now); + + return MainPageConverter.toMainPageResponseDto(discountResponseDtoList, supportResponseDtoList, + topGoalCategoryResponseDTO, userConsumptionGoal); + } +} From 335acb44dc3314f77ffc7805f0c5e5e2d10227e8 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Fri, 26 Jul 2024 12:09:30 +0900 Subject: [PATCH 184/307] =?UTF-8?q?[feat]=20MainPage=20converter=20?= =?UTF-8?q?=EB=B0=8F=20dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainpage/converter/MainPageConverter.java | 24 +++++++++++++++++++ .../mainpage/dto/MainPageResponseDto.java | 22 +++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/mainpage/converter/MainPageConverter.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/mainpage/dto/MainPageResponseDto.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/converter/MainPageConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/converter/MainPageConverter.java new file mode 100644 index 00000000..02a7e32b --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/converter/MainPageConverter.java @@ -0,0 +1,24 @@ +package com.bbteam.budgetbuddies.domain.mainpage.converter; + +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; +import com.bbteam.budgetbuddies.domain.mainpage.dto.MainPageResponseDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; + +import java.util.List; + +public class MainPageConverter { + public static MainPageResponseDto toMainPageResponseDto( + List discountResponseDtoList, + List supportResponseDtoList, + TopGoalCategoryResponseDTO topGoalCategoryResponseDTO, + ConsumptionGoalResponseListDto consumptionGoalResponseListDto) { + return MainPageResponseDto.builder() + .discountResponseDtoList(discountResponseDtoList) + .supportResponseDtoList(supportResponseDtoList) + .topGoalCategoryResponseDTO(topGoalCategoryResponseDTO) + .consumptionGoalResponseListDto(consumptionGoalResponseListDto) + .build(); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/dto/MainPageResponseDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/dto/MainPageResponseDto.java new file mode 100644 index 00000000..2031c2d3 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/dto/MainPageResponseDto.java @@ -0,0 +1,22 @@ +package com.bbteam.budgetbuddies.domain.mainpage.dto; + +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +@Getter +@Builder +public class MainPageResponseDto { + + private TopGoalCategoryResponseDTO topGoalCategoryResponseDTO; + private ConsumptionGoalResponseListDto consumptionGoalResponseListDto; + private List discountResponseDtoList; + private List supportResponseDtoList; + // 기존 DTO들 활용 + +} From a2be2505a133671e504d5dfca666874257fe3f5a Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Fri, 26 Jul 2024 12:10:48 +0900 Subject: [PATCH 185/307] =?UTF-8?q?[feat]=20MainPage=20Controller=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 --- .../mainpage/controller/MainPageApi.java | 21 ++++++++++++++++ .../controller/MainPageController.java | 24 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageApi.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageController.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageApi.java new file mode 100644 index 00000000..7b10b64b --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageApi.java @@ -0,0 +1,21 @@ +package com.bbteam.budgetbuddies.domain.mainpage.controller; + +import com.bbteam.budgetbuddies.domain.mainpage.dto.MainPageResponseDto; +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 org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestParam; + +public interface MainPageApi { + + @Operation(summary = "[User] 메인페이지 요청 API", description = "userId 기반으로 메인 페이지를 가져옵니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "userId", description = "현재 데이터를 요청하는 사용자입니다. parameter"), + }) + ResponseEntity getMainPage(Long userId); +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageController.java b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageController.java new file mode 100644 index 00000000..0c449f25 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageController.java @@ -0,0 +1,24 @@ +package com.bbteam.budgetbuddies.domain.mainpage.controller; + +import com.bbteam.budgetbuddies.domain.mainpage.dto.MainPageResponseDto; +import com.bbteam.budgetbuddies.domain.mainpage.service.MainPageService; +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 +public class MainPageController implements MainPageApi{ + + private final MainPageService mainPageService; + + @GetMapping("/main") + public ResponseEntity getMainPage + (@RequestParam("userId") Long userId) { + MainPageResponseDto mainPage = mainPageService.getMainPage(userId); + return ResponseEntity.ok(mainPage); + } +} From b2a3b8fb6ab18e3aedd030f466f0de16f8e214e2 Mon Sep 17 00:00:00 2001 From: MJJ Date: Sat, 27 Jul 2024 14:28:47 +0900 Subject: [PATCH 186/307] =?UTF-8?q?[test]=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?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalServiceTest.java | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 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 7d7bec1b..457d4a08 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 @@ -1,10 +1,13 @@ package com.bbteam.budgetbuddies.domain.consumptiongoal.service; import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.BDDMockito.*; import java.time.LocalDate; import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; import java.util.Random; import org.junit.jupiter.api.BeforeEach; @@ -20,9 +23,12 @@ 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.dto.PeerInfoResponseDTO; 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; @DisplayName("ConsumptionGoal 테스트의 ") @ExtendWith(MockitoExtension.class) @@ -32,11 +38,13 @@ class ConsumptionGoalServiceTest { private LocalDate goalMonth; @InjectMocks - private ConsumptionGoalService consumptionGoalService; + private ConsumptionGoalServiceImpl consumptionGoalService; @Mock private CategoryRepository categoryRepository; @Mock private ConsumptionGoalRepository consumptionGoalRepository; + @Mock + private UserRepository userRepository; @BeforeEach void setUp() { @@ -44,7 +52,13 @@ void setUp() { 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()); + user = Mockito.spy(User.builder() + .email("email") + .age(24) + .name("name") + .gender(Gender.MALE) + .phoneNumber("010-1234-5678") + .build()); given(user.getId()).willReturn(-1L); } @@ -155,4 +169,42 @@ void findUserConsumptionGoal_previousMonthAndGoalMonth() { assertThat(result.getConsumptionGoalList()).usingRecursiveComparison() .isEqualTo(List.of(ConsumptionGoalResponseDto.of(goalMonthUserCategoryGoal))); } + + @Test + @DisplayName("getPeerInfo : 또래 나이와 성별 정보를 통해 PeerInfo 조회 성공") + void getPeerInfo_Success() { + // given + when(userRepository.findById(user.getId())).thenReturn(Optional.of(user)); + + // when + int peerAgeStart = 23; + int peerAgeEnd = 25; + String peerGender = "MALE"; + + PeerInfoResponseDTO result = consumptionGoalService.getPeerInfo(user.getId(), peerAgeStart, peerAgeEnd, + peerGender); + + // then + assertThat(result).isNotNull(); + assertThat(result.getPeerAgeStart()).isEqualTo(peerAgeStart); + assertThat(result.getPeerAgeEnd()).isEqualTo(peerAgeEnd); + assertThat(result.getPeerGender()).isEqualTo("MALE"); + } + + @Test + @DisplayName("getPeerInfo : 유저를 찾을 수 없음") + void getPeerInfo_UserNotFound() { + // given + when(userRepository.findById(user.getId())).thenReturn(Optional.empty()); + + // when + int peerAgeStart = 23; + int peerAgeEnd = 25; + String peerGender = "MALE"; + + // then + assertThrows(NoSuchElementException.class, () -> { + consumptionGoalService.getPeerInfo(user.getId(), peerAgeStart, peerAgeEnd, peerGender); + }); + } } \ No newline at end of file From 6aa173be863779b22b39760e623f508f79392b62 Mon Sep 17 00:00:00 2001 From: MJJ Date: Sat, 27 Jul 2024 14:29:49 +0900 Subject: [PATCH 187/307] =?UTF-8?q?[test]=20=EB=98=90=EB=9E=98=EB=93=A4?= =?UTF-8?q?=EC=9D=B4=20=EA=B0=80=EC=9E=A5=20=ED=81=B0=20=EB=AA=A9=ED=91=9C?= =?UTF-8?q?=EB=A1=9C=20=EC=84=B8=EC=9A=B4=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConsumptionGoalRepositoryTest.java | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) 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 571f5189..2c30dabf 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 @@ -16,6 +16,7 @@ import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; import com.bbteam.budgetbuddies.domain.user.entity.User; import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; +import com.bbteam.budgetbuddies.enums.Gender; @DisplayName("ConsumptionGoal 레포지토리 테스트의 ") @DataJpaTest @@ -63,7 +64,8 @@ void findConsumptionGoalByUserIdAndGoalMonth_Success() { setUnselectedConsumptionGoal(mainUser, goalMonth, defaultCategory); // when - List result = consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(mainUser.getId(), + List result = consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth( + mainUser.getId(), goalMonth); // then @@ -71,6 +73,50 @@ void findConsumptionGoalByUserIdAndGoalMonth_Success() { .isEqualTo(List.of(defaultCategoryConsumptionGoal, userCategoryConsumptionGoal)); } + @Test + @DisplayName("또래 나이와 성별 정보를 통해 GoalConsumption 조회 성공") + void findTopCategoriesAndGoalAmount_Success() { + //given + User mainUser = userRepository.save( + User.builder() + .email("email") + .age(24) + .name("name") + .gender(Gender.MALE) + .phoneNumber("010-1234-5678") + .build()); + + Category defaultCategory = categoryRepository.save( + Category.builder().name("디폴트 카테고리").user(null).isDefault(true).build()); + + LocalDate goalMonth = LocalDate.of(2024, 07, 01); + + ConsumptionGoal defaultCategoryConsumptionGoal = consumptionGoalRepository.save(ConsumptionGoal.builder() + .goalAmount(1L) + .consumeAmount(1L) + .user(mainUser) + .goalMonth(goalMonth) + .category(defaultCategory) + .build()); + + // when + int top = 4; + int peerAgeStart = 23; + int peerAgeEnd = 25; + Gender peerGender = Gender.MALE; + + List result = consumptionGoalRepository.findTopCategoriesAndGoalAmount( + top, peerAgeStart, peerAgeEnd, peerGender); + + // then + ConsumptionGoal resultGoal = result.get(0); + assertThat(resultGoal.getGoalAmount()).isEqualTo(1L); + assertThat(resultGoal.getConsumeAmount()).isEqualTo(1L); + assertThat(resultGoal.getUser().getAge()).isEqualTo(24); + assertThat(resultGoal.getCategory().getName()).isEqualTo("디폴트 카테고리"); + assertThat(resultGoal.getUser().getGender()).isEqualTo(Gender.MALE); + } + 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()); From 496e6a12da8d0784ae70755654e752e4b11adc61 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Sat, 27 Jul 2024 17:15:58 +0900 Subject: [PATCH 188/307] =?UTF-8?q?[feat]=20categories/get/{userId}=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 --- .../category/controller/CategoryController.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 beb16f89..671b272a 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 @@ -13,6 +13,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.List; + @RestController @RequiredArgsConstructor @RequestMapping("/categories") @@ -35,4 +37,18 @@ public ResponseEntity createCategory( CategoryResponseDTO response = categoryService.createCategory(categoryRequestDTO); return ResponseEntity.ok(response); } + + + @Operation(summary = "유저 개인의 카테고리 조회", description = "유저의 카테고리(default + 개인 custom)를 조회합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "401", description = "Unauthorized"), + @ApiResponse(responseCode = "403", description = "Forbidden"), + @ApiResponse(responseCode = "404", description = "Not Found") + }) + @GetMapping("/get/{userId}") + public ResponseEntity> getUserCategories(@PathVariable Long userId) { + List response = categoryService.getUserCategories(userId); + return ResponseEntity.ok(response); + } } From b799cb69dc0dd3afddcda177f475d5370297c540 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Sat, 27 Jul 2024 17:16:36 +0900 Subject: [PATCH 189/307] =?UTF-8?q?[feat]=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=ED=95=B4?= =?UTF-8?q?=EC=98=A4=EB=8A=94=20getUserCategories()=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../category/service/CategoryService.java | 3 +++ .../category/service/CategoryServiceImpl.java | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) 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 index 352b64c6..1ba8ec9c 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryService.java @@ -3,7 +3,10 @@ import com.bbteam.budgetbuddies.domain.category.dto.CategoryRequestDTO; import com.bbteam.budgetbuddies.domain.category.dto.CategoryResponseDTO; +import java.util.List; + public interface CategoryService { CategoryResponseDTO createCategory(CategoryRequestDTO categoryRequestDTO); + List getUserCategories(Long userId); } 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 52b26658..47bf1a9d 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 @@ -11,6 +11,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.stream.Collectors; + @Service @RequiredArgsConstructor @Transactional @@ -35,4 +38,20 @@ public CategoryResponseDTO createCategory(CategoryRequestDTO categoryRequestDTO) return categoryConverter.toCategoryResponseDTO(savedCategory); } + + @Override + public List getUserCategories(Long userId) { + + userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found with id: " + userId)); + + List categories = categoryRepository.findUserCategoryByUserId(userId); + return categories.stream() + .map(category -> CategoryResponseDTO.builder() + .id(category.getId()) + .name(category.getName()) + .isDefault(category.getIsDefault()) + .build()) + .collect(Collectors.toList()); + } } \ No newline at end of file From efd4f0ee461a0a8d5d24c45a798a2dd67254577d Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Sat, 27 Jul 2024 17:36:49 +0900 Subject: [PATCH 190/307] =?UTF-8?q?[refactor]=20converter=EB=A5=BC=20?= =?UTF-8?q?=ED=86=B5=ED=95=B4=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B0=B8?= =?UTF-8?q?=EC=A1=B0=20=ED=98=95=EC=8B=9D=EC=9C=BC=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 --- .../domain/category/service/CategoryServiceImpl.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 47bf1a9d..2df03410 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 @@ -47,11 +47,7 @@ public List getUserCategories(Long userId) { List categories = categoryRepository.findUserCategoryByUserId(userId); return categories.stream() - .map(category -> CategoryResponseDTO.builder() - .id(category.getId()) - .name(category.getName()) - .isDefault(category.getIsDefault()) - .build()) + .map(categoryConverter::toCategoryResponseDTO) .collect(Collectors.toList()); } } \ No newline at end of file From 6711522b180fd2faac31f70e4973f1ec461ba808 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Sat, 27 Jul 2024 17:44:41 +0900 Subject: [PATCH 191/307] =?UTF-8?q?[refactor]=20CategoryApi=20=EC=9D=B8?= =?UTF-8?q?=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=EB=A1=9C=20swagger=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../category/controller/CategoryApi.java | 40 +++++++++++++++++++ .../controller/CategoryController.java | 30 ++------------ 2 files changed, 44 insertions(+), 26 deletions(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/category/controller/CategoryApi.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/controller/CategoryApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/controller/CategoryApi.java new file mode 100644 index 00000000..b299a4a0 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/controller/CategoryApi.java @@ -0,0 +1,40 @@ +package com.bbteam.budgetbuddies.domain.category.controller; + +import com.bbteam.budgetbuddies.domain.category.dto.CategoryRequestDTO; +import com.bbteam.budgetbuddies.domain.category.dto.CategoryResponseDTO; +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 org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +public interface CategoryApi { + + @Operation(summary = "카테고리 추가", description = "사용자가 직접 카테고리를 추가합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + @ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) + }) + @PostMapping("/add") + ResponseEntity createCategory( + @Parameter(description = "user_id, name(사용자가 입력한 카테고리명), is_default(default 카테고리 여부)로 request") + @RequestBody CategoryRequestDTO categoryRequestDTO); + + + @Operation(summary = "유저 개인의 카테고리 조회", description = "유저의 카테고리(default + 개인 custom)를 조회합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "401", description = "Unauthorized"), + @ApiResponse(responseCode = "403", description = "Forbidden"), + @ApiResponse(responseCode = "404", description = "Not Found") + }) + @GetMapping("/get/{userId}") + ResponseEntity> getUserCategories(@PathVariable Long userId); +} 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 671b272a..49b9dfdf 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 @@ -3,12 +3,6 @@ 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.*; @@ -18,34 +12,18 @@ @RestController @RequiredArgsConstructor @RequestMapping("/categories") -public class CategoryController { +public class CategoryController implements CategoryApi { 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))) - }) + @Override @PostMapping("/add") - public ResponseEntity createCategory( - @Parameter(description = "user_id, name(사용자가 입력한 카테고리명), is_default(default 카테고리 여부)로 request") - @RequestBody CategoryRequestDTO categoryRequestDTO - ) { + public ResponseEntity createCategory(@RequestBody CategoryRequestDTO categoryRequestDTO) { CategoryResponseDTO response = categoryService.createCategory(categoryRequestDTO); return ResponseEntity.ok(response); } - - @Operation(summary = "유저 개인의 카테고리 조회", description = "유저의 카테고리(default + 개인 custom)를 조회합니다.") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "401", description = "Unauthorized"), - @ApiResponse(responseCode = "403", description = "Forbidden"), - @ApiResponse(responseCode = "404", description = "Not Found") - }) + @Override @GetMapping("/get/{userId}") public ResponseEntity> getUserCategories(@PathVariable Long userId) { List response = categoryService.getUserCategories(userId); From 6fdfd223f625efc33e70812777430d585b386c4f Mon Sep 17 00:00:00 2001 From: MJJ Date: Sat, 27 Jul 2024 21:54:02 +0900 Subject: [PATCH 192/307] =?UTF-8?q?[fix]=20=ED=8A=B9=EC=A0=95=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=A4=91=20=EC=9D=B4=EB=B2=88=20?= =?UTF-8?q?=EC=A3=BC=20=EC=86=8C=EB=B9=84=EB=AA=A9=ED=91=9C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20limit=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumptiongoal/repository/ConsumptionGoalRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 40ee25d7..972a8c7c 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 @@ -30,7 +30,7 @@ Optional findConsumptionGoalByUserAndCategoryAndGoalMonth(User LocalDate goalMonth); @Query("SELECT cg FROM ConsumptionGoal cg JOIN cg.category c WHERE c.id = :categoryId AND cg.goalMonth " - + "BETWEEN :startOfWeek AND :endOfWeek ORDER BY cg.consumeAmount DESC") + + "BETWEEN :startOfWeek AND :endOfWeek ORDER BY cg.consumeAmount DESC limit 1") Optional findTopConsumptionByCategoryIdAndCurrentWeek(@Param("categoryId") Long categoryId, @Param("startOfWeek") LocalDate startOfWeek, @Param("endOfWeek") LocalDate endOfWeek); } \ No newline at end of file From c2b057ff688ca70cda9ca442c307ec3ed0222b2b Mon Sep 17 00:00:00 2001 From: MJJ Date: Sat, 27 Jul 2024 21:54:30 +0900 Subject: [PATCH 193/307] =?UTF-8?q?[test]=20=EB=98=90=EB=9E=98=EB=93=A4?= =?UTF-8?q?=EC=9D=B4=20=EA=B0=80=EC=9E=A5=20=ED=81=B0=20=EB=AA=A9=ED=91=9C?= =?UTF-8?q?=EB=A1=9C=20=EC=84=B8=EC=9A=B4=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=EC=99=80=20=EA=B7=B8=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=EC=97=90=EC=84=9C=20=EC=9D=B4=EB=B2=88=20=EC=A3=BC?= =?UTF-8?q?=EC=9D=98=20=EC=86=8C=EB=B9=84=20=EB=AA=A9=ED=91=9C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConsumptionGoalRepositoryTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) 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 2c30dabf..13deca84 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 @@ -4,6 +4,7 @@ import java.time.LocalDate; import java.util.List; +import java.util.Optional; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -117,6 +118,54 @@ void findTopCategoriesAndGoalAmount_Success() { assertThat(resultGoal.getUser().getGender()).isEqualTo(Gender.MALE); } + @Test + @DisplayName("또래들이 가장 큰 목표로 세운 카테고리와 그 카테고리에서 이번 주의 소비 목표 조회 성공") + void findTopConsumptionByCategoryIdAndCurrentWeek_Success() { + // given + LocalDate startOfWeek = LocalDate.of(2024, 7, 1); // 월요일 + LocalDate endOfWeek = LocalDate.of(2024, 7, 7); // 일요일 + + User mainUser = userRepository.save(User.builder() + .email("email") + .age(24) + .name("name") + .gender(Gender.MALE) + .phoneNumber("010-1234-5678") + .build()); + + Category category = categoryRepository.save(Category.builder() + .name("Test Category") + .user(mainUser) + .isDefault(false) + .build()); + + ConsumptionGoal goal1 = consumptionGoalRepository.save(ConsumptionGoal.builder() + .goalAmount(5000L) + .consumeAmount(2000L) + .user(mainUser) + .category(category) + .goalMonth(startOfWeek) + .build()); + + ConsumptionGoal goal2 = consumptionGoalRepository.save(ConsumptionGoal.builder() + .goalAmount(3000L) + .consumeAmount(1500L) + .user(mainUser) + .category(category) + .goalMonth(startOfWeek) + .build()); + + // when + Optional result = consumptionGoalRepository.findTopConsumptionByCategoryIdAndCurrentWeek( + category.getId(), startOfWeek, endOfWeek); + + // then + ConsumptionGoal topGoal = result.get(); + assertThat(topGoal.getConsumeAmount()).isEqualTo(2000L); + assertThat(topGoal.getGoalAmount()).isEqualTo(5000L); + assertThat(topGoal.getCategory().getId()).isEqualTo(category.getId()); + } + 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()); From e5ed1589f05f86ade712aa39347120a548067521 Mon Sep 17 00:00:00 2001 From: MJJ Date: Sat, 27 Jul 2024 22:11:12 +0900 Subject: [PATCH 194/307] =?UTF-8?q?[fix]=20=EC=9E=98=EB=AA=BB=20=EC=BB=A4?= =?UTF-8?q?=EB=B0=8B=EB=90=9C=20=ED=8C=8C=EC=9D=BC=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- naver-intellij-formatter.xml | 62 ------------------------------------ 1 file changed, 62 deletions(-) delete mode 100644 naver-intellij-formatter.xml diff --git a/naver-intellij-formatter.xml b/naver-intellij-formatter.xml deleted file mode 100644 index 658fc659..00000000 --- a/naver-intellij-formatter.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - From b12d3c13162c1a67b7f205cef33c8565af1e5599 Mon Sep 17 00:00:00 2001 From: MJJ Date: Sun, 28 Jul 2024 00:02:45 +0900 Subject: [PATCH 195/307] =?UTF-8?q?[test]=20=EB=98=90=EB=9E=98=EB=93=A4?= =?UTF-8?q?=EC=9D=B4=20=EC=84=B8=EC=9A=B4=20=EA=B0=80=EC=9E=A5=20=ED=81=B0?= =?UTF-8?q?=20=EB=AA=A9=ED=91=9C=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC?= =?UTF-8?q?=EC=99=80=20=EA=B7=B8=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=9D=B4=EB=B2=88=20=EC=A3=BC=20=EC=86=8C?= =?UTF-8?q?=EB=B9=84=20=EA=B8=88=EC=95=A1=20=EC=A1=B0=ED=9A=8C=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalServiceTest.java | 52 ++++++++++++++++--- 1 file changed, 45 insertions(+), 7 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 360cba68..db3cd7dd 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 @@ -4,7 +4,9 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.BDDMockito.*; +import java.time.DayOfWeek; import java.time.LocalDate; +import java.time.temporal.TemporalAdjusters; import java.util.List; import java.util.NoSuchElementException; import java.util.Optional; @@ -23,6 +25,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.dto.ConsumptionAnalysisResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalListRequestDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalRequestDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseDto; @@ -58,13 +61,7 @@ void setUp() { int randomDay = random.nextInt(30) + 1; goalMonthRandomDay = LocalDate.of(GOAL_MONTH.getYear(), GOAL_MONTH.getMonth(), randomDay); - user = Mockito.spy(User.builder() - .email("email") - .age(24) - .name("name") - .gender(Gender.MALE) - .phoneNumber("010-1234-5678") - .build()); + user = Mockito.spy(User.builder().email("email").age(24).name("name").gender(Gender.MALE).phoneNumber("010-1234-5678").build()); given(user.getId()).willReturn(-1L); given(userRepository.findById(user.getId())).willReturn(Optional.ofNullable(user)); } @@ -273,4 +270,45 @@ void getPeerInfo_UserNotFound() { consumptionGoalService.getPeerInfo(user.getId(), peerAgeStart, peerAgeEnd, peerGender); }); } + + @Test + @DisplayName("getTopCategoryAndConsumptionAmount : 가장 큰 계획 카테고리와 이번 주 소비 금액 조회 성공") + void getTopCategoryAndConsumptionAmount_Success() { + // given + Category defaultCategory = Mockito.spy(Category.builder().name("디폴트 카테고리").user(null).isDefault(true).build()); + given(defaultCategory.getId()).willReturn(-1L); + + ConsumptionGoal topConsumptionGoal = ConsumptionGoal.builder() + .goalAmount(5000L) + .consumeAmount(3000L) + .user(user) + .category(defaultCategory) + .goalMonth(goalMonthRandomDay) + .build(); + + ConsumptionGoal currentWeekConsumptionGoal = ConsumptionGoal.builder() + .goalAmount(5000L) + .consumeAmount(2000L) + .user(user) + .category(defaultCategory) + .goalMonth(goalMonthRandomDay) + .build(); + + LocalDate startOfWeek = goalMonthRandomDay.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); + LocalDate endOfWeek = goalMonthRandomDay.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY)); + + given(userRepository.findById(user.getId())).willReturn(Optional.of(user)); + given(consumptionGoalRepository.findTopCategoriesAndGoalAmount(1, 23, 25, Gender.MALE)) + .willReturn(List.of(topConsumptionGoal)); + given(consumptionGoalRepository.findTopConsumptionByCategoryIdAndCurrentWeek( + defaultCategory.getId(), startOfWeek, endOfWeek)) + .willReturn(Optional.of(currentWeekConsumptionGoal)); + + // when + ConsumptionAnalysisResponseDTO result = consumptionGoalService.getTopCategoryAndConsumptionAmount(user.getId()); + + // then + assertThat(result.getGoalCategory()).isEqualTo(defaultCategory.getName()); + assertThat(result.getCurrentWeekConsumptionAmount()).isEqualTo(currentWeekConsumptionGoal.getConsumeAmount()); + } } \ No newline at end of file From d32f5f05d54ed0a19aa9d4d9f6633f1601e4f7c5 Mon Sep 17 00:00:00 2001 From: MJJ Date: Sun, 28 Jul 2024 00:35:03 +0900 Subject: [PATCH 196/307] =?UTF-8?q?[test]=20=EB=98=90=EB=9E=98=EB=93=A4?= =?UTF-8?q?=EC=9D=B4=20=EC=84=B8=EC=9A=B4=20=EA=B0=80=EC=9E=A5=20=ED=81=B0?= =?UTF-8?q?=20=EB=AA=A9=ED=91=9C=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20top=204=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalServiceTest.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) 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 db3cd7dd..ca282360 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 @@ -31,6 +31,7 @@ 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; import com.bbteam.budgetbuddies.domain.user.entity.User; @@ -311,4 +312,64 @@ void getTopCategoryAndConsumptionAmount_Success() { assertThat(result.getGoalCategory()).isEqualTo(defaultCategory.getName()); assertThat(result.getCurrentWeekConsumptionAmount()).isEqualTo(currentWeekConsumptionGoal.getConsumeAmount()); } + + @Test + @DisplayName("getTopGoalCategories : 또래들이 세운 가장 큰 목표 카테고리 조회 top 4 성공") + void getTopGoalCategories_Success() { + // given + Category defaultCategory = Mockito.spy(Category.builder().name("디폴트 카테고리").user(null).isDefault(true).build()); + Category defaultCategory2 = Mockito.spy(Category.builder().name("디폴트 카테고리2").user(null).isDefault(true).build()); + Category defaultCategory3 = Mockito.spy(Category.builder().name("디폴트 카테고리3").user(null).isDefault(true).build()); + Category defaultCategory4 = Mockito.spy(Category.builder().name("디폴트 카테고리4").user(null).isDefault(true).build()); + + ConsumptionGoal topConsumptionGoal1 = ConsumptionGoal.builder() + .goalAmount(5000L) + .consumeAmount(3000L) + .user(user) + .category(defaultCategory) + .goalMonth(goalMonthRandomDay) + .build(); + + ConsumptionGoal topConsumptionGoal2 = ConsumptionGoal.builder() + .goalAmount(6000L) + .consumeAmount(3000L) + .user(user) + .category(defaultCategory2) + .goalMonth(goalMonthRandomDay) + .build(); + + ConsumptionGoal topConsumptionGoal3 = ConsumptionGoal.builder() + .goalAmount(7000L) + .consumeAmount(3000L) + .user(user) + .category(defaultCategory3) + .goalMonth(goalMonthRandomDay) + .build(); + + ConsumptionGoal topConsumptionGoal4 = ConsumptionGoal.builder() + .goalAmount(8000L) + .consumeAmount(3000L) + .user(user) + .category(defaultCategory4) + .goalMonth(goalMonthRandomDay) + .build(); + + given(userRepository.findById(user.getId())).willReturn(Optional.of(user)); + given(consumptionGoalRepository.findTopCategoriesAndGoalAmount(4, 23, 25, Gender.MALE)) + .willReturn(List.of(topConsumptionGoal1, topConsumptionGoal2, topConsumptionGoal3, topConsumptionGoal4)); + + // when + List result = consumptionGoalService.getTopGoalCategories(4, user.getId(), 0, 0, "none"); + + // then + assertThat(result).hasSize(4); + assertThat(result.get(0).getCategoryName()).isEqualTo(defaultCategory.getName()); + assertThat(result.get(0).getGoalAmount()).isEqualTo(topConsumptionGoal1.getGoalAmount()); + assertThat(result.get(1).getCategoryName()).isEqualTo(defaultCategory2.getName()); + assertThat(result.get(1).getGoalAmount()).isEqualTo(topConsumptionGoal2.getGoalAmount()); + assertThat(result.get(2).getCategoryName()).isEqualTo(defaultCategory3.getName()); + assertThat(result.get(2).getGoalAmount()).isEqualTo(topConsumptionGoal3.getGoalAmount()); + assertThat(result.get(3).getCategoryName()).isEqualTo(defaultCategory4.getName()); + assertThat(result.get(3).getGoalAmount()).isEqualTo(topConsumptionGoal4.getGoalAmount()); + } } \ No newline at end of file From bda7879b6f47bf6175df01bdcbe45409b460fee0 Mon Sep 17 00:00:00 2001 From: MJJ Date: Sun, 28 Jul 2024 00:46:07 +0900 Subject: [PATCH 197/307] =?UTF-8?q?[fix]=20application.yaml=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 --- .gitignore | 2 +- src/main/resources/application.yaml | 17 ----------------- 2 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 src/main/resources/application.yaml diff --git a/.gitignore b/.gitignore index 7dbfa83c..38944b87 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,4 @@ out/ .vscode/ ### Setting File ### -src/main/resources/application.yml \ No newline at end of file +src/main/resources/** \ No newline at end of file diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml deleted file mode 100644 index a36ce978..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: update - - datasource: - url: jdbc:mysql://localhost:3306/budgetbuddies # mysql ?? ?? (?? ?? DB? ?? ? ??) - driver-class-name: com.mysql.cj.jdbc.Driver - username: root - password: 1226 # db ???? \ No newline at end of file From 1fa8582cda26c2780bbbc5f8dce9ee9550492fda Mon Sep 17 00:00:00 2001 From: MJJ Date: Sun, 28 Jul 2024 01:01:15 +0900 Subject: [PATCH 198/307] =?UTF-8?q?[refactor]=20ConsumptionGoalServiceImpl?= =?UTF-8?q?=20checkPeerInfo=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalServiceImpl.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 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 7ca9cc5e..6cbb5a00 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 @@ -53,9 +53,7 @@ public class ConsumptionGoalServiceImpl implements ConsumptionGoalService { public List getTopGoalCategories(int top, Long userId, int peerAgeS, int peerAgeE, String peerG) { - User user = findUserById(userId); - - checkPeerInfo(user, peerAgeS, peerAgeE, peerG); + checkPeerInfo(userId, peerAgeS, peerAgeE, peerG); List topGoals = consumptionGoalRepository.findTopCategoriesAndGoalAmount(top, peerAgeStart, peerAgeEnd, peerGender); @@ -66,9 +64,7 @@ public List getTopGoalCategories(int top, Long userI @Transactional(readOnly = true) public PeerInfoResponseDTO getPeerInfo(Long userId, int peerAgeS, int peerAgeE, String peerG) { - User user = findUserById(userId); - - checkPeerInfo(user, peerAgeS, peerAgeE, peerG); + checkPeerInfo(userId, peerAgeS, peerAgeE, peerG); return PeerInfoConverter.fromEntity(peerAgeStart, peerAgeEnd, peerGender); } @@ -77,9 +73,7 @@ public PeerInfoResponseDTO getPeerInfo(Long userId, int peerAgeS, int peerAgeE, @Transactional(readOnly = true) public ConsumptionAnalysisResponseDTO getTopCategoryAndConsumptionAmount(Long userId) { - User user = findUserById(userId); - - checkPeerInfo(user, 0, 0, "none"); + checkPeerInfo(userId, 0, 0, "none"); ConsumptionGoal topConsumptionGoal = consumptionGoalRepository.findTopCategoriesAndGoalAmount(1, peerAgeStart, peerAgeEnd, peerGender).get(0); @@ -146,7 +140,9 @@ private User findUserById(Long userId) { return user.get(); } - private void checkPeerInfo(User user, int peerAgeS, int peerAgeE, String peerG) { + private void checkPeerInfo(Long userId, int peerAgeS, int peerAgeE, String peerG) { + + User user = findUserById(userId); Gender gender = Gender.valueOf(peerG.toUpperCase()); From a090fdb7a9c4695f07db713ea3a34c983353b6a4 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 28 Jul 2024 16:39:26 +0900 Subject: [PATCH 199/307] =?UTF-8?q?[fix]=20@ColumnDefault("0")=EB=A5=BC=20?= =?UTF-8?q?@Builder.Default=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/supportinfo/entity/SupportInfo.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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 cc83973e..f811f7ee 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 @@ -3,10 +3,7 @@ import com.bbteam.budgetbuddies.common.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import lombok.experimental.SuperBuilder; import org.hibernate.annotations.ColumnDefault; @@ -26,10 +23,10 @@ public class SupportInfo extends BaseEntity { private LocalDate endDate; - @ColumnDefault("0") + @Builder.Default private Integer likeCount = 0; - @ColumnDefault("0") + @Builder.Default private Integer anonymousNumber = 0; @Column(length = 1000) From d8a1657059eb16dd59852a4907e1ae878c831ee8 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 28 Jul 2024 16:39:48 +0900 Subject: [PATCH 200/307] =?UTF-8?q?[feat]=20isLike=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20toggleLike()=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=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 --- .../supportinfolike/entity/SupportInfoLike.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/entity/SupportInfoLike.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/entity/SupportInfoLike.java index 1be0154f..1480282f 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/entity/SupportInfoLike.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/entity/SupportInfoLike.java @@ -7,10 +7,7 @@ import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import lombok.experimental.SuperBuilder; @Entity @@ -28,4 +25,11 @@ public class SupportInfoLike extends BaseEntity { @JoinColumn(name = "support_info_id") private SupportInfo supportInfo; + @Builder.Default + private Boolean isLike = false; + + public void toggleLike() { + isLike = !isLike; + } + } From 0ff2a72fa8a330b5bec29ad0c0ac57bfb1d955e0 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 28 Jul 2024 16:40:16 +0900 Subject: [PATCH 201/307] =?UTF-8?q?[refactor]=20isLike=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/SupportInfoServiceImpl.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 index 6f5568f9..25530dd8 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java @@ -96,14 +96,22 @@ public SupportResponseDto toggleLike(Long userId, Long supportInfoId) { Optional existingLike = supportInfoLikeRepository.findByUserAndSupportInfo(user, supportInfo); if (existingLike.isPresent()) { - // 이미 좋아요를 누른 상태라면 - supportInfoLikeRepository.delete(existingLike.get()); - supportInfo.subLikeCount(); + // 이미 객체가 존재한다면 + if (existingLike.get().getIsLike()) { + // 좋아요를 누른 상태라면 + existingLike.get().toggleLike(); + supportInfo.subLikeCount(); + } else { + // 좋아요를 누르지 않은 상태라면 + existingLike.get().toggleLike(); + supportInfo.addLikeCount(); + } } else { // 아직 좋아요를 누르지 않은 상태라면 SupportInfoLike newLike = SupportInfoLike.builder() .user(user) .supportInfo(supportInfo) + .isLike(true) .build(); supportInfoLikeRepository.save(newLike); supportInfo.addLikeCount(); From f8d9ccc754e3338000bad325ff83effe728dc221 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 28 Jul 2024 16:40:44 +0900 Subject: [PATCH 202/307] =?UTF-8?q?[test]=20SupportInfoRepository=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 특정 년월에 속하는 지원 정보 데이터 조회 성공 테스트 - 특정 년월에 속하는 지원 정보 데이터 조회 실패 테스트 --- .../repository/SupportInfoRepositoryTest.java | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) 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 index 7d490ee8..8032ac12 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepositoryTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepositoryTest.java @@ -1,24 +1,78 @@ 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.assertj.core.api.Assertions; +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 org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; -@SpringBootTest +@DataJpaTest @Transactional +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) class SupportInfoRepositoryTest { @Autowired SupportInfoRepository supportInfoRepository; + @Test + @DisplayName("특정 년월에 속하는 지원 정보 데이터 조회 성공") + void findByDateRangeSuccess() { + // given + SupportInfo discount1 = SupportInfo.builder() + .title("지원정보1") + .startDate(LocalDate.of(2024, 7, 1)) + .endDate(LocalDate.of(2024, 7, 21)) + .siteUrl("http://example1.com") + .build(); + supportInfoRepository.save(discount1); + + // when + Page results = supportInfoRepository.findByDateRange( + LocalDate.of(2024, 7, 1), + LocalDate.of(2024, 7, 31), + PageRequest.of(0, 10) + ); + + // then + assertThat(results).hasSize(1); + assertThat(results.getContent().get(0).getTitle()).isEqualTo("지원정보1"); + } + + @Test + @DisplayName("특정 년월에 속하는 지원 정보 데이터 조회 실패") + void findByDateRangeFailure() { + // given + SupportInfo discount1 = SupportInfo.builder() + .title("지원정보1") + .startDate(LocalDate.of(2024, 6, 1)) + .endDate(LocalDate.of(2024, 6, 21)) + .siteUrl("http://example1.com") + .build(); + supportInfoRepository.save(discount1); + + // when + Page results = supportInfoRepository.findByDateRange( + LocalDate.of(2024, 7, 1), + LocalDate.of(2024, 7, 31), + PageRequest.of(0, 10) + ); + + // then + assertThat(results).hasSize(0); + } @Test void findByMonthTest(){ From 3d83d9f788b683783a27b143fa9814c4e9e64048 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 28 Jul 2024 16:41:07 +0900 Subject: [PATCH 203/307] =?UTF-8?q?[test]=20SupportInfoService=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 지원 정보 2개를 등록한 뒤, 호출했을 때 2개가 정상적으로 반환되는지 검증 - 지원 정보 등록이 정상적으로 되는지 검증 - 좋아요를 처음 눌렀을 때 1을 반환하는지 검증 --- .../service/SupportInfoServiceTest.java | 222 ++++++++++++++++++ 1 file changed, 222 insertions(+) create mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java new file mode 100644 index 00000000..c8aa3ddd --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java @@ -0,0 +1,222 @@ +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.discountinfo.service.DiscountInfoServiceImpl; +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 com.bbteam.budgetbuddies.enums.Gender; +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.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; + +@Transactional +@ExtendWith(MockitoExtension.class) +class SupportInfoServiceTest { + + @Mock + private SupportInfoRepository supportInfoRepository; + + @Mock + private SupportInfoLikeRepository supportInfoLikeRepository; + + @Mock + private SupportInfoConverter supportInfoConverter; + + @Mock + private UserRepository userRepository; + + @InjectMocks + private SupportInfoServiceImpl supportInfoService; + + @Test + @DisplayName("지원 정보 2개를 등록한 뒤, 호출했을 때 2개가 정상적으로 반환되는지 검증") + void getSupportsByYearAndMonthTest() { + // given + LocalDate startDate = LocalDate.of(2024, 7, 1); + LocalDate endDate = LocalDate.of(2024, 7, 31); + Pageable pageable = PageRequest.of(0, 10); + + SupportInfo support1 = SupportInfo.builder() + .title("Support 1") + .startDate(startDate) + .endDate(endDate) + .siteUrl("http://example1.com") + .build(); + + SupportInfo support2 = SupportInfo.builder() + .title("Support 2") + .startDate(startDate) + .endDate(endDate) + .siteUrl("http://example2.com") + .build(); + + List supports = List.of(support1, support2); + Page supportPage = new PageImpl<>(supports, pageable, supports.size()); + + SupportResponseDto dto1 = new SupportResponseDto(); + SupportResponseDto dto2 = new SupportResponseDto(); + + when(supportInfoRepository.findByDateRange(startDate, endDate, pageable)).thenReturn(supportPage); + when(supportInfoConverter.toDto(support1)).thenReturn(dto1); + when(supportInfoConverter.toDto(support2)).thenReturn(dto2); + + // when + Page result = supportInfoService.getSupportsByYearAndMonth(2024, 7, 0, 10); + + // then + // 1. 데이터가 2개인지 검증 + // 2. 각 데이터 내용이 일치하는지 검증 + assertThat(result.getContent()).hasSize(2); + assertThat(result.getContent().get(0)).isEqualTo(dto1); + assertThat(result.getContent().get(1)).isEqualTo(dto2); + + // 3. 각 메소드가 1번씩만 호출되었는지 검증 + verify(supportInfoRepository, times(1)).findByDateRange(startDate, endDate, pageable); + verify(supportInfoConverter, times(1)).toDto(support1); + verify(supportInfoConverter, times(1)).toDto(support2); + } + + @Test + @DisplayName("지원 정보 등록이 정상적으로 되는지 검증") + void registerSupportInfoTest() { + // given + SupportRequestDto requestDto = SupportRequestDto.builder() + .title("지원 정보 제목") + .startDate(LocalDate.of(2024, 7, 1)) + .endDate(LocalDate.of(2024, 7, 21)) + .siteUrl("http://example.com") + .build(); + + SupportInfo entity = SupportInfo.builder() + .title("지원 정보 제목") + .startDate(LocalDate.of(2024, 7, 1)) + .endDate(LocalDate.of(2024, 7, 21)) + .siteUrl("http://example.com") + .build(); + + SupportResponseDto responseDto = SupportResponseDto.builder() + .id(1L) + .title("지원 정보 제목") + .startDate(LocalDate.of(2024, 7, 1)) + .endDate(LocalDate.of(2024, 7, 21)) + .siteUrl("http://example.com") + .likeCount(0) + .anonymousNumber(0) + .build(); + + when(supportInfoConverter.toEntity(requestDto)).thenReturn(entity); + when(supportInfoRepository.save(entity)).thenReturn(entity); + when(supportInfoConverter.toDto(entity)).thenReturn(responseDto); + + // when + SupportResponseDto result = supportInfoService.registerSupportInfo(requestDto); + + // then + // 1. 데이터 내용이 일치하는지 검증 + assertThat(result).isEqualTo(responseDto); + + // 2. 각 메소드가 1번씩만 호출되었는지 검증 + verify(supportInfoConverter, times(1)).toEntity(requestDto); + verify(supportInfoRepository, times(1)).save(entity); + verify(supportInfoConverter, times(1)).toDto(entity); + } + + @Test + @DisplayName("좋아요를 처음 눌렀을 때 1을 반환하는지 검증") + void toggleLikeTest() { + // given + User user = User.builder() + .id(1L) + .phoneNumber("010-1234-5678") + .name("John") + .age(30) + .gender(Gender.MALE) + .email("john.doe@example.com") + .photoUrl("http://example.com/photo.jpg") + .consumptionPattern("Regular") + .lastLoginAt(LocalDateTime.now()) + .build(); + + SupportInfo supportInfo = SupportInfo.builder() + .id(1L) + .title("지원 정보 제목") + .startDate(LocalDate.of(2024, 7, 20)) + .endDate(LocalDate.of(2024, 7, 30)) + .likeCount(0) + .anonymousNumber(0) + .siteUrl("http://example.com") + .build(); + + SupportInfoLike supportInfoLike = SupportInfoLike.builder() + .id(1L) + .user(user) + .supportInfo(supportInfo) + .isLike(false) + .build(); + + SupportResponseDto responseDto = SupportResponseDto.builder() + .id(1L) + .title("지원 정보 제목") + .startDate(LocalDate.of(2024, 7, 20)) + .endDate(LocalDate.of(2024, 7, 30)) + .likeCount(1) + .anonymousNumber(0) + .siteUrl("http://example.com") + .build(); + + when(supportInfoRepository.save(any(SupportInfo.class))).thenReturn(supportInfo); + when(userRepository.findById(anyLong())).thenReturn(Optional.of(user)); + when(supportInfoRepository.findById(anyLong())).thenReturn(Optional.of(supportInfo)); + when(supportInfoLikeRepository.findByUserAndSupportInfo(user, supportInfo)).thenReturn(Optional.of(supportInfoLike)); + when(supportInfoConverter.toDto(any(SupportInfo.class))).thenReturn(responseDto); + + // when + SupportResponseDto result = supportInfoService.toggleLike(1L, 1L); + + // then + // 1. 결과 객체 비교 검증 + assertThat(result).isEqualTo(responseDto); + + // 2. 좋아요 개수 0 -> 1로 증가했는지 검증 + assertThat(supportInfo.getLikeCount()).isEqualTo(1); + + // 3. 각 메소드가 1번씩만 호출되었는지 검증 + verify(supportInfoRepository, times(1)).findById(1L); + verify(supportInfoRepository, times(1)).save(supportInfo); + verify(supportInfoConverter, times(1)).toDto(supportInfo); + } + +} \ No newline at end of file From ccc22114981fb3e96225c98a0aeb67c7c18b09ec Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 28 Jul 2024 17:52:39 +0900 Subject: [PATCH 204/307] =?UTF-8?q?[refactor]=20deleted=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EB=AA=85=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/bbteam/budgetbuddies/common/BaseEntity.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java index b8e40e17..ae774f30 100644 --- a/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java +++ b/src/main/java/com/bbteam/budgetbuddies/common/BaseEntity.java @@ -8,7 +8,7 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; -import org.hibernate.annotations.SoftDelete; +import org.hibernate.annotations.*; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -20,7 +20,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @SuperBuilder -@SoftDelete // boolean 타입의 deleted 필드가 추가 +@SoftDelete(columnName = "deleted") // boolean 타입의 deleted 필드가 추가 @Getter public abstract class BaseEntity { @@ -36,4 +36,7 @@ public abstract class BaseEntity { @Column(name = "updated_at") private LocalDateTime updatedAt; + @Column(name = "deleted", insertable = false, updatable = false) + private boolean deleted; + } From b1ae9a20cb8b44d01baee31e1c1ca04243ee1ae5 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 28 Jul 2024 17:53:01 +0900 Subject: [PATCH 205/307] =?UTF-8?q?[refactor]=20FetchType=20EAGER=20->=20L?= =?UTF-8?q?AZY=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 --- .../bbteam/budgetbuddies/domain/category/entity/Category.java | 2 +- 1 file changed, 1 insertion(+), 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 b25530f3..0d0c761a 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 @@ -26,7 +26,7 @@ public class Category { @ColumnDefault("1") private Boolean isDefault; - @ManyToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; From cf02275da3c07cc81772c2f4df1a1e04be91b11f Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 28 Jul 2024 17:53:38 +0900 Subject: [PATCH 206/307] =?UTF-8?q?[refactor]=20FetchType=20EAGER=20->=20L?= =?UTF-8?q?AZY=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 오류 해결을 위해 @NotFound(action = NotFoundAction.IGNORE) 추가 --- .../domain/discountinfolike/entity/DiscountInfoLike.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/entity/DiscountInfoLike.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/entity/DiscountInfoLike.java index bb3fda22..387e700a 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/entity/DiscountInfoLike.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfolike/entity/DiscountInfoLike.java @@ -10,6 +10,8 @@ import jakarta.persistence.ManyToOne; import lombok.*; import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.NotFound; +import org.hibernate.annotations.NotFoundAction; @Entity @Getter @@ -18,11 +20,13 @@ @SuperBuilder public class DiscountInfoLike extends BaseEntity { - @ManyToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.LAZY) + @NotFound(action = NotFoundAction.IGNORE) @JoinColumn(name = "user_id") private User user; - @ManyToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.LAZY) + @NotFound(action = NotFoundAction.IGNORE) @JoinColumn(name = "discount_info_id") private DiscountInfo discountInfo; From ff521e90f9499ea5484ce7aa6185703bec60b813 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 28 Jul 2024 17:53:50 +0900 Subject: [PATCH 207/307] =?UTF-8?q?[refactor]=20FetchType=20EAGER=20->=20L?= =?UTF-8?q?AZY=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 오류 해결을 위해 @NotFound(action = NotFoundAction.IGNORE) 추가 --- .../domain/supportinfolike/entity/SupportInfoLike.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/entity/SupportInfoLike.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/entity/SupportInfoLike.java index 1be0154f..f3cacf21 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/entity/SupportInfoLike.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfolike/entity/SupportInfoLike.java @@ -12,6 +12,9 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.NotFound; +import org.hibernate.annotations.NotFoundAction; +import org.hibernate.annotations.Where; @Entity @Getter @@ -20,11 +23,13 @@ @SuperBuilder public class SupportInfoLike extends BaseEntity { - @ManyToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.LAZY) + @NotFound(action = NotFoundAction.IGNORE) @JoinColumn(name = "user_id") private User user; - @ManyToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.LAZY) + @NotFound(action = NotFoundAction.IGNORE) @JoinColumn(name = "support_info_id") private SupportInfo supportInfo; From f97f529ba4ba3082b9793047ad2184c320dbca64 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 28 Jul 2024 17:54:06 +0900 Subject: [PATCH 208/307] =?UTF-8?q?[refactor]=20FetchType=20EAGER=20->=20L?= =?UTF-8?q?AZY=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 --- .../bbteam/budgetbuddies/domain/expense/entity/Expense.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/entity/Expense.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/entity/Expense.java index 0d94c760..814aad79 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/entity/Expense.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/entity/Expense.java @@ -10,6 +10,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.Where; import java.time.LocalDateTime; @@ -28,11 +29,11 @@ public class Expense extends BaseEntity { private LocalDateTime expenseDate; - @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 1c9e260d25188592503a463a4f43241b06bee101 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 28 Jul 2024 17:54:43 +0900 Subject: [PATCH 209/307] =?UTF-8?q?[test]=20SoftDelete=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DiscountInfoRepositoryTest.java | 31 +++++++++++++++++ .../repository/SupportInfoRepositoryTest.java | 33 ++++++++++++++++++- 2 files changed, 63 insertions(+), 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 84cf5776..31826927 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 @@ -25,6 +25,37 @@ class DiscountInfoRepositoryTest { @Autowired private DiscountInfoRepository discountInfoRepository; + @Test + @DisplayName("@SoftDelete 테스트") + void deletedTest() { + // given + DiscountInfo discount1 = DiscountInfo.builder() + .title("할인정보1") + .startDate(LocalDate.of(2024, 7, 1)) + .endDate(LocalDate.of(2024, 7, 21)) + .discountRate(40) + .siteUrl("http://example1.com") + .build(); + + DiscountInfo discount2 = DiscountInfo.builder() + .title("할인정보2") + .startDate(LocalDate.of(2024, 7, 1)) + .endDate(LocalDate.of(2024, 7, 21)) + .discountRate(40) + .siteUrl("http://example1.com") + .build(); + + discountInfoRepository.save(discount1); + discountInfoRepository.save(discount2); + + // when + discountInfoRepository.deleteById(1L); + + // then + assertThat(discountInfoRepository.findAll()).hasSize(1); + assertThat(discountInfoRepository.findAll().get(0).getTitle()).isEqualTo("할인정보2"); + } + @Test @DisplayName("특정 년월에 속하는 할인 정보 데이터 조회 성공") void findByDateRangeSuccess() { 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 index 7d490ee8..adce1522 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepositoryTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepositoryTest.java @@ -1,7 +1,9 @@ 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.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -10,6 +12,7 @@ import java.time.LocalDate; import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; @SpringBootTest @@ -17,8 +20,36 @@ class SupportInfoRepositoryTest { @Autowired - SupportInfoRepository supportInfoRepository; + private SupportInfoRepository supportInfoRepository; + @Test + @DisplayName("@SoftDelete 테스트") + void deletedTest() { + // given + SupportInfo discount1 = SupportInfo.builder() + .title("지원정보1") + .startDate(LocalDate.of(2024, 7, 1)) + .endDate(LocalDate.of(2024, 7, 21)) + .siteUrl("http://example1.com") + .build(); + + SupportInfo discount2 = SupportInfo.builder() + .title("지원정보2") + .startDate(LocalDate.of(2024, 7, 1)) + .endDate(LocalDate.of(2024, 7, 21)) + .siteUrl("http://example1.com") + .build(); + + supportInfoRepository.save(discount1); + supportInfoRepository.save(discount2); + + // when + supportInfoRepository.deleteById(1L); + + // then + assertThat(supportInfoRepository.findAll()).hasSize(1); + assertThat(supportInfoRepository.findAll().get(0).getTitle()).isEqualTo("지원정보2"); + } @Test void findByMonthTest(){ From 8aed408937f4ec3a87ea29042ea88cd1442afc37 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 28 Jul 2024 19:39:04 +0900 Subject: [PATCH 210/307] =?UTF-8?q?[refactor]=20=ED=95=A0=EC=9D=B8=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20Swagger=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/DiscountInfoApi.java | 65 +++++++++++++++++++ .../controller/DiscountInfoController.java | 60 ++--------------- 2 files changed, 69 insertions(+), 56 deletions(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java new file mode 100644 index 00000000..f381f94f --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java @@ -0,0 +1,65 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.controller; + +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; +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 org.springframework.data.domain.Page; +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.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + +public interface DiscountInfoApi { + + @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개입니다.)") + }) + ResponseEntity> getDiscountsByYearAndMonth( + @RequestParam Integer year, + @RequestParam Integer month, + @RequestParam(defaultValue = "0") Integer page, + @RequestParam(defaultValue = "10") Integer size + ); + + @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))) + }) + public ResponseEntity registerDiscountInfo( + @RequestBody DiscountRequestDto discountRequestDto + ); + + @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 = "discountInfoId", description = "좋아요를 누를 할인정보의 id입니다."), + }) + public ResponseEntity likeDiscountInfo( + @RequestParam Long userId, + @PathVariable Long discountInfoId + ); + +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java index 711671e1..cd129809 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java @@ -1,42 +1,25 @@ package com.bbteam.budgetbuddies.domain.discountinfo.controller; -import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; import com.bbteam.budgetbuddies.domain.discountinfo.service.DiscountInfoService; 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.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; 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.*; -import java.util.List; - @RestController @RequiredArgsConstructor @RequestMapping("/discounts") -public class DiscountInfoController { +public class DiscountInfoController implements DiscountInfoApi { private final DiscountInfoService discountInfoService; - @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개입니다.)") - }) + @Override @GetMapping("") public ResponseEntity> getDiscountsByYearAndMonth( @RequestParam Integer year, @@ -49,13 +32,7 @@ public ResponseEntity> getDiscountsByYearAndMonth( return ResponseEntity.ok(discounts); } - @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))) - }) + @Override @PostMapping("") public ResponseEntity registerDiscountInfo( @RequestBody DiscountRequestDto discountRequestDto @@ -65,17 +42,7 @@ public ResponseEntity registerDiscountInfo( return ResponseEntity.ok(discountResponseDto); } - @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 = "discountInfoId", description = "좋아요를 누를 할인정보의 id입니다."), - }) + @Override @PostMapping("/{discountInfoId}/likes") public ResponseEntity likeDiscountInfo( @RequestParam Long userId, @@ -86,23 +53,4 @@ public ResponseEntity likeDiscountInfo( return ResponseEntity.ok(discountResponseDto); } -// @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 = "discountInfoId", description = "댓글을 작성할 할인정보의 id입니다."), -// }) -// @GetMapping("/{discountInfoId}/comments") -// public List getComments( -// @RequestParam Long userId, -// @PathVariable Long discountInfoId -// ) { -// return null; -// } - } From 5aa53c294b888d8d2c6b7b2dcceba3b03f0e52a3 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Sun, 28 Jul 2024 19:39:14 +0900 Subject: [PATCH 211/307] =?UTF-8?q?[refactor]=20=EC=A7=80=EC=9B=90=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20Swagger=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/SupportInfoApi.java | 63 +++++++++++++++++++ .../controller/SupportInfoController.java | 36 ++--------- 2 files changed, 67 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java new file mode 100644 index 00000000..94f0d16c --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java @@ -0,0 +1,63 @@ +package com.bbteam.budgetbuddies.domain.supportinfo.controller; + +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequestDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; +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 org.springframework.data.domain.Page; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + +public interface SupportInfoApi { + + @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개입니다.)") + }) + public ResponseEntity> getSupportsByYearAndMonth( + @RequestParam Integer year, + @RequestParam Integer month, + @RequestParam(defaultValue = "0") Integer page, + @RequestParam(defaultValue = "10") Integer size + ); + + @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))) + }) + public ResponseEntity registerDiscountInfo( + @RequestBody SupportRequestDto requestDto + ); + + @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입니다."), + }) + public ResponseEntity likeDiscountInfo( + @RequestParam Long userId, + @PathVariable Long supportInfoId + ); +} 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 index 059ae9b6..beba1301 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoController.java @@ -17,23 +17,11 @@ @RestController @RequiredArgsConstructor @RequestMapping("/supports") -public class SupportInfoController { +public class SupportInfoController implements SupportInfoApi { 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개입니다.)") - }) + @Override @GetMapping("") public ResponseEntity> getSupportsByYearAndMonth( @RequestParam Integer year, @@ -46,13 +34,7 @@ public ResponseEntity> getSupportsByYearAndMonth( 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))) - }) + @Override @PostMapping("") public ResponseEntity registerDiscountInfo( @RequestBody SupportRequestDto requestDto @@ -62,17 +44,7 @@ public ResponseEntity registerDiscountInfo( 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입니다."), - }) + @Override @PostMapping("/{supportInfoId}/likes") public ResponseEntity likeDiscountInfo( @RequestParam Long userId, From cf27045ed40960e969a1a64baef608a1b6d6be71 Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 29 Jul 2024 03:51:53 +0900 Subject: [PATCH 212/307] =?UTF-8?q?[fix]=20ConsumptionGoalResponseListDto?= =?UTF-8?q?=20=EC=B4=9D=EC=86=8C=EB=B9=84=EC=95=A1=20=EB=B0=8F=20=EC=B4=9D?= =?UTF-8?q?=EB=AA=A9=ED=91=9C=EC=95=A1=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/ConsumptionGoalResponseListDto.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 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 e7f5a54e..f09ffc90 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 @@ -4,17 +4,18 @@ import java.util.List; import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor +@Builder public class ConsumptionGoalResponseListDto { private LocalDate goalMonth; + private Long totalGoalAmount; + private Long totalConsumptionAmount; private List consumptionGoalList; - - public ConsumptionGoalResponseListDto(LocalDate goalMonth, List consumptionGoalList) { - this.goalMonth = goalMonth; - this.consumptionGoalList = consumptionGoalList; - } } From 82d1d29cdec6039bffde972d48ea1ac9d0ea9ece Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 29 Jul 2024 03:53:14 +0900 Subject: [PATCH 213/307] =?UTF-8?q?[fix]=20ConsumptionGoalConverter?= =?UTF-8?q?=EB=A5=BC=20=ED=86=B5=ED=95=B4=20toConsumptionGoalResponseListD?= =?UTF-8?q?to=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 | 23 ++++ .../service/ConsumptionGoalServiceImpl.java | 100 +++++++++--------- .../service/ConsumptionGoalServiceTest.java | 3 +- 3 files changed, 75 insertions(+), 51 deletions(-) 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 index a2c835cc..cff4f4d3 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionGoalConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionGoalConverter.java @@ -1,9 +1,13 @@ package com.bbteam.budgetbuddies.domain.consumptiongoal.converter; +import java.time.LocalDate; +import java.util.List; + 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.dto.ConsumptionGoalResponseListDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; @Component @@ -25,4 +29,23 @@ public ConsumptionGoalResponseDto toConsumptionGoalResponseDto(ConsumptionGoal c .consumeAmount(consumptionGoal.getConsumeAmount()) .build(); } + + public ConsumptionGoalResponseListDto toConsumptionGoalResponseListDto( + List consumptionGoalList, LocalDate goalMonth) { + return ConsumptionGoalResponseListDto.builder() + .goalMonth(goalMonth) + .totalGoalAmount(sumTotalGoalAmount(consumptionGoalList)) + .totalConsumptionAmount(sumTotalConsumptionAmount(consumptionGoalList)) + .consumptionGoalList(consumptionGoalList) + .build(); + + } + + private Long sumTotalConsumptionAmount(List consumptionGoalList) { + return consumptionGoalList.stream().reduce(0L, (sum, c2) -> sum + c2.getConsumeAmount(), Long::sum); + } + + private Long sumTotalGoalAmount(List consumptionGoalList) { + return consumptionGoalList.stream().reduce(0L, (sum, c2) -> sum + c2.getGoalAmount(), Long::sum); + } } 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 7ca9cc5e..4afa9f99 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 @@ -97,45 +97,6 @@ public ConsumptionAnalysisResponseDTO getTopCategoryAndConsumptionAmount(Long us return ConsumptionAnalysisConverter.fromEntity(topConsumptionGoal, totalConsumptionAmountForCurrentWeek); } - @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); - } - - @Override - @Transactional(readOnly = true) - 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 -> consumptionGoalConverter.toConsumptionGoalResponseDto(category))); - } - private User findUserById(Long userId) { Optional user = userRepository.findById(userId); @@ -179,21 +140,24 @@ private void setAgeGroupByUser(int userAge) { } } - private void updateGoalMapWithPreviousMonth(Long userId, LocalDate goalMonth, - Map goalMap) { - updateGoalMap(userId, goalMonth.minusMonths(1), goalMap); - } + @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")); - private void updateGoalMapWithCurrentMonth(Long userId, LocalDate goalMonth, - Map goalMap) { - updateGoalMap(userId, goalMonth, goalMap); - } + List updatedConsumptionGoal = consumptionGoalListRequestDto.getConsumptionGoalList() + .stream() + .map(c -> updateConsumptionGoalWithRequestDto(user, c, thisMonth)) + .toList(); - private void updateGoalMap(Long userId, LocalDate month, Map goalMap) { - consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(userId, month) + List response = consumptionGoalRepository.saveAll(updatedConsumptionGoal) .stream() .map(consumptionGoalConverter::toConsumptionGoalResponseDto) - .forEach(goal -> goalMap.put(goal.getCategoryId(), goal)); + .toList(); + + return consumptionGoalConverter.toConsumptionGoalResponseListDto(response, thisMonth); } private ConsumptionGoal updateConsumptionGoalWithRequestDto(User user, @@ -216,4 +180,40 @@ private ConsumptionGoal findOrElseGenerateConsumptionGoal(User user, Category ca private ConsumptionGoal generateConsumptionGoal(User user, Category category, LocalDate goalMonth) { return ConsumptionGoal.builder().goalMonth(goalMonth).user(user).category(category).consumeAmount(0L).build(); } + + @Override + @Transactional(readOnly = true) + 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 consumptionGoalConverter.toConsumptionGoalResponseListDto(new ArrayList<>(goalMap.values()), goalMonth); + } + + private Map initializeGoalMap(Long userId, LocalDate goalMonth) { + return categoryRepository.findUserCategoryByUserId(userId) + .stream() + .collect(Collectors.toMap(Category::getId, + category -> consumptionGoalConverter.toConsumptionGoalResponseDto(category))); + } + + private void updateGoalMapWithPreviousMonth(Long userId, LocalDate goalMonth, + Map goalMap) { + updateGoalMap(userId, goalMonth.minusMonths(1), goalMap); + } + + private void updateGoalMapWithCurrentMonth(Long userId, LocalDate goalMonth, + Map goalMap) { + updateGoalMap(userId, goalMonth, goalMap); + } + + private void updateGoalMap(Long userId, LocalDate month, Map goalMap) { + consumptionGoalRepository.findConsumptionGoalByUserIdAndGoalMonth(userId, month) + .stream() + .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 ca282360..f03aa713 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 @@ -64,7 +64,6 @@ void setUp() { user = Mockito.spy(User.builder().email("email").age(24).name("name").gender(Gender.MALE).phoneNumber("010-1234-5678").build()); given(user.getId()).willReturn(-1L); - given(userRepository.findById(user.getId())).willReturn(Optional.ofNullable(user)); } @Test @@ -185,6 +184,8 @@ void updateConsumptionGoal_Success() { Long defaultGoalAmount = 100L; Long userGoalAmount = 200L; + given(userRepository.findById(user.getId())).willReturn(Optional.ofNullable(user)); + ConsumptionGoalListRequestDto request = new ConsumptionGoalListRequestDto( List.of(new ConsumptionGoalRequestDto(-1L, defaultGoalAmount), new ConsumptionGoalRequestDto(-2L, userGoalAmount))); From 788e6b8f3a750141190fe542bb372c41d744f341 Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 29 Jul 2024 17:39:45 +0900 Subject: [PATCH 214/307] =?UTF-8?q?[feat]=20=EC=9B=94=EB=B3=84=20=EC=86=8C?= =?UTF-8?q?=EB=B9=84=20=EC=9D=91=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 --- .../dto/CompactExpenseResponseDto.java | 20 ++++++++++++++++++ .../dto/MonthlyExpenseCompactResponseDto.java | 21 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/CompactExpenseResponseDto.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/MonthlyExpenseCompactResponseDto.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/CompactExpenseResponseDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/CompactExpenseResponseDto.java new file mode 100644 index 00000000..e2f26ee7 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/CompactExpenseResponseDto.java @@ -0,0 +1,20 @@ +package com.bbteam.budgetbuddies.domain.expense.dto; + +import java.time.LocalDateTime; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor +@Builder +public class CompactExpenseResponseDto { + private Long expenseId; + private String description; + private Long amount; + private LocalDateTime expenseDate; +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/MonthlyExpenseCompactResponseDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/MonthlyExpenseCompactResponseDto.java new file mode 100644 index 00000000..bd7ce82e --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/MonthlyExpenseCompactResponseDto.java @@ -0,0 +1,21 @@ +package com.bbteam.budgetbuddies.domain.expense.dto; + +import java.time.LocalDate; +import java.util.List; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor +@Builder +public class MonthlyExpenseCompactResponseDto { + private LocalDate expenseMonth; + private int currentPage; + private boolean hasNext; + private List expenseList; +} From fa967b650bd27470c22428bbce1e335b3d762f7b Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 29 Jul 2024 17:42:36 +0900 Subject: [PATCH 215/307] =?UTF-8?q?[feat]=20ExpenseRepository=20Slice?= =?UTF-8?q?=EB=A5=BC=20=ED=86=B5=ED=95=B4=20=EC=9D=BC=EC=A0=95=20=EA=B8=B0?= =?UTF-8?q?=EA=B0=84=20=EC=86=8C=EB=B9=84=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 --- .../expense/repository/ExpenseRepository.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) 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 c846f92e..ab9721e0 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 @@ -1,18 +1,27 @@ package com.bbteam.budgetbuddies.domain.expense.repository; -import com.bbteam.budgetbuddies.domain.expense.entity.Expense; +import java.time.LocalDateTime; +import java.util.List; + +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; 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; +import com.bbteam.budgetbuddies.domain.expense.entity.Expense; +import com.bbteam.budgetbuddies.domain.user.entity.User; 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 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); - @Query("SELECT e FROM Expense e WHERE e.user.id = :userId") - List findByUserId(@Param("userId") Long userId); + @Query("SELECT e FROM Expense e WHERE e.user = :user AND e.expenseDate BETWEEN :startDate AND :endDate ORDER BY e.expenseDate DESC") + Slice findAllByUserIdForPeriod(Pageable pageable, @Param("user") User user, + @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate); } From 3905be18bf1382d2885230be415e198cdd735be1 Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 29 Jul 2024 17:42:42 +0900 Subject: [PATCH 216/307] =?UTF-8?q?[feat]=20ExpenseRepository=20Slice?= =?UTF-8?q?=EB=A5=BC=20=ED=86=B5=ED=95=B4=20=EC=9D=BC=EC=A0=95=20=EA=B8=B0?= =?UTF-8?q?=EA=B0=84=20=EC=86=8C=EB=B9=84=20=EC=A1=B0=ED=9A=8C=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=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 --- .../repository/ExpenseRepositoryTest.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/expense/repository/ExpenseRepositoryTest.java diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/expense/repository/ExpenseRepositoryTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/expense/repository/ExpenseRepositoryTest.java new file mode 100644 index 00000000..9c1b1156 --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/expense/repository/ExpenseRepositoryTest.java @@ -0,0 +1,92 @@ +package com.bbteam.budgetbuddies.domain.expense.repository; + +import static org.assertj.core.api.Assertions.*; + +import java.time.LocalDate; +import java.util.ArrayList; +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 org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; + +import com.bbteam.budgetbuddies.domain.category.entity.Category; +import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; +import com.bbteam.budgetbuddies.domain.expense.entity.Expense; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; + +@DisplayName("Expense 레포지토리 테스트의 ") +@DataJpaTest +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) +class ExpenseRepositoryTest { + @Autowired + private ExpenseRepository expenseRepository; + @Autowired + private UserRepository userRepository; + @Autowired + private CategoryRepository categoryRepository; + + @Test + @DisplayName("findAllByUserIdFOrPeriod 성공") + void findAllByUserIdForPeriod_Success() { + // given + User user = userRepository.save( + User.builder().email("email").age(24).name("name").phoneNumber("010-1234-5678").build()); + + Category userCategory = categoryRepository.save( + Category.builder().name("유저 카테고리").user(user).isDefault(false).build()); + + LocalDate startDate = LocalDate.of(2024, 07, 01); + LocalDate endDate = startDate.withDayOfMonth(startDate.lengthOfMonth()); + + List expected = setExpense(user, userCategory, startDate); + + Pageable pageable = PageRequest.of(0, 5); + + Slice result = expenseRepository.findAllByUserIdForPeriod(pageable, user, + startDate.atStartOfDay(), endDate.atStartOfDay()); + + assertThat(result.getContent()).usingRecursiveComparison().isEqualTo(expected); + } + + private List setExpense(User user, Category userCategory, LocalDate startDate) { + setUnexpectedExpense(user, userCategory, startDate); + + return setExpectedExpenseOrderByDateDesc(user, userCategory, startDate); + } + + private List setExpectedExpenseOrderByDateDesc(User user, Category userCategory, LocalDate startDate) { + List expenses = new ArrayList<>(); + + for (int i = startDate.lengthOfMonth(); i > startDate.lengthOfMonth() - 5; i--) { + Expense expense = Expense.builder() + .user(user) + .category(userCategory) + .amount(100000L * i) + .expenseDate(startDate.withDayOfMonth(i).atStartOfDay()) + .build(); + + expenses.add(expenseRepository.save(expense)); + } + return expenses; + } + + private void setUnexpectedExpense(User user, Category userCategory, LocalDate startDate) { + for (int i = 1; i <= 5; i++) { + Expense expense = Expense.builder() + .user(user) + .category(userCategory) + .amount(100000L * i) + .expenseDate(startDate.withMonth(8).atStartOfDay()) + .build(); + + expenseRepository.save(expense); + } + } +} \ No newline at end of file From 37af2fb45eb2dd6bf1db236096c06d1fd08b7577 Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 29 Jul 2024 17:43:10 +0900 Subject: [PATCH 217/307] =?UTF-8?q?[feat]=20=EC=9B=94=EB=B3=84=20=EC=86=8C?= =?UTF-8?q?=EB=B9=84=20=EC=A1=B0=ED=9A=8C=20Response=20Converter=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../expense/converter/ExpenseConverter.java | 72 +++++++++++++------ 1 file changed, 51 insertions(+), 21 deletions(-) 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 index ac88217c..57bb2a64 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/converter/ExpenseConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/converter/ExpenseConverter.java @@ -1,34 +1,64 @@ package com.bbteam.budgetbuddies.domain.expense.converter; +import java.time.LocalDate; +import java.util.List; + +import org.springframework.data.domain.Slice; +import org.springframework.stereotype.Component; + import com.bbteam.budgetbuddies.domain.category.entity.Category; +import com.bbteam.budgetbuddies.domain.expense.dto.CompactExpenseResponseDto; import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseRequestDto; import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; +import com.bbteam.budgetbuddies.domain.expense.dto.MonthlyExpenseCompactResponseDto; 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(); - } + 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(); + } + + public MonthlyExpenseCompactResponseDto toMonthlyExpenseCompactResponseDto(Slice expenseSlice, + LocalDate startOfMonth) { + List compactResponseList = expenseSlice.getContent().stream() + .map(this::toExpenseCompactResponseDto).toList(); + + return MonthlyExpenseCompactResponseDto + .builder() + .expenseMonth(startOfMonth) + .currentPage(expenseSlice.getPageable().getPageNumber()) + .hasNext(expenseSlice.hasNext()) + .expenseList(compactResponseList) + .build(); + } + + private CompactExpenseResponseDto toExpenseCompactResponseDto(Expense expense) { + return CompactExpenseResponseDto.builder() + .expenseId(expense.getId()) + .description(expense.getDescription()) + .amount(expense.getAmount()) + .expenseDate(expense.getExpenseDate()) + .build(); + } } From c796ec860f9cf43355660aff46f1e6d2a0d403e9 Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 29 Jul 2024 17:44:16 +0900 Subject: [PATCH 218/307] =?UTF-8?q?[feat]=20ExpenseService=20=EC=9B=94?= =?UTF-8?q?=EB=B3=84=20=EC=86=8C=EB=B9=84=20=EC=A1=B0=ED=9A=8C=20=EB=B9=84?= =?UTF-8?q?=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=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 --- .../expense/service/ExpenseService.java | 12 +++-- .../expense/service/ExpenseServiceImpl.java | 53 +++++++++++++------ 2 files changed, 46 insertions(+), 19 deletions(-) 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 cbcddb72..aa4007ca 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 @@ -1,11 +1,15 @@ package com.bbteam.budgetbuddies.domain.expense.service; +import java.time.LocalDate; + +import org.springframework.data.domain.Pageable; + 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; +import com.bbteam.budgetbuddies.domain.expense.dto.MonthlyExpenseCompactResponseDto; public interface ExpenseService { - ExpenseResponseDto createExpense(ExpenseRequestDto expenseRequestDto); + ExpenseResponseDto createExpense(ExpenseRequestDto expenseRequestDto); + + MonthlyExpenseCompactResponseDto getMonthlyExpense(Pageable pageable, Long userId, LocalDate localDate); } 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 index b4675ebe..37c1e178 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java @@ -1,36 +1,59 @@ package com.bbteam.budgetbuddies.domain.expense.service; +import java.time.LocalDate; + +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +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.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.dto.MonthlyExpenseCompactResponseDto; 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; + 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); + } + + @Override + @Transactional(readOnly = true) + public MonthlyExpenseCompactResponseDto getMonthlyExpense(Pageable pageable, Long userId, LocalDate localDate) { + LocalDate startOfMonth = localDate.withDayOfMonth(1); + LocalDate endOfMonth = localDate.withDayOfMonth(startOfMonth.lengthOfMonth()); - @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")); + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("Invalid user ID")); - Expense expense = expenseConverter.toExpenseEntity(expenseRequestDto, user, category); - expenseRepository.save(expense); + Slice expenseSlice = expenseRepository.findAllByUserIdForPeriod(pageable, user, + startOfMonth.atStartOfDay(), endOfMonth.atStartOfDay()); - return expenseConverter.toExpenseResponseDto(expense); - } + return expenseConverter.toMonthlyExpenseCompactResponseDto(expenseSlice, startOfMonth); + } } From fff1b4c39a0410b7351a92f1476baa06e2a69050 Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 29 Jul 2024 17:44:28 +0900 Subject: [PATCH 219/307] =?UTF-8?q?[feat]=20ExpenseService=20=EC=9B=94?= =?UTF-8?q?=EB=B3=84=20=EC=86=8C=EB=B9=84=20=EC=A1=B0=ED=9A=8C=20=EB=B9=84?= =?UTF-8?q?=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=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 --- .../service/ConsumptionGoalServiceTest.java | 34 +++-- .../service/ExpenseServiceImplTest.java | 118 ++++++++++++++++++ 2 files changed, 140 insertions(+), 12 deletions(-) create mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImplTest.java 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 f03aa713..23601804 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 @@ -62,7 +62,13 @@ void setUp() { int randomDay = random.nextInt(30) + 1; goalMonthRandomDay = LocalDate.of(GOAL_MONTH.getYear(), GOAL_MONTH.getMonth(), randomDay); - user = Mockito.spy(User.builder().email("email").age(24).name("name").gender(Gender.MALE).phoneNumber("010-1234-5678").build()); + user = Mockito.spy(User.builder() + .email("email") + .age(24) + .name("name") + .gender(Gender.MALE) + .phoneNumber("010-1234-5678") + .build()); given(user.getId()).willReturn(-1L); } @@ -300,11 +306,11 @@ void getTopCategoryAndConsumptionAmount_Success() { LocalDate endOfWeek = goalMonthRandomDay.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY)); given(userRepository.findById(user.getId())).willReturn(Optional.of(user)); - given(consumptionGoalRepository.findTopCategoriesAndGoalAmount(1, 23, 25, Gender.MALE)) - .willReturn(List.of(topConsumptionGoal)); - given(consumptionGoalRepository.findTopConsumptionByCategoryIdAndCurrentWeek( - defaultCategory.getId(), startOfWeek, endOfWeek)) - .willReturn(Optional.of(currentWeekConsumptionGoal)); + given(consumptionGoalRepository.findTopCategoriesAndGoalAmount(1, 23, 25, Gender.MALE)).willReturn( + List.of(topConsumptionGoal)); + given( + consumptionGoalRepository.findTopConsumptionByCategoryIdAndCurrentWeek(defaultCategory.getId(), startOfWeek, + endOfWeek)).willReturn(Optional.of(currentWeekConsumptionGoal)); // when ConsumptionAnalysisResponseDTO result = consumptionGoalService.getTopCategoryAndConsumptionAmount(user.getId()); @@ -319,9 +325,12 @@ void getTopCategoryAndConsumptionAmount_Success() { void getTopGoalCategories_Success() { // given Category defaultCategory = Mockito.spy(Category.builder().name("디폴트 카테고리").user(null).isDefault(true).build()); - Category defaultCategory2 = Mockito.spy(Category.builder().name("디폴트 카테고리2").user(null).isDefault(true).build()); - Category defaultCategory3 = Mockito.spy(Category.builder().name("디폴트 카테고리3").user(null).isDefault(true).build()); - Category defaultCategory4 = Mockito.spy(Category.builder().name("디폴트 카테고리4").user(null).isDefault(true).build()); + Category defaultCategory2 = Mockito.spy( + Category.builder().name("디폴트 카테고리2").user(null).isDefault(true).build()); + Category defaultCategory3 = Mockito.spy( + Category.builder().name("디폴트 카테고리3").user(null).isDefault(true).build()); + Category defaultCategory4 = Mockito.spy( + Category.builder().name("디폴트 카테고리4").user(null).isDefault(true).build()); ConsumptionGoal topConsumptionGoal1 = ConsumptionGoal.builder() .goalAmount(5000L) @@ -356,11 +365,12 @@ void getTopGoalCategories_Success() { .build(); given(userRepository.findById(user.getId())).willReturn(Optional.of(user)); - given(consumptionGoalRepository.findTopCategoriesAndGoalAmount(4, 23, 25, Gender.MALE)) - .willReturn(List.of(topConsumptionGoal1, topConsumptionGoal2, topConsumptionGoal3, topConsumptionGoal4)); + given(consumptionGoalRepository.findTopCategoriesAndGoalAmount(4, 23, 25, Gender.MALE)).willReturn( + List.of(topConsumptionGoal1, topConsumptionGoal2, topConsumptionGoal3, topConsumptionGoal4)); // when - List result = consumptionGoalService.getTopGoalCategories(4, user.getId(), 0, 0, "none"); + List result = consumptionGoalService.getTopGoalCategories(4, user.getId(), 0, 0, + "none"); // then assertThat(result).hasSize(4); diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImplTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImplTest.java new file mode 100644 index 00000000..82083dfa --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImplTest.java @@ -0,0 +1,118 @@ +package com.bbteam.budgetbuddies.domain.expense.service; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.BDDMockito.*; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +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.Spy; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.domain.SliceImpl; + +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.CompactExpenseResponseDto; +import com.bbteam.budgetbuddies.domain.expense.dto.MonthlyExpenseCompactResponseDto; +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; + +@ExtendWith(MockitoExtension.class) +@DisplayName("ExpenseService 테스트의 ") +class ExpenseServiceImplTest { + @InjectMocks + private ExpenseServiceImpl expenseService; + @Mock + private ExpenseRepository expenseRepository; + @Mock + private UserRepository userRepository; + @Mock + private CategoryRepository categoryRepository; + @Spy + private ExpenseConverter expenseConverter; + + @Test + @DisplayName("getMonthlyExpense : 성공") + void getMonthlyExpense_Success() { + // given + final int pageSize = 5; + + User user = Mockito.spy(User.builder().build()); + given(user.getId()).willReturn(-1L); + given(userRepository.findById(user.getId())).willReturn(Optional.of(user)); + + Category userCategory = Mockito.spy(Category.builder().build()); + + LocalDate requestMonth = LocalDate.of(2024, 07, 8); + Pageable requestPage = PageRequest.of(0, pageSize); + + List expenses = generateExpenseList(requestMonth, user, userCategory, pageSize); + + Slice expenseSlice = new SliceImpl<>(expenses, requestPage, false); + given(expenseRepository.findAllByUserIdForPeriod(any(Pageable.class), any(User.class), any(LocalDateTime.class), + any(LocalDateTime.class))).willReturn(expenseSlice); + + MonthlyExpenseCompactResponseDto expected = generateExpectation(requestMonth, pageSize); + + // when + MonthlyExpenseCompactResponseDto result = expenseService.getMonthlyExpense(requestPage, user.getId(), + requestMonth); + + // then + assertThat(result).usingRecursiveComparison().isEqualTo(expected); + } + + private List generateExpenseList(LocalDate month, User user, Category userCategory, int repeat) { + List expenses = new ArrayList<>(); + for (int i = repeat; i > 0; i--) { + Expense expense = Mockito.spy(Expense.builder() + .amount(i * 100000L) + .description("User 소비" + i) + .expenseDate(month.withDayOfMonth(i).atStartOfDay()) + .user(user) + .category(userCategory) + .build()); + given(expense.getId()).willReturn((long)-i); + + expenses.add(expense); + } + return expenses; + } + + private MonthlyExpenseCompactResponseDto generateExpectation(LocalDate month, int count) { + return MonthlyExpenseCompactResponseDto.builder() + .expenseMonth(month.withDayOfMonth(1)) + .hasNext(false) + .currentPage(0) + .expenseList(generateCompactExpenseResponseList(month, count)) + .build(); + } + + private List generateCompactExpenseResponseList(LocalDate month, int count) { + List compactExpenses = new ArrayList<>(); + for (int i = count; i > 0; i--) { + compactExpenses.add(CompactExpenseResponseDto.builder() + .description("User 소비" + i) + .expenseId((long)-i) + .expenseDate(month.withDayOfMonth(i).atStartOfDay()) + .amount(i * 100000L) + .build()); + } + return compactExpenses; + } +} \ No newline at end of file From 2ace002b29e35588b1b98aa223404718f3e23b77 Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 29 Jul 2024 17:45:47 +0900 Subject: [PATCH 220/307] =?UTF-8?q?[feat]=20ExpenseController=20=EC=9B=94?= =?UTF-8?q?=EB=B3=84=20=EC=86=8C=EB=B9=84=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../expense/controller/ExpenseController.java | 59 +++++++++++++------ 1 file changed, 41 insertions(+), 18 deletions(-) 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 index 159c6fc9..ed1c74f5 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java @@ -1,8 +1,24 @@ package com.bbteam.budgetbuddies.domain.expense.controller; +import java.time.LocalDate; + +import org.springframework.data.domain.Pageable; +import org.springframework.data.repository.query.Param; +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.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.expense.dto.ExpenseRequestDto; import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; +import com.bbteam.budgetbuddies.domain.expense.dto.MonthlyExpenseCompactResponseDto; 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; @@ -10,28 +26,35 @@ 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); - } + 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); + } + + @GetMapping("/{userId}") + public ResponseEntity findExpensesForMonth( + Pageable pageable, + @PathVariable @Param("userId") Long userId, + @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) { + + return ResponseEntity.ok(expenseService.getMonthlyExpense(pageable, userId, date)); + } } From 354cb336a3010a7812b36e4ace9806709c33ed1c Mon Sep 17 00:00:00 2001 From: JunRain Date: Mon, 29 Jul 2024 17:51:41 +0900 Subject: [PATCH 221/307] =?UTF-8?q?[feat]=20ExpenseController=20Swagger=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=BD=94=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 --- .../domain/expense/controller/ExpenseApi.java | 42 +++++++++++++++++++ .../expense/controller/ExpenseController.java | 23 +++------- 2 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java new file mode 100644 index 00000000..48fbdaac --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java @@ -0,0 +1,42 @@ +package com.bbteam.budgetbuddies.domain.expense.controller; + +import java.time.LocalDate; + +import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; + +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseRequestDto; +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; +import com.bbteam.budgetbuddies.domain.expense.dto.MonthlyExpenseCompactResponseDto; + +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; + +public interface ExpenseApi { + @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))), + @ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) + }) + ResponseEntity createExpense( + @Parameter(description = "user_id, category_id, amount, description, expenseDate") + ExpenseRequestDto expenseRequestDto); + + @Operation(summary = "월별 소비 조회", description = "무한 스크롤을 통한 조회로 예상하여 Slice를 통해서 조회") + @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))), + @ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) + }) + ResponseEntity findExpensesForMonth( + Pageable pageable, + Long userId, + LocalDate date); +} 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 index ed1c74f5..a28bfabc 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java @@ -19,39 +19,26 @@ import com.bbteam.budgetbuddies.domain.expense.dto.MonthlyExpenseCompactResponseDto; 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; @RestController @RequiredArgsConstructor @RequestMapping("/expenses") -public class ExpenseController { - +public class ExpenseController implements ExpenseApi { 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))) - }) + @Override @PostMapping("/add") public ResponseEntity createExpense( - @Parameter(description = "user_id, category_id, amount, description, expenseDate") - @RequestBody ExpenseRequestDto expenseRequestDto) { + @Parameter(description = "user_id, category_id, amount, description, expenseDate") @RequestBody ExpenseRequestDto expenseRequestDto) { ExpenseResponseDto response = expenseService.createExpense(expenseRequestDto); return ResponseEntity.ok(response); } + @Override @GetMapping("/{userId}") - public ResponseEntity findExpensesForMonth( - Pageable pageable, + public ResponseEntity findExpensesForMonth(Pageable pageable, @PathVariable @Param("userId") Long userId, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) { From 2412c318cf3c3692b0c1f0cdbb254de17009fef0 Mon Sep 17 00:00:00 2001 From: MJJ Date: Mon, 29 Jul 2024 22:28:06 +0900 Subject: [PATCH 222/307] =?UTF-8?q?[fix]=20=EA=B0=80=EC=9E=A5=20=ED=81=B0?= =?UTF-8?q?=20=EA=B3=84=ED=9A=8D=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC?= =?UTF-8?q?=EC=99=80=20=EC=9D=B4=EB=B2=88=20=EC=A3=BC=20=EC=86=8C=EB=B9=84?= =?UTF-8?q?=20=EA=B8=88=EC=95=A1=20=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=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/ConsumptionGoalServiceTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 23601804..2e09a47d 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 @@ -286,12 +286,14 @@ void getTopCategoryAndConsumptionAmount_Success() { Category defaultCategory = Mockito.spy(Category.builder().name("디폴트 카테고리").user(null).isDefault(true).build()); given(defaultCategory.getId()).willReturn(-1L); + LocalDate goalMonthRandomDay = LocalDate.now(); + ConsumptionGoal topConsumptionGoal = ConsumptionGoal.builder() .goalAmount(5000L) .consumeAmount(3000L) .user(user) .category(defaultCategory) - .goalMonth(goalMonthRandomDay) + .goalMonth(goalMonthRandomDay.minusWeeks(1)) .build(); ConsumptionGoal currentWeekConsumptionGoal = ConsumptionGoal.builder() From bbaa6d04b798220693ccd5a6689d6342d513078d Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Sat, 27 Jul 2024 19:08:03 +0900 Subject: [PATCH 223/307] =?UTF-8?q?[refactor]=20Repository,=20Service?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=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 | 3 ++ .../service/ConsumptionGoalService.java | 1 + .../service/ConsumptionGoalServiceImpl.java | 20 +++++++++++ .../expense/repository/ExpenseRepository.java | 10 +----- .../expense/service/ExpenseServiceImpl.java | 36 ++++++++++++++++--- src/main/resources/application.yaml | 17 +++++++++ 6 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 src/main/resources/application.yaml 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 a0df97bc..ee63bbd3 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,6 +44,9 @@ public class ConsumptionGoal extends BaseEntity { @JoinColumn(name = "category_id") private Category category; + public void updateConsumeAmount(Long amount) { + this.consumeAmount += amount; + } 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 cb4d297b..1114920e 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 @@ -25,4 +25,5 @@ ConsumptionGoalResponseListDto updateConsumptionGoals(Long userId, ConsumptionGoalListRequestDto consumptionGoalListRequestDto); ConsumptionAnalysisResponseDTO getTopCategoryAndConsumptionAmount(Long userId); + void updateConsumeAmount(Long userId, Long categoryId, Long amount); } \ 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 4afa9f99..a4031799 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 @@ -216,4 +216,24 @@ private void updateGoalMap(Long userId, LocalDate month, Map goalMap.put(goal.getCategoryId(), goal)); } + + @Override + public void updateConsumeAmount(Long userId, Long categoryId, Long amount) { + // User와 Category를 찾습니다. + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("Not found user")); + + Category category = categoryRepository.findById(categoryId) + .orElseThrow(() -> new IllegalArgumentException("Not found Category")); + + // ConsumptionGoal을 찾거나 생성합니다. + LocalDate thisMonth = LocalDate.now().withDayOfMonth(1); + ConsumptionGoal consumptionGoal = consumptionGoalRepository + .findConsumptionGoalByUserAndCategoryAndGoalMonth(user, category, thisMonth) + .orElseGet(() -> generateConsumptionGoal(user, category, thisMonth)); + + // 소비 금액을 업데이트합니다. + consumptionGoal.updateConsumeAmount(amount); + consumptionGoalRepository.save(consumptionGoal); + } } 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 ab9721e0..2bfef5a4 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 @@ -13,15 +13,7 @@ import com.bbteam.budgetbuddies.domain.user.entity.User; 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); - @Query("SELECT e FROM Expense e WHERE e.user = :user AND e.expenseDate BETWEEN :startDate AND :endDate ORDER BY e.expenseDate DESC") Slice findAllByUserIdForPeriod(Pageable pageable, @Param("user") User user, - @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate); + @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate); } 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 index 37c1e178..0bbb5071 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java @@ -9,6 +9,7 @@ import com.bbteam.budgetbuddies.domain.category.entity.Category; import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; +import com.bbteam.budgetbuddies.domain.consumptiongoal.service.ConsumptionGoalService; import com.bbteam.budgetbuddies.domain.expense.converter.ExpenseConverter; import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseRequestDto; import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; @@ -28,18 +29,45 @@ public class ExpenseServiceImpl implements ExpenseService { private final UserRepository userRepository; private final CategoryRepository categoryRepository; private final ExpenseConverter expenseConverter; + private final ConsumptionGoalService consumptionGoalService; @Override public ExpenseResponseDto createExpense(ExpenseRequestDto expenseRequestDto) { User user = userRepository.findById(expenseRequestDto.getUserId()) - .orElseThrow(() -> new IllegalArgumentException("Invalid user ID")); + .orElseThrow(() -> new IllegalArgumentException("Invalid user ID")); Category category = categoryRepository.findById(expenseRequestDto.getCategoryId()) - .orElseThrow(() -> new IllegalArgumentException("Invalid category ID")); + .orElseThrow(() -> new IllegalArgumentException("Invalid category ID")); + + /* + case 1) + - 카테고리 ID가 1~10 사이 && default => DB의 immutable 필드인 default category + - DB 관리 이슈로 category에 default 카테고리의 중복이 발생할 경우, 이를 대비하기 위해 1<= id <= 10 조건도 추가 + */ + if (expenseRequestDto.getCategoryId() >= 1 && expenseRequestDto.getCategoryId() <= 10 && category.getIsDefault()) { + // category.setUser(user); + // default category + } + /* + Case 2) + !default && 키테고리 테이블의 UserId 컬럼의 값이 나와 맞으면 (= custom cateogory) + */ + else if (!category.getIsDefault() && category.getUser().getId().equals(expenseRequestDto.getUserId())) { + // custom category + } + else { + throw new IllegalArgumentException("User and category are not matched properly."); + } Expense expense = expenseConverter.toExpenseEntity(expenseRequestDto, user, category); expenseRepository.save(expense); + consumptionGoalService.updateConsumeAmount(expenseRequestDto.getUserId(), expenseRequestDto.getCategoryId(), expenseRequestDto.getAmount()); + return expenseConverter.toExpenseResponseDto(expense); + /* + 결과 Case 1) 해당 유저의 user_id + immutable 필드 중 하나의 조합으로 Expense 테이블에 저장 + 결과 Case 2) 내가 직접 생성한 카테고리 중 하나로 카테고리를 설정하여 Expense 테이블에 저장 + */ } @Override @@ -49,10 +77,10 @@ public MonthlyExpenseCompactResponseDto getMonthlyExpense(Pageable pageable, Lon LocalDate endOfMonth = localDate.withDayOfMonth(startOfMonth.lengthOfMonth()); User user = userRepository.findById(userId) - .orElseThrow(() -> new IllegalArgumentException("Invalid user ID")); + .orElseThrow(() -> new IllegalArgumentException("Invalid user ID")); Slice expenseSlice = expenseRepository.findAllByUserIdForPeriod(pageable, user, - startOfMonth.atStartOfDay(), endOfMonth.atStartOfDay()); + startOfMonth.atStartOfDay(), endOfMonth.atStartOfDay()); return expenseConverter.toMonthlyExpenseCompactResponseDto(expenseSlice, startOfMonth); } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml new file mode 100644 index 00000000..cdd26de1 --- /dev/null +++ b/src/main/resources/application.yaml @@ -0,0 +1,17 @@ +spring: + application: + name: budgetbuddies + + jpa: + show-sql: true # sql ???? ??? ???? ??. + properties: + format_sql: true + dialect: org.hibernate.dialect.MySQL8Dialect + hibernate: + ddl-auto: update + + datasource: + url: jdbc:mysql://localhost:3306/budgetbuddies # mysql ?? ?? (?? ?? DB? ?? ? ??) + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: Asdsr11847783! # db ???? \ No newline at end of file From 4b0690ace70e28731add2bf5fb15e21bafee6470 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Sat, 27 Jul 2024 19:43:19 +0900 Subject: [PATCH 224/307] =?UTF-8?q?[refactor]=20=ED=95=B4=EB=8B=B9=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=EB=8A=94=20default=20+=20=EB=B3=B8=EC=9D=B8?= =?UTF-8?q?=EC=9D=B4=20=EC=84=A4=EC=A0=95=ED=95=9C=20custom=20category?= =?UTF-8?q?=EB=A7=8C=EC=9D=84=20=EC=A0=80=EC=9E=A5=ED=95=A0=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EB=8F=84=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../budgetbuddies/domain/category/entity/Category.java | 6 ++---- .../domain/expense/service/ExpenseServiceImpl.java | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) 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 0d0c761a..788bf807 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,14 +3,12 @@ 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 lombok.*; import org.hibernate.annotations.ColumnDefault; @Entity @Getter +@Setter @NoArgsConstructor @AllArgsConstructor @Builder 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 index 0bbb5071..bf289fc1 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java @@ -44,7 +44,7 @@ public ExpenseResponseDto createExpense(ExpenseRequestDto expenseRequestDto) { - DB 관리 이슈로 category에 default 카테고리의 중복이 발생할 경우, 이를 대비하기 위해 1<= id <= 10 조건도 추가 */ if (expenseRequestDto.getCategoryId() >= 1 && expenseRequestDto.getCategoryId() <= 10 && category.getIsDefault()) { - // category.setUser(user); + // category.setUser(user); // default category } /* @@ -61,6 +61,7 @@ else if (!category.getIsDefault() && category.getUser().getId().equals(expenseRe Expense expense = expenseConverter.toExpenseEntity(expenseRequestDto, user, category); expenseRepository.save(expense); + // 소비 목표 업데이트 consumptionGoalService.updateConsumeAmount(expenseRequestDto.getUserId(), expenseRequestDto.getCategoryId(), expenseRequestDto.getAmount()); return expenseConverter.toExpenseResponseDto(expense); @@ -85,3 +86,4 @@ public MonthlyExpenseCompactResponseDto getMonthlyExpense(Pageable pageable, Lon return expenseConverter.toMonthlyExpenseCompactResponseDto(expenseSlice, startOfMonth); } } + From 92b905922b1db114d0152638bedb8a1779b6dc61 Mon Sep 17 00:00:00 2001 From: JunRain Date: Tue, 30 Jul 2024 13:12:10 +0900 Subject: [PATCH 225/307] =?UTF-8?q?[fix]=20ExpenseResponseDto=EC=97=90=20c?= =?UTF-8?q?ategoryName=20=ED=95=84=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/domain/expense/converter/ExpenseConverter.java | 1 + .../budgetbuddies/domain/expense/dto/ExpenseResponseDto.java | 1 + 2 files changed, 2 insertions(+) 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 index 57bb2a64..23b1790e 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/converter/ExpenseConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/converter/ExpenseConverter.java @@ -32,6 +32,7 @@ public ExpenseResponseDto toExpenseResponseDto(Expense expense) { .expenseId(expense.getId()) .userId(expense.getUser().getId()) .categoryId(expense.getCategory().getId()) + .categoryName(expense.getCategory().getName()) .amount(expense.getAmount()) .description(expense.getDescription()) .expenseDate(expense.getExpenseDate()) 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 index 79b74cf6..4ae1a934 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseResponseDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseResponseDto.java @@ -15,6 +15,7 @@ public class ExpenseResponseDto { private Long expenseId; private Long userId; private Long categoryId; + private String categoryName; private Long amount; private String description; private LocalDateTime expenseDate; From f65d8299833cc919a130b8516993e4867e761761 Mon Sep 17 00:00:00 2001 From: JunRain Date: Tue, 30 Jul 2024 14:29:05 +0900 Subject: [PATCH 226/307] =?UTF-8?q?[feat]=20ExpenseService=20=EB=8B=A8?= =?UTF-8?q?=EC=9D=BC=20=EC=86=8C=EB=B9=84=20=EC=A1=B0=ED=9A=8C=20=EB=B0=8F?= =?UTF-8?q?=20user=EC=9D=B8=EC=A6=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../expense/service/ExpenseService.java | 2 + .../expense/service/ExpenseServiceImpl.java | 18 +++++- .../service/ExpenseServiceImplTest.java | 58 ++++++++++++++++++- 3 files changed, 74 insertions(+), 4 deletions(-) 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 aa4007ca..773e59bc 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 @@ -12,4 +12,6 @@ public interface ExpenseService { ExpenseResponseDto createExpense(ExpenseRequestDto expenseRequestDto); MonthlyExpenseCompactResponseDto getMonthlyExpense(Pageable pageable, Long userId, LocalDate localDate); + + ExpenseResponseDto findExpenseResponseFromUserIdAndExpenseId(Long userId, Long expenseId); } 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 index 37c1e178..44f6c514 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java @@ -48,12 +48,26 @@ public MonthlyExpenseCompactResponseDto getMonthlyExpense(Pageable pageable, Lon LocalDate startOfMonth = localDate.withDayOfMonth(1); LocalDate endOfMonth = localDate.withDayOfMonth(startOfMonth.lengthOfMonth()); - User user = userRepository.findById(userId) - .orElseThrow(() -> new IllegalArgumentException("Invalid user ID")); + User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("Invalid user ID")); Slice expenseSlice = expenseRepository.findAllByUserIdForPeriod(pageable, user, startOfMonth.atStartOfDay(), endOfMonth.atStartOfDay()); return expenseConverter.toMonthlyExpenseCompactResponseDto(expenseSlice, startOfMonth); } + + @Override + public ExpenseResponseDto findExpenseResponseFromUserIdAndExpenseId(Long userId, Long expenseId) { + Expense expense = expenseRepository.findById(expenseId) + .orElseThrow(() -> new IllegalArgumentException("Not found expense")); + + if (isAllowedUser(userId, expense)) + throw new IllegalArgumentException("Unauthorized user"); + + return expenseConverter.toExpenseResponseDto(expense); + } + + private boolean isAllowedUser(Long userId, Expense expense) { + return expense.getUser().getId() != userId; + } } diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImplTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImplTest.java index 82083dfa..11ecbf07 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImplTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImplTest.java @@ -1,6 +1,7 @@ package com.bbteam.budgetbuddies.domain.expense.service; import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.BDDMockito.*; import java.time.LocalDate; @@ -9,6 +10,7 @@ import java.util.List; import java.util.Optional; +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; @@ -26,6 +28,7 @@ import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; import com.bbteam.budgetbuddies.domain.expense.converter.ExpenseConverter; import com.bbteam.budgetbuddies.domain.expense.dto.CompactExpenseResponseDto; +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; import com.bbteam.budgetbuddies.domain.expense.dto.MonthlyExpenseCompactResponseDto; import com.bbteam.budgetbuddies.domain.expense.entity.Expense; import com.bbteam.budgetbuddies.domain.expense.repository.ExpenseRepository; @@ -46,14 +49,20 @@ class ExpenseServiceImplTest { @Spy private ExpenseConverter expenseConverter; + private User user; + + @BeforeEach + void setUp() { + user = Mockito.spy(User.builder().build()); + given(user.getId()).willReturn(-1L); + } + @Test @DisplayName("getMonthlyExpense : 성공") void getMonthlyExpense_Success() { // given final int pageSize = 5; - User user = Mockito.spy(User.builder().build()); - given(user.getId()).willReturn(-1L); given(userRepository.findById(user.getId())).willReturn(Optional.of(user)); Category userCategory = Mockito.spy(Category.builder().build()); @@ -115,4 +124,49 @@ private List generateCompactExpenseResponseList(Local } return compactExpenses; } + + @Test + @DisplayName("findExpenseFromUserIdAndExpenseId : 성공") + void findExpenseResponseFromUserIdAndExpenseId_Success() { + // given + final Long expenseId = -1L; + + Category userCategory = Mockito.spy(Category.builder().name("유저 카테고리").build()); + given(userCategory.getId()).willReturn(-1L); + + Expense expense = Mockito.spy(Expense.builder().user(user).category(userCategory).description("유저 소비").build()); + given(expense.getId()).willReturn(expenseId); + given(expenseRepository.findById(expense.getId())).willReturn(Optional.of(expense)); + + ExpenseResponseDto expected = ExpenseResponseDto.builder() + .userId(user.getId()) + .expenseId(-1L) + .description("유저 소비") + .categoryName("유저 카테고리") + .categoryId(-1L) + .build(); + + // when + ExpenseResponseDto result = expenseService.findExpenseResponseFromUserIdAndExpenseId(user.getId(), expenseId); + + // then + assertThat(result).usingRecursiveComparison().isEqualTo(expected); + } + + @Test + @DisplayName("findExpenseFromUserIdAndExpenseId : 소비 유저와 다른 유저로 인한 예외 반환") + void findExpenseResponseFromUserIdAndExpenseId_Fail() { + // given + final Long expenseId = -1L; + + Category userCategory = Mockito.spy(Category.builder().name("유저 카테고리").build()); + + Expense expense = Mockito.spy(Expense.builder().user(user).category(userCategory).description("유저 소비").build()); + given(expense.getId()).willReturn(expenseId); + given(expenseRepository.findById(expense.getId())).willReturn(Optional.of(expense)); + + // then + assertThrows(IllegalArgumentException.class, + () -> expenseService.findExpenseResponseFromUserIdAndExpenseId(-2L, expenseId)); + } } \ No newline at end of file From 9a1ee0efdcb824655fada368db7a4d01acf1c6c0 Mon Sep 17 00:00:00 2001 From: JunRain Date: Tue, 30 Jul 2024 14:29:21 +0900 Subject: [PATCH 227/307] =?UTF-8?q?[feat]=20ExpenseController=20=EB=8B=A8?= =?UTF-8?q?=EC=9D=BC=20=EC=86=8C=EB=B9=84=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 --- .../domain/expense/controller/ExpenseController.java | 7 +++++++ 1 file changed, 7 insertions(+) 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 index a28bfabc..3321950b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java @@ -44,4 +44,11 @@ public ResponseEntity findExpensesForMonth(Pag return ResponseEntity.ok(expenseService.getMonthlyExpense(pageable, userId, date)); } + + @Override + @GetMapping("/{userId}/{expenseId}") + public ResponseEntity findExpense(@PathVariable Long userId, @PathVariable Long expenseId) { + + return ResponseEntity.ok(expenseService.findExpenseResponseFromUserIdAndExpenseId(userId, expenseId)); + } } From 41e040ac4de24318302f06ff61e21f5a92323d35 Mon Sep 17 00:00:00 2001 From: JunRain Date: Tue, 30 Jul 2024 14:29:32 +0900 Subject: [PATCH 228/307] =?UTF-8?q?[feat]=20ExpenseController=20=EB=8B=A8?= =?UTF-8?q?=EC=9D=BC=20=EC=86=8C=EB=B9=84=20Swagger=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/expense/controller/ExpenseApi.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java index 48fbdaac..3db10871 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java @@ -3,7 +3,9 @@ import java.time.LocalDate; import org.springframework.data.domain.Pageable; +import org.springframework.data.repository.query.Param; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseRequestDto; import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; @@ -22,21 +24,25 @@ public interface ExpenseApi { @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))), @ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), - @ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) - }) + @ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class)))}) ResponseEntity createExpense( - @Parameter(description = "user_id, category_id, amount, description, expenseDate") - ExpenseRequestDto expenseRequestDto); + @Parameter(description = "user_id, category_id, amount, description, expenseDate") ExpenseRequestDto expenseRequestDto); @Operation(summary = "월별 소비 조회", description = "무한 스크롤을 통한 조회로 예상하여 Slice를 통해서 조회") @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))), @ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), - @ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) - }) - ResponseEntity findExpensesForMonth( - Pageable pageable, - Long userId, + @ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class)))}) + ResponseEntity findExpensesForMonth(Pageable pageable, Long userId, LocalDate date); + + @Operation(summary = "단일 소비 조회하기", description = "queryParameter를 통해 소비 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))), + @ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class)))}) + @GetMapping("/{userId}/{expenseId}") + ResponseEntity findExpense(@Param("userId") Long userId, @Param("expenseId") Long expenseId); } From 1f6e3073a1f8951351abfd85cc8a9b7421a78582 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Tue, 30 Jul 2024 15:58:34 +0900 Subject: [PATCH 229/307] =?UTF-8?q?[refactor]=20Controller=20=EC=9D=B8?= =?UTF-8?q?=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EB=B0=8F=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=EC=B2=B4=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/controller/CommentController.java | 109 +++++++----------- .../controller/CommentControllerApi.java | 80 +++++++++++++ 2 files changed, 123 insertions(+), 66 deletions(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.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 36500a8b..6fd4a094 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,83 +1,60 @@ package com.bbteam.budgetbuddies.domain.comment.controller; - import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; -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 com.bbteam.budgetbuddies.domain.comment.service.CommentService; +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.GetMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +public class CommentController implements CommentControllerApi { + + private final CommentService commentService; + + @PostMapping("/discounts/comments") + public ResponseEntity saveDiscountInfoComment( + @RequestParam("userId") Long userId, + @RequestBody CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto){ + CommentResponseDto.DiscountInfoSuccessDto dto = commentService.saveDiscountComment(userId, discountInfoCommentDto); + return ResponseEntity.ok(dto); + } + -public interface CommentController { - @Operation(summary = "[User] 특정 할인 정보 게시글에 댓글달기", description = "특정 할인 정보 게시글에 댓글을 다는 API입니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), - }) - @Parameters({ - @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), - @Parameter(name = "discountInfoId", description = "댓글을 다는 할인 정보 게시글 id입니다. requestBody"), - @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), - }) - ResponseEntity saveDiscountInfoComment( - Long userId, - CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto); + @GetMapping("/discounts/comments") + public ResponseEntity> findAllByDiscountInfo( + @RequestParam("discountInfoId") Long discountInfoId, + @PageableDefault(size = 20, page = 0) Pageable pageable){ + Page result = commentService.findByDiscountInfoWithPaging(discountInfoId, pageable); + return ResponseEntity.ok(result); + } - @Operation(summary = "[User] 특정 할인 정보 게시글의 댓글 조회하기", description = "특정 할인 정보 게시글의 댓글을 가져오는 API입니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), - }) - @Parameters({ - @Parameter(name = "discountInfoId", description = "댓글을 가져올 할인 정보 게시글 id입니다. parameter"), - @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), - @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") - }) - ResponseEntity> findAllByDiscountInfo( - Long discountInfoId, - Pageable pageable); + @PostMapping("/supports/comments") + 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 = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), - @Parameter(name = "supportInfoId", description = "댓글을 다는 지원 정보 게시글 id입니다. requestBody"), - @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), - }) - ResponseEntity saveSupportInfoComment( - Long userId, - CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto); - @Operation(summary = "[User] 특정 지원 정보 게시글의 댓글 조회하기", description = "특정 지원 정보 게시글의 댓글을 가져오는 API입니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), - }) - @Parameters({ - @Parameter(name = "supportInfoId", description = "댓글을 가져올 지원 정보 게시글 id입니다. parameter"), - @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), - @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") + @GetMapping("/supports/comments") + 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); + public ResponseEntity deleteComment(@RequestParam("commentId") Long commentId) { + commentService.deleteComment(commentId); + return ResponseEntity.ok("ok"); + } - @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") - ResponseEntity deleteComment(Long commentId); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java new file mode 100644 index 00000000..363412ad --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java @@ -0,0 +1,80 @@ +package com.bbteam.budgetbuddies.domain.comment.controller; + + +import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; +import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; +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 org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; + +public interface CommentControllerApi { + @Operation(summary = "[User] 특정 할인 정보 게시글에 댓글달기", description = "특정 할인 정보 게시글에 댓글을 다는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), + @Parameter(name = "discountInfoId", description = "댓글을 다는 할인 정보 게시글 id입니다. requestBody"), + @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), + }) + ResponseEntity saveDiscountInfoComment( + Long userId, + CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto); + + + @Operation(summary = "[User] 특정 할인 정보 게시글의 댓글 조회하기", description = "특정 할인 정보 게시글의 댓글을 가져오는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "discountInfoId", description = "댓글을 가져올 할인 정보 게시글 id입니다. parameter"), + @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), + @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") + }) + ResponseEntity> findAllByDiscountInfo( + Long discountInfoId, + Pageable pageable); + + @Operation(summary = "[User] 특정 지원 정보 게시글에 댓글달기", description = "특정 지원 정보 게시글에 댓글을 다는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), + @Parameter(name = "supportInfoId", description = "댓글을 다는 지원 정보 게시글 id입니다. requestBody"), + @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), + }) + ResponseEntity saveSupportInfoComment( + Long userId, + CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto); + + @Operation(summary = "[User] 특정 지원 정보 게시글의 댓글 조회하기", description = "특정 지원 정보 게시글의 댓글을 가져오는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "supportInfoId", description = "댓글을 가져올 지원 정보 게시글 id입니다. parameter"), + @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), + @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") + + + }) + ResponseEntity> findAllBySupportInfo( + Long supportInfoId, + Pageable pageable); + + @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") + ResponseEntity deleteComment(Long commentId); +} From 4fb98a00a0b7d2785b474c7365b9e5e25757b5f6 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Sat, 27 Jul 2024 19:48:35 +0900 Subject: [PATCH 230/307] =?UTF-8?q?[refactor]=20swagger=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EB=B6=80=EB=B6=84=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/expense/controller/ExpenseApi.java | 28 ++++++++----------- .../expense/controller/ExpenseController.java | 10 +++---- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java index 48fbdaac..d2dff327 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java @@ -1,42 +1,36 @@ package com.bbteam.budgetbuddies.domain.expense.controller; import java.time.LocalDate; - import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; - import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseRequestDto; import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; import com.bbteam.budgetbuddies.domain.expense.dto.MonthlyExpenseCompactResponseDto; - 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 org.springframework.web.bind.annotation.RequestBody; public interface ExpenseApi { @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))), - @ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), - @ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) + @ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + @ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) }) ResponseEntity createExpense( - @Parameter(description = "user_id, category_id, amount, description, expenseDate") - ExpenseRequestDto expenseRequestDto); + @Parameter(description = "user_id, category_id, amount, description, expenseDate") @RequestBody ExpenseRequestDto expenseRequestDto); @Operation(summary = "월별 소비 조회", description = "무한 스크롤을 통한 조회로 예상하여 Slice를 통해서 조회") @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))), - @ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), - @ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) + @ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + @ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))) }) - ResponseEntity findExpensesForMonth( - Pageable pageable, - Long userId, - LocalDate date); + ResponseEntity findExpensesForMonth(Pageable pageable, Long userId, LocalDate date); } 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 index a28bfabc..30552a4b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java @@ -2,6 +2,7 @@ import java.time.LocalDate; +import io.swagger.v3.oas.annotations.Parameter; import org.springframework.data.domain.Pageable; import org.springframework.data.repository.query.Param; import org.springframework.format.annotation.DateTimeFormat; @@ -13,13 +14,10 @@ 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.expense.dto.ExpenseRequestDto; import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; import com.bbteam.budgetbuddies.domain.expense.dto.MonthlyExpenseCompactResponseDto; import com.bbteam.budgetbuddies.domain.expense.service.ExpenseService; - -import io.swagger.v3.oas.annotations.Parameter; import lombok.RequiredArgsConstructor; @RestController @@ -31,7 +29,7 @@ public class ExpenseController implements ExpenseApi { @Override @PostMapping("/add") public ResponseEntity createExpense( - @Parameter(description = "user_id, category_id, amount, description, expenseDate") @RequestBody ExpenseRequestDto expenseRequestDto) { + @Parameter(description = "user_id, category_id, amount, description, expenseDate") @RequestBody ExpenseRequestDto expenseRequestDto) { ExpenseResponseDto response = expenseService.createExpense(expenseRequestDto); return ResponseEntity.ok(response); } @@ -39,8 +37,8 @@ public ResponseEntity createExpense( @Override @GetMapping("/{userId}") public ResponseEntity findExpensesForMonth(Pageable pageable, - @PathVariable @Param("userId") Long userId, - @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) { + @PathVariable @Param("userId") Long userId, + @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) { return ResponseEntity.ok(expenseService.getMonthlyExpense(pageable, userId, date)); } From 4045c260c51050884bcec1cb09d88c467f97c35a Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Tue, 30 Jul 2024 18:01:08 +0900 Subject: [PATCH 231/307] =?UTF-8?q?[refactor]=20=EC=A3=BC=EC=84=9D=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 --- .../consumptiongoal/service/ConsumptionGoalServiceImpl.java | 3 --- 1 file changed, 3 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 a4031799..58547008 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 @@ -219,20 +219,17 @@ private void updateGoalMap(Long userId, LocalDate month, Map new IllegalArgumentException("Not found user")); Category category = categoryRepository.findById(categoryId) .orElseThrow(() -> new IllegalArgumentException("Not found Category")); - // ConsumptionGoal을 찾거나 생성합니다. LocalDate thisMonth = LocalDate.now().withDayOfMonth(1); ConsumptionGoal consumptionGoal = consumptionGoalRepository .findConsumptionGoalByUserAndCategoryAndGoalMonth(user, category, thisMonth) .orElseGet(() -> generateConsumptionGoal(user, category, thisMonth)); - // 소비 금액을 업데이트합니다. consumptionGoal.updateConsumeAmount(amount); consumptionGoalRepository.save(consumptionGoal); } From ea6bcce8c474c8b5887a547557f3dbddfe0d1450 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Sat, 27 Jul 2024 19:48:35 +0900 Subject: [PATCH 232/307] =?UTF-8?q?[refactor]=20swagger=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EB=B6=80=EB=B6=84=20=EB=B6=84=EB=A6=AC?= 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 cdd26de1..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: update - - datasource: - url: jdbc:mysql://localhost:3306/budgetbuddies # mysql ?? ?? (?? ?? DB? ?? ? ??) - driver-class-name: com.mysql.cj.jdbc.Driver - username: root - password: Asdsr11847783! # db ???? \ No newline at end of file From 9277ed49d0d5cd38b355520ba5f528ed8d095d02 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Tue, 30 Jul 2024 20:38:32 +0900 Subject: [PATCH 233/307] =?UTF-8?q?[refactor]=20Comment=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=EC=8B=9C=20=EC=9E=91=EC=84=B1=20=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=EB=8F=84=20=EA=B0=99=EC=9D=B4=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../budgetbuddies/domain/comment/dto/CommentResponseDto.java | 5 +++++ 1 file changed, 5 insertions(+) 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 bfc27405..1e7bcb9e 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 @@ -4,6 +4,9 @@ import lombok.Builder; import lombok.Getter; +import java.time.LocalDate; +import java.time.LocalDateTime; + public class CommentResponseDto { @Getter @@ -14,6 +17,7 @@ public static class DiscountInfoCommentDto{ private Long discountInfoId; private String content; private Integer anonymousNumber; + private LocalDateTime createdAt; } @Getter @@ -24,6 +28,7 @@ public static class SupportInfoCommentDto{ private Long supportInfoId; private String content; private Integer anonymousNumber; + private LocalDateTime createdAt; } @Getter From 25ac8ee94e3079adf836c2895758b38383d27e5c Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Tue, 30 Jul 2024 20:38:54 +0900 Subject: [PATCH 234/307] =?UTF-8?q?[feat]=20CommentService=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20=EC=88=98=EC=A0=95=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 --- .../comment/service/CommentService.java | 6 ++- .../comment/service/CommentServiceImpl.java | 48 +++++++++++++++++-- 2 files changed, 49 insertions(+), 5 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 ac49bc5a..19aaa266 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 @@ -33,8 +33,12 @@ public interface CommentService { void deleteComment(Long commentId); + CommentResponseDto.DiscountInfoCommentDto findDiscountCommentOne(Long commentId); + CommentResponseDto.SupportInfoCommentDto findSupportCommentOne(Long commentId); - + //dirty checking 사용해서 변경 + CommentResponseDto.DiscountInfoCommentDto modifyDiscountComment(CommentRequestDto.DiscountInfoCommentDto dto); + CommentResponseDto.SupportInfoCommentDto modifySupportComment(CommentRequestDto.SupportInfoCommentDto dto); } 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 df8063fa..97ee1ea3 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 @@ -18,10 +18,7 @@ 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.Optional; +import java.util.*; import java.util.stream.Collectors; // 임시로 유저는 service에서 찾아서 처리하는 로직으로 작성함 @@ -137,4 +134,47 @@ public void deleteComment(Long commentId) { Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); commentRepository.delete(comment); } + + @Override + public CommentResponseDto.DiscountInfoCommentDto findDiscountCommentOne(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such comment")); + if(comment.getDiscountInfo() == null){ + throw new RuntimeException("discountInfo comment에 대한 요청이 아닙니다."); + } + return CommentConverter.toDiscountInfoCommentDto(comment); + + } + + @Override + public CommentResponseDto.SupportInfoCommentDto findSupportCommentOne(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such comment")); + if(comment.getSupportInfo() == null){ + throw new RuntimeException("supportInfo comment에 대한 요청이 아닙니다."); + } + return CommentConverter.toSupportInfoCommentDto(comment); + } + + @Override + @Transactional + public CommentResponseDto.DiscountInfoCommentDto modifyDiscountComment(CommentRequestDto.DiscountInfoCommentDto dto) { + Comment comment = commentRepository.findById(dto.getDiscountInfoId()).orElseThrow(() -> new NoSuchElementException("xxx")); + if(comment.getDiscountInfo() == null) { + throw new RuntimeException("discountInfo comment에 대한 요청이 아닙니다."); + } + comment.modifyComment(dto.getContent()); + + return CommentConverter.toDiscountInfoCommentDto(comment); + } + + @Override + @Transactional + public CommentResponseDto.SupportInfoCommentDto modifySupportComment(CommentRequestDto.SupportInfoCommentDto dto) { + Comment comment = commentRepository.findById(dto.getSupportInfoId()).orElseThrow(() -> new NoSuchElementException("xxx")); + if (comment.getSupportInfo() == null) { + throw new RuntimeException("supportInfo comment에 대한 요청이 아닙니다."); + } + comment.modifyComment(dto.getContent()); + + return CommentConverter.toSupportInfoCommentDto(comment); + } } From 1e95bf89190d362d568b5443a244b3d39db95bb4 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Tue, 30 Jul 2024 20:39:36 +0900 Subject: [PATCH 235/307] =?UTF-8?q?[refactor]=20CommentConverter=20Respons?= =?UTF-8?q?eDto=EC=97=90=20createadAt=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/comment/converter/CommentConverter.java | 2 ++ 1 file changed, 2 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 626a1e6f..6a5a9f8d 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 @@ -36,6 +36,7 @@ public static CommentResponseDto.DiscountInfoCommentDto toDiscountInfoCommentDto .userId(comment.getUser().getId()) .content(comment.getContent()) .anonymousNumber(comment.getAnonymousNumber()) + .createdAt(comment.getCreatedAt()) .build(); } @@ -47,6 +48,7 @@ public static CommentResponseDto.SupportInfoCommentDto toSupportInfoCommentDto(C .userId(comment.getUser().getId()) .content(comment.getContent()) .anonymousNumber(comment.getAnonymousNumber()) + .createdAt(comment.getCreatedAt()) .build(); } From 537fe49c323acf6d5f7bb78a36643425490b036a Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Tue, 30 Jul 2024 20:39:57 +0900 Subject: [PATCH 236/307] =?UTF-8?q?[feat]=20Comment=20content=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EC=9C=84=ED=95=9C=20=EB=A7=A4=EC=84=9C=EB=93=9C=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/comment/entity/Comment.java | 5 +++++ 1 file changed, 5 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 ce3ecccc..81827240 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 @@ -41,4 +41,9 @@ public class Comment extends BaseEntity { @Column(nullable = false) private Integer anonymousNumber; + public void modifyComment(String newComment) { + this.content = newComment; + return; + } + } From b45256fefc07d542f1e1125a6b45a28884761e72 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Tue, 30 Jul 2024 21:48:24 +0900 Subject: [PATCH 237/307] =?UTF-8?q?[feat]=20DiscountInfo=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=EC=97=90=20thumbnailUrl=20=ED=95=84=EB=93=9C?= =?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 --- .../domain/discountinfo/converter/DiscountInfoConverter.java | 2 ++ .../domain/discountinfo/dto/DiscountRequestDto.java | 2 ++ .../domain/discountinfo/dto/DiscountResponseDto.java | 2 ++ .../budgetbuddies/domain/discountinfo/entity/DiscountInfo.java | 3 +++ 4 files changed, 9 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java index 66793215..81e76f77 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java @@ -23,6 +23,7 @@ public DiscountResponseDto toDto(DiscountInfo entity) { .discountRate(entity.getDiscountRate()) .likeCount(entity.getLikeCount()) .siteUrl(entity.getSiteUrl()) + .thumbnailUrl(entity.getThumbnailUrl()) .build(); } @@ -41,6 +42,7 @@ public DiscountInfo toEntity(DiscountRequestDto requestDto) { .discountRate(requestDto.getDiscountRate()) .likeCount(0) .siteUrl(requestDto.getSiteUrl()) + .thumbnailUrl(requestDto.getThumbnailUrl()) .build(); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java index 894f6b3b..573a9715 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java @@ -20,4 +20,6 @@ public class DiscountRequestDto { private String siteUrl; + private String thumbnailUrl; + } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java index 3cd64ff4..3948f419 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java @@ -26,4 +26,6 @@ public class DiscountResponseDto { private String siteUrl; + private String thumbnailUrl; + } 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 2beb881a..4560c034 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 @@ -34,6 +34,9 @@ public class DiscountInfo extends BaseEntity { @Column(length = 1000) private String siteUrl; + @Column(length = 1000) + private String thumbnailUrl; // 카드 썸네일 이미지 + public void addLikeCount() { this.likeCount++; } From 0a86e4c2b81a68e96d1593a828e6ef3d4ba7d81d Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Tue, 30 Jul 2024 21:48:35 +0900 Subject: [PATCH 238/307] =?UTF-8?q?[feat]=20SupportInfo=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=EC=97=90=20thumbnailUrl=20=ED=95=84=EB=93=9C?= =?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 --- .../domain/supportinfo/converter/SupportInfoConverter.java | 2 ++ .../domain/supportinfo/dto/SupportRequestDto.java | 2 ++ .../domain/supportinfo/dto/SupportResponseDto.java | 2 ++ .../budgetbuddies/domain/supportinfo/entity/SupportInfo.java | 3 +++ 4 files changed, 9 insertions(+) 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 index 8e9bd62f..6bc8a7be 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/converter/SupportInfoConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/converter/SupportInfoConverter.java @@ -24,6 +24,7 @@ public SupportResponseDto toDto(SupportInfo entity) { .anonymousNumber(entity.getAnonymousNumber()) .likeCount(entity.getLikeCount()) .siteUrl(entity.getSiteUrl()) + .thumbnailUrl(entity.getThumbnailUrl()) .build(); } @@ -41,6 +42,7 @@ public SupportInfo toEntity(SupportRequestDto requestDto) { .anonymousNumber(0) .likeCount(0) .siteUrl(requestDto.getSiteUrl()) + .thumbnailUrl(requestDto.getThumbnailUrl()) .build(); } } 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 index ff883f7d..c008de0a 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequestDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequestDto.java @@ -21,4 +21,6 @@ public class SupportRequestDto { private String siteUrl; + private String thumbnailUrl; + } 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 index b04825f7..5392e54c 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportResponseDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportResponseDto.java @@ -27,4 +27,6 @@ public class SupportResponseDto { private String siteUrl; + private String thumbnailUrl; + } 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 f811f7ee..752341b7 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 @@ -32,6 +32,9 @@ public class SupportInfo extends BaseEntity { @Column(length = 1000) private String siteUrl; + @Column(length = 1000) + private String thumbnailUrl; // 카드 썸네일 이미지 + public void addLikeCount() { this.likeCount++; } From 6b444e035497c7a6ad1b5beb3fdfa182ba2f5ede Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Tue, 30 Jul 2024 21:12:02 +0900 Subject: [PATCH 239/307] =?UTF-8?q?[feat]=20custom=20=EC=B9=B4=ED=85=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC=20=EC=B6=94=EA=B0=80=20=EC=8B=9C=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99=EC=9C=BC=EB=A1=9C=20consumptionGoal=EC=97=90=20?= =?UTF-8?q?=ED=95=B4=EB=8B=B9=20=EB=A0=88=EC=BD=94=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80(consumeAmount=20=3D=200,=20goalAmount=20=3D=200)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../category/service/CategoryServiceImpl.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 2df03410..23f37b74 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 @@ -5,12 +5,15 @@ 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.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 lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; import java.util.List; import java.util.stream.Collectors; @@ -22,6 +25,7 @@ public class CategoryServiceImpl implements CategoryService { private final CategoryRepository categoryRepository; private final UserRepository userRepository; private final CategoryConverter categoryConverter; + private final ConsumptionGoalRepository consumptionGoalRepository; @Override public CategoryResponseDTO createCategory(CategoryRequestDTO categoryRequestDTO) { @@ -32,10 +36,20 @@ public CategoryResponseDTO createCategory(CategoryRequestDTO categoryRequestDTO) throw new IllegalArgumentException("User already has a category with the same name"); } - Category category = categoryConverter.toCategoryEntity(categoryRequestDTO, user); Category savedCategory = categoryRepository.save(category); + // custom 카테고리 생성 -> 소비 목표 테이블에 초기 값 추가 + ConsumptionGoal consumptionGoal = ConsumptionGoal.builder() + .user(user) + .category(savedCategory) + .goalMonth(LocalDate.now().withDayOfMonth(1)) // custom 카테고리를 생성한 현재 달(지금)로 설정 + .goalAmount(0L) + .consumeAmount(0L) + .build(); + + consumptionGoalRepository.save(consumptionGoal); + return categoryConverter.toCategoryResponseDTO(savedCategory); } From cd69d644238192d2f42418caa6613f5c38dc37fb Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Tue, 30 Jul 2024 22:05:49 +0900 Subject: [PATCH 240/307] =?UTF-8?q?[feat]=20default=20=EC=B9=B4=ED=85=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC=20=EC=B6=94=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/category/repository/CategoryRepository.java | 2 ++ 1 file changed, 2 insertions(+) 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 c6b571bb..fb64bd42 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 @@ -12,5 +12,7 @@ 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); + @Query("SELECT c FROM Category c WHERE c.isDefault = true") + List findAllByIsDefaultTrue(); boolean existsByUserIdAndName(Long userId, String name); } \ No newline at end of file From 642e03a194551a1d77a437849ade4f4ec678221a Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Tue, 30 Jul 2024 22:06:16 +0900 Subject: [PATCH 241/307] =?UTF-8?q?[feat]=20response=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/UserConsumptionGoalResponse.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/UserConsumptionGoalResponse.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/UserConsumptionGoalResponse.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/UserConsumptionGoalResponse.java new file mode 100644 index 00000000..71aa00e4 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/UserConsumptionGoalResponse.java @@ -0,0 +1,15 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.dto; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDate; + +@Getter +@Builder +public class UserConsumptionGoalResponse { + private Long categoryId; + private LocalDate goalMonth; + private Long consumeAmount; + private Long goalAmount; +} \ No newline at end of file From dc5b4a901adefbd6845408d5dd3aa112ddae028b Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Tue, 30 Jul 2024 22:06:46 +0900 Subject: [PATCH 242/307] =?UTF-8?q?[feat]=20converter=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/ConsumptionGoalConverter.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 index cff4f4d3..2def3e93 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionGoalConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/ConsumptionGoalConverter.java @@ -3,6 +3,7 @@ import java.time.LocalDate; import java.util.List; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.UserConsumptionGoalResponse; import org.springframework.stereotype.Component; import com.bbteam.budgetbuddies.domain.category.entity.Category; @@ -48,4 +49,13 @@ private Long sumTotalConsumptionAmount(List consumpt private Long sumTotalGoalAmount(List consumptionGoalList) { return consumptionGoalList.stream().reduce(0L, (sum, c2) -> sum + c2.getGoalAmount(), Long::sum); } + + public UserConsumptionGoalResponse toUserConsumptionGoalResponse(ConsumptionGoal consumptionGoal) { + return UserConsumptionGoalResponse.builder() + .categoryId(consumptionGoal.getCategory().getId()) + .goalMonth(consumptionGoal.getGoalMonth()) + .consumeAmount(consumptionGoal.getConsumeAmount()) + .goalAmount(consumptionGoal.getGoalAmount()) + .build(); + } } From 817c99df8439f9ffffb3c8f6714fea3ba93fed47 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Tue, 30 Jul 2024 22:07:10 +0900 Subject: [PATCH 243/307] =?UTF-8?q?[feat]=20service=20=EC=9D=B8=ED=84=B0?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EB=B0=8F=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=EC=B2=B4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/service/UserService.java | 8 +++ .../domain/user/service/UserServiceImpl.java | 51 +++++++++++++++++++ .../domain/user/service/package-info.java | 1 - 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserService.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserServiceImpl.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/service/package-info.java 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..c8da6a48 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserService.java @@ -0,0 +1,8 @@ +package com.bbteam.budgetbuddies.domain.user.service; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.UserConsumptionGoalResponse; + +import java.util.List; + +public interface UserService { + List createConsumptionGoalWithDefaultGoals(Long userId); +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserServiceImpl.java new file mode 100644 index 00000000..db6efe96 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserServiceImpl.java @@ -0,0 +1,51 @@ +package com.bbteam.budgetbuddies.domain.user.service; + +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.UserConsumptionGoalResponse; +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 lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class UserServiceImpl implements UserService { + + private final UserRepository userRepository; + private final CategoryRepository categoryRepository; + private final ConsumptionGoalRepository consumptionGoalRepository; + private final ConsumptionGoalConverter consumptionGoalConverter; + + @Override + @Transactional + public List createConsumptionGoalWithDefaultGoals(Long userId) { + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + + List defaultCategories = categoryRepository.findAllByIsDefaultTrue(); + List consumptionGoals = defaultCategories.stream() + .map(category -> ConsumptionGoal.builder() + .user(user) + .category(category) + .goalMonth(LocalDate.now().withDayOfMonth(1)) + .consumeAmount(0L) + .goalAmount(0L) + .build()) + .collect(Collectors.toList()); + + List savedConsumptionGoals = consumptionGoalRepository.saveAll(consumptionGoals); + + return savedConsumptionGoals.stream() + .map(consumptionGoalConverter::toUserConsumptionGoalResponse) + .collect(Collectors.toList()); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/service/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/service/package-info.java deleted file mode 100644 index ddb7edf6..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/user/service/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.user.service; \ No newline at end of file From 3814a91dc9a67a5fa1c56e1f81d00e6d7c937cd6 Mon Sep 17 00:00:00 2001 From: ryogaeng Date: Tue, 30 Jul 2024 22:07:20 +0900 Subject: [PATCH 244/307] =?UTF-8?q?[feat]=20controller=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 23 +++++++++++++++++++ .../domain/user/controller/package-info.java | 1 - 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/controller/UserController.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/controller/package-info.java 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..2f517ecc --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/user/controller/UserController.java @@ -0,0 +1,23 @@ +package com.bbteam.budgetbuddies.domain.user.controller; + +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.UserConsumptionGoalResponse; +import com.bbteam.budgetbuddies.domain.user.service.UserService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + + import java.util.List; + +@RestController +@RequestMapping("/users") +@RequiredArgsConstructor +public class UserController { + + private final UserService userService; + + @PostMapping("/{userId}/add/default-categories/consumption-goal") + public ResponseEntity> createConsumptionGoals(@PathVariable Long userId) { + List consumptionGoals = userService.createConsumptionGoalWithDefaultGoals(userId); + return ResponseEntity.ok(consumptionGoals); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/controller/package-info.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/controller/package-info.java deleted file mode 100644 index f734f3e8..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/user/controller/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.bbteam.budgetbuddies.domain.user.controller; \ No newline at end of file From 29d431de3b5fc2562c17ed639ddd0668839a1f6f Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Tue, 30 Jul 2024 22:12:06 +0900 Subject: [PATCH 245/307] =?UTF-8?q?[test]=20Generic=20Interface=EB=A5=BC?= =?UTF-8?q?=20=ED=86=B5=ED=95=9C=20Service=20=ED=86=B5=ED=95=A9=20?= =?UTF-8?q?=EC=8B=9C=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/DiscountCommentService.java | 98 +++ .../service/SupportCommentService.java | 100 +++ .../comment/service/CommentServiceTestV2.java | 569 ++++++++++++++++++ 3 files changed, 767 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java create mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java new file mode 100644 index 00000000..d1a16e0f --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java @@ -0,0 +1,98 @@ +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.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; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.stream.Collectors; + +@Service("discountCommentService") +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class DiscountCommentService implements CommentService{ + private final CommentRepository commentRepository; + private final UserRepository userRepository; + private final DiscountInfoRepository discountInfoRepository; + + @Override + @Transactional + public CommentResponseDto.DiscountInfoCommentDto saveComment(Long userId, CommentRequestDto.DiscountInfoCommentDto dto) { + User user = userRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("유저 존재 x")); + DiscountInfo info = discountInfoRepository.findById(dto.getDiscountInfoId()).orElseThrow(() -> new NoSuchElementException("정보 존재 x")); // dto에서 infoId를 추출하여 찾는 메서드 + int anonymousNumber = getAnonymousNumber(user, info); + Comment comment = CommentConverter.toDiscountComment(dto, user, info, anonymousNumber); + Comment savedComment = commentRepository.save(comment); + + return CommentConverter.toDiscountInfoCommentDto(savedComment); + } + + private int getAnonymousNumber(User user, DiscountInfo info) { + int anonymousNumber; + Optional foundComment = commentRepository.findTopByUserAndDiscountInfo(user, info); + if (foundComment.isEmpty()) { + anonymousNumber = info.addAndGetAnonymousNumber(); + } else { + anonymousNumber = foundComment.get().getAnonymousNumber(); + } + return anonymousNumber; + } + + @Override + public List findByInfo(Long infoId) { + List commentList = commentRepository.findByDiscountInfo(infoId); + List collect = commentList.stream() + .map(CommentConverter::toDiscountInfoCommentDto) + .collect(Collectors.toList()); + return collect; + } + + @Override + public Page findByInfoWithPaging(Long infoId, Pageable pageable) { + Page commentPage = commentRepository.findByDiscountInfoWithPaging(infoId, pageable); + Page result = commentPage.map(CommentConverter::toDiscountInfoCommentDto); + return result; + } + + @Override + @Transactional + public void deleteComment(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); + commentRepository.delete(comment); + } + + @Override + public CommentResponseDto.DiscountInfoCommentDto findCommentOne(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such comment")); + if(comment.getDiscountInfo() == null){ + throw new RuntimeException("DiscountInfo comment에 대한 요청이 아닙니다."); + } + return CommentConverter.toDiscountInfoCommentDto(comment); + } + + @Override + @Transactional + public CommentResponseDto.DiscountInfoCommentDto modifyComment(CommentRequestDto.DiscountInfoCommentDto dto) { + Comment comment = commentRepository.findById(dto.getDiscountInfoId()).orElseThrow(() -> new NoSuchElementException("xxx")); + if (comment.getDiscountInfo() == null) { + throw new RuntimeException("DiscountInfo comment에 대한 요청이 아닙니다."); + } + comment.modifyComment(dto.getContent()); + + return CommentConverter.toDiscountInfoCommentDto(comment); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java new file mode 100644 index 00000000..d6c4ec1a --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java @@ -0,0 +1,100 @@ +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.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.data.domain.Page; +import org.springframework.data.domain.Pageable; +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.Optional; +import java.util.stream.Collectors; + +@Service("supportCommentService") +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class SupportCommentService implements CommentService { + + private final CommentRepository commentRepository; + private final UserRepository userRepository; + private final SupportInfoRepository supportInfoRepository; + + @Override + @Transactional + public CommentResponseDto.SupportInfoCommentDto saveComment(Long userId, CommentRequestDto.SupportInfoCommentDto dto) { + User user = userRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("유저 존재 x")); + SupportInfo info = supportInfoRepository.findById(dto.getSupportInfoId()).orElseThrow(() -> new NoSuchElementException("정보 존재 x")); // dto에서 infoId를 추출하여 찾는 메서드 + int anonymousNumber = getAnonymousNumber(user, info); + Comment comment = CommentConverter.toSupportComment(dto, user, info, anonymousNumber); + Comment savedComment = commentRepository.save(comment); + + return CommentConverter.toSupportInfoCommentDto(savedComment); + } + + private int getAnonymousNumber(User user, SupportInfo info) { + int anonymousNumber; + Optional foundComment = commentRepository.findTopByUserAndSupportInfo(user, info); + if (foundComment.isEmpty()) { + anonymousNumber = info.addAndGetAnonymousNumber(); + } else { + anonymousNumber = foundComment.get().getAnonymousNumber(); + } + return anonymousNumber; + } + + @Override + public List findByInfo(Long infoId) { + List commentList = commentRepository.findBySupportInfo(infoId); + List collect = commentList.stream() + .map(CommentConverter::toSupportInfoCommentDto) + .collect(Collectors.toList()); + return collect; + } + + @Override + public Page findByInfoWithPaging(Long infoId, Pageable pageable) { + Page commentPage = commentRepository.findBySupportInfoWithPaging(infoId, pageable); + Page result = commentPage.map(CommentConverter::toSupportInfoCommentDto); + return result; + } + + @Override + @Transactional + public void deleteComment(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); + commentRepository.delete(comment); + } + + @Override + public CommentResponseDto.SupportInfoCommentDto findCommentOne(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such comment")); + if(comment.getSupportInfo() == null){ + throw new RuntimeException("supportInfo comment에 대한 요청이 아닙니다."); + } + return CommentConverter.toSupportInfoCommentDto(comment); + } + + @Override + @Transactional + public CommentResponseDto.SupportInfoCommentDto modifyComment(CommentRequestDto.SupportInfoCommentDto dto) { + Comment comment = commentRepository.findById(dto.getSupportInfoId()).orElseThrow(() -> new NoSuchElementException("xxx")); + if (comment.getSupportInfo() == null) { + throw new RuntimeException("supportInfo comment에 대한 요청이 아닙니다."); + } + comment.modifyComment(dto.getContent()); + + return CommentConverter.toSupportInfoCommentDto(comment); + } +} diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java b/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java new file mode 100644 index 00000000..aafa0422 --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java @@ -0,0 +1,569 @@ +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.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + + +/** + * comment service는 다음과 같은 기능을 제공해야한다. + * 1. comment 저장 기능 + * 2. 특정 게시글에 따른 comment return + * 현재 게시글의 종류는 2가지로 각각 할인정보, 지원정보이다. + * 즉, 할인정보, 지원정보 ID가 들어오면 해당 게시글에 대한 댓글 정보를 다 가지고 올 수 있어야한다. + * 아마 관리 측면에선 댓글 삭제 기능도 필요할 것이다. + * 3. 특정 userid로 댓글 찾는 기능 + * 얘는 게시글 ID랑 제목 정도 같이??? + * 4. 특정 게시글 id로 댓글 찾는 기능 + */ + + +/* + 테스트마다 테스트케이스가 다를 수 있어서 공통로직으로 처리하지 않아 매우 깁니다... + */ +@SpringBootTest +@Transactional +class CommentServiceTestV2 { + + @Qualifier("discountCommentService") + @Autowired + CommentService discountCommentService; + + @Qualifier("supportCommentService") + @Autowired + CommentService supportCommentService; + + @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("무신사 할인") + .anonymousNumber(0) + .build(); + discountInfoRepository.save(sale1); + + CommentRequestDto.DiscountInfoCommentDto dto1 = CommentRequestDto.DiscountInfoCommentDto.builder() + .discountInfoId(sale1.getId()) + .content("굿") + .build(); + + discountCommentService.saveComment(user1.getId(), dto1); + em.flush(); + + List returnDto = discountCommentService.findByInfo(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("무신사 할인") + .anonymousNumber(0) + .build(); + discountInfoRepository.save(sale1); + DiscountInfo sale2 = DiscountInfo.builder().title("핫트랙스 할인") + .anonymousNumber(0) + .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(); + + discountCommentService.saveComment(user1.getId(), dto1); + discountCommentService.saveComment(user2.getId(), dto2); + discountCommentService.saveComment(user1.getId(), dto3); + + em.flush(); + + List returnDto = discountCommentService.findByInfo(sale1.getId()); + List returnDto2 = discountCommentService.findByInfo(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().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(); + + discountCommentService.saveComment(user1.getId(), dto1); + discountCommentService.saveComment(user2.getId(), dto2); + discountCommentService.saveComment(user1.getId(), dto3); + + discountCommentService.saveComment(user1.getId(), dto4); + discountCommentService.saveComment(user3.getId(), dto4); + + em.flush(); + + List result = discountCommentService.findByInfo(sale1.getId()); + 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); + 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().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(); + + supportCommentService.saveComment(user1.getId(), dto1); + supportCommentService.saveComment(user2.getId(), dto2); + supportCommentService.saveComment(user1.getId(), dto3); + + em.flush(); + + List returnDto = supportCommentService.findByInfo(info1.getId()); + List returnDto2 = supportCommentService.findByInfo(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().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(); + + supportCommentService.saveComment(user1.getId(), dto1); + supportCommentService.saveComment(user2.getId(), dto2); + supportCommentService.saveComment(user1.getId(), dto3); + supportCommentService.saveComment(user3.getId(), dto4); + supportCommentService.saveComment(user4.getId(), dto5); + supportCommentService.saveComment(user1.getId(), dto6); + + em.flush(); + + List returnDto = supportCommentService.findByInfo(info1.getId()); + List returnDto2 = supportCommentService.findByInfo(info2.getId()); + + 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); + Assertions.assertThat(test3).isEqualTo(3); + Assertions.assertThat(test4).isEqualTo(4); + 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(); + + discountCommentService.saveComment(user1.getId(), dto1); + discountCommentService.saveComment(user2.getId(), dto2); + discountCommentService.saveComment(user1.getId(), dto3); + + discountCommentService.saveComment(user1.getId(), dto4); + discountCommentService.saveComment(user3.getId(), dto4); + discountCommentService.saveComment(user2.getId(), dto4); + //sale1 = 5 + em.flush(); + + PageRequest pageRequest1 = PageRequest.of(0, 2); + + Page result1 = discountCommentService.findByInfoWithPaging(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 = discountCommentService.findByInfoWithPaging(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(); + + supportCommentService.saveComment(user1.getId(), dto1); + supportCommentService.saveComment(user2.getId(), dto2); + supportCommentService.saveComment(user1.getId(), dto3); // 얘만 info2 + supportCommentService.saveComment(user3.getId(), dto4); + supportCommentService.saveComment(user4.getId(), dto5); + supportCommentService.saveComment(user1.getId(), dto6); + supportCommentService.saveComment(user2.getId(), dto5); + supportCommentService.saveComment(user3.getId(), dto5); + em.flush(); + + PageRequest pageRequest1 = PageRequest.of(0, 2); + Page result1 = supportCommentService.findByInfoWithPaging(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 = supportCommentService.findByInfoWithPaging(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 87551a52e8dc940727adb78099f53242d3ece06d Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Tue, 30 Jul 2024 22:12:54 +0900 Subject: [PATCH 246/307] =?UTF-8?q?[remove]=20=ED=86=B5=ED=95=A9=20?= =?UTF-8?q?=EC=8B=9C=EB=8F=84=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/DiscountCommentService.java | 98 --- .../service/SupportCommentService.java | 100 --- .../comment/service/CommentServiceTestV2.java | 569 ------------------ 3 files changed, 767 deletions(-) delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java delete mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java deleted file mode 100644 index d1a16e0f..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java +++ /dev/null @@ -1,98 +0,0 @@ -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.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; - -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Optional; -import java.util.stream.Collectors; - -@Service("discountCommentService") -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class DiscountCommentService implements CommentService{ - private final CommentRepository commentRepository; - private final UserRepository userRepository; - private final DiscountInfoRepository discountInfoRepository; - - @Override - @Transactional - public CommentResponseDto.DiscountInfoCommentDto saveComment(Long userId, CommentRequestDto.DiscountInfoCommentDto dto) { - User user = userRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("유저 존재 x")); - DiscountInfo info = discountInfoRepository.findById(dto.getDiscountInfoId()).orElseThrow(() -> new NoSuchElementException("정보 존재 x")); // dto에서 infoId를 추출하여 찾는 메서드 - int anonymousNumber = getAnonymousNumber(user, info); - Comment comment = CommentConverter.toDiscountComment(dto, user, info, anonymousNumber); - Comment savedComment = commentRepository.save(comment); - - return CommentConverter.toDiscountInfoCommentDto(savedComment); - } - - private int getAnonymousNumber(User user, DiscountInfo info) { - int anonymousNumber; - Optional foundComment = commentRepository.findTopByUserAndDiscountInfo(user, info); - if (foundComment.isEmpty()) { - anonymousNumber = info.addAndGetAnonymousNumber(); - } else { - anonymousNumber = foundComment.get().getAnonymousNumber(); - } - return anonymousNumber; - } - - @Override - public List findByInfo(Long infoId) { - List commentList = commentRepository.findByDiscountInfo(infoId); - List collect = commentList.stream() - .map(CommentConverter::toDiscountInfoCommentDto) - .collect(Collectors.toList()); - return collect; - } - - @Override - public Page findByInfoWithPaging(Long infoId, Pageable pageable) { - Page commentPage = commentRepository.findByDiscountInfoWithPaging(infoId, pageable); - Page result = commentPage.map(CommentConverter::toDiscountInfoCommentDto); - return result; - } - - @Override - @Transactional - public void deleteComment(Long commentId) { - Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); - commentRepository.delete(comment); - } - - @Override - public CommentResponseDto.DiscountInfoCommentDto findCommentOne(Long commentId) { - Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such comment")); - if(comment.getDiscountInfo() == null){ - throw new RuntimeException("DiscountInfo comment에 대한 요청이 아닙니다."); - } - return CommentConverter.toDiscountInfoCommentDto(comment); - } - - @Override - @Transactional - public CommentResponseDto.DiscountInfoCommentDto modifyComment(CommentRequestDto.DiscountInfoCommentDto dto) { - Comment comment = commentRepository.findById(dto.getDiscountInfoId()).orElseThrow(() -> new NoSuchElementException("xxx")); - if (comment.getDiscountInfo() == null) { - throw new RuntimeException("DiscountInfo comment에 대한 요청이 아닙니다."); - } - comment.modifyComment(dto.getContent()); - - return CommentConverter.toDiscountInfoCommentDto(comment); - } -} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java deleted file mode 100644 index d6c4ec1a..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java +++ /dev/null @@ -1,100 +0,0 @@ -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.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.data.domain.Page; -import org.springframework.data.domain.Pageable; -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.Optional; -import java.util.stream.Collectors; - -@Service("supportCommentService") -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class SupportCommentService implements CommentService { - - private final CommentRepository commentRepository; - private final UserRepository userRepository; - private final SupportInfoRepository supportInfoRepository; - - @Override - @Transactional - public CommentResponseDto.SupportInfoCommentDto saveComment(Long userId, CommentRequestDto.SupportInfoCommentDto dto) { - User user = userRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("유저 존재 x")); - SupportInfo info = supportInfoRepository.findById(dto.getSupportInfoId()).orElseThrow(() -> new NoSuchElementException("정보 존재 x")); // dto에서 infoId를 추출하여 찾는 메서드 - int anonymousNumber = getAnonymousNumber(user, info); - Comment comment = CommentConverter.toSupportComment(dto, user, info, anonymousNumber); - Comment savedComment = commentRepository.save(comment); - - return CommentConverter.toSupportInfoCommentDto(savedComment); - } - - private int getAnonymousNumber(User user, SupportInfo info) { - int anonymousNumber; - Optional foundComment = commentRepository.findTopByUserAndSupportInfo(user, info); - if (foundComment.isEmpty()) { - anonymousNumber = info.addAndGetAnonymousNumber(); - } else { - anonymousNumber = foundComment.get().getAnonymousNumber(); - } - return anonymousNumber; - } - - @Override - public List findByInfo(Long infoId) { - List commentList = commentRepository.findBySupportInfo(infoId); - List collect = commentList.stream() - .map(CommentConverter::toSupportInfoCommentDto) - .collect(Collectors.toList()); - return collect; - } - - @Override - public Page findByInfoWithPaging(Long infoId, Pageable pageable) { - Page commentPage = commentRepository.findBySupportInfoWithPaging(infoId, pageable); - Page result = commentPage.map(CommentConverter::toSupportInfoCommentDto); - return result; - } - - @Override - @Transactional - public void deleteComment(Long commentId) { - Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); - commentRepository.delete(comment); - } - - @Override - public CommentResponseDto.SupportInfoCommentDto findCommentOne(Long commentId) { - Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such comment")); - if(comment.getSupportInfo() == null){ - throw new RuntimeException("supportInfo comment에 대한 요청이 아닙니다."); - } - return CommentConverter.toSupportInfoCommentDto(comment); - } - - @Override - @Transactional - public CommentResponseDto.SupportInfoCommentDto modifyComment(CommentRequestDto.SupportInfoCommentDto dto) { - Comment comment = commentRepository.findById(dto.getSupportInfoId()).orElseThrow(() -> new NoSuchElementException("xxx")); - if (comment.getSupportInfo() == null) { - throw new RuntimeException("supportInfo comment에 대한 요청이 아닙니다."); - } - comment.modifyComment(dto.getContent()); - - return CommentConverter.toSupportInfoCommentDto(comment); - } -} diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java b/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java deleted file mode 100644 index aafa0422..00000000 --- a/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java +++ /dev/null @@ -1,569 +0,0 @@ -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.beans.factory.annotation.Qualifier; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - - -/** - * comment service는 다음과 같은 기능을 제공해야한다. - * 1. comment 저장 기능 - * 2. 특정 게시글에 따른 comment return - * 현재 게시글의 종류는 2가지로 각각 할인정보, 지원정보이다. - * 즉, 할인정보, 지원정보 ID가 들어오면 해당 게시글에 대한 댓글 정보를 다 가지고 올 수 있어야한다. - * 아마 관리 측면에선 댓글 삭제 기능도 필요할 것이다. - * 3. 특정 userid로 댓글 찾는 기능 - * 얘는 게시글 ID랑 제목 정도 같이??? - * 4. 특정 게시글 id로 댓글 찾는 기능 - */ - - -/* - 테스트마다 테스트케이스가 다를 수 있어서 공통로직으로 처리하지 않아 매우 깁니다... - */ -@SpringBootTest -@Transactional -class CommentServiceTestV2 { - - @Qualifier("discountCommentService") - @Autowired - CommentService discountCommentService; - - @Qualifier("supportCommentService") - @Autowired - CommentService supportCommentService; - - @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("무신사 할인") - .anonymousNumber(0) - .build(); - discountInfoRepository.save(sale1); - - CommentRequestDto.DiscountInfoCommentDto dto1 = CommentRequestDto.DiscountInfoCommentDto.builder() - .discountInfoId(sale1.getId()) - .content("굿") - .build(); - - discountCommentService.saveComment(user1.getId(), dto1); - em.flush(); - - List returnDto = discountCommentService.findByInfo(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("무신사 할인") - .anonymousNumber(0) - .build(); - discountInfoRepository.save(sale1); - DiscountInfo sale2 = DiscountInfo.builder().title("핫트랙스 할인") - .anonymousNumber(0) - .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(); - - discountCommentService.saveComment(user1.getId(), dto1); - discountCommentService.saveComment(user2.getId(), dto2); - discountCommentService.saveComment(user1.getId(), dto3); - - em.flush(); - - List returnDto = discountCommentService.findByInfo(sale1.getId()); - List returnDto2 = discountCommentService.findByInfo(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().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(); - - discountCommentService.saveComment(user1.getId(), dto1); - discountCommentService.saveComment(user2.getId(), dto2); - discountCommentService.saveComment(user1.getId(), dto3); - - discountCommentService.saveComment(user1.getId(), dto4); - discountCommentService.saveComment(user3.getId(), dto4); - - em.flush(); - - List result = discountCommentService.findByInfo(sale1.getId()); - 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); - 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().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(); - - supportCommentService.saveComment(user1.getId(), dto1); - supportCommentService.saveComment(user2.getId(), dto2); - supportCommentService.saveComment(user1.getId(), dto3); - - em.flush(); - - List returnDto = supportCommentService.findByInfo(info1.getId()); - List returnDto2 = supportCommentService.findByInfo(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().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(); - - supportCommentService.saveComment(user1.getId(), dto1); - supportCommentService.saveComment(user2.getId(), dto2); - supportCommentService.saveComment(user1.getId(), dto3); - supportCommentService.saveComment(user3.getId(), dto4); - supportCommentService.saveComment(user4.getId(), dto5); - supportCommentService.saveComment(user1.getId(), dto6); - - em.flush(); - - List returnDto = supportCommentService.findByInfo(info1.getId()); - List returnDto2 = supportCommentService.findByInfo(info2.getId()); - - 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); - Assertions.assertThat(test3).isEqualTo(3); - Assertions.assertThat(test4).isEqualTo(4); - 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(); - - discountCommentService.saveComment(user1.getId(), dto1); - discountCommentService.saveComment(user2.getId(), dto2); - discountCommentService.saveComment(user1.getId(), dto3); - - discountCommentService.saveComment(user1.getId(), dto4); - discountCommentService.saveComment(user3.getId(), dto4); - discountCommentService.saveComment(user2.getId(), dto4); - //sale1 = 5 - em.flush(); - - PageRequest pageRequest1 = PageRequest.of(0, 2); - - Page result1 = discountCommentService.findByInfoWithPaging(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 = discountCommentService.findByInfoWithPaging(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(); - - supportCommentService.saveComment(user1.getId(), dto1); - supportCommentService.saveComment(user2.getId(), dto2); - supportCommentService.saveComment(user1.getId(), dto3); // 얘만 info2 - supportCommentService.saveComment(user3.getId(), dto4); - supportCommentService.saveComment(user4.getId(), dto5); - supportCommentService.saveComment(user1.getId(), dto6); - supportCommentService.saveComment(user2.getId(), dto5); - supportCommentService.saveComment(user3.getId(), dto5); - em.flush(); - - PageRequest pageRequest1 = PageRequest.of(0, 2); - Page result1 = supportCommentService.findByInfoWithPaging(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 = supportCommentService.findByInfoWithPaging(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 fb18935c64775702b6179276d52903815783dc56 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Tue, 30 Jul 2024 22:49:05 +0900 Subject: [PATCH 247/307] =?UTF-8?q?[feat]=20DiscountInfo=20update=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=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 | 10 ++++++++++ 1 file 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 4560c034..3c1d0a5e 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 @@ -1,6 +1,7 @@ package com.bbteam.budgetbuddies.domain.discountinfo.entity; import com.bbteam.budgetbuddies.common.BaseEntity; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import jakarta.persistence.Column; import jakarta.persistence.Entity; import lombok.*; @@ -50,4 +51,13 @@ public Integer addAndGetAnonymousNumber() { return anonymousNumber; } + public void update(DiscountRequest.UpdateDto discountRequestDto) { + this.title = discountRequestDto.getTitle(); + this.startDate = discountRequestDto.getStartDate(); + this.endDate = discountRequestDto.getEndDate(); + this.discountRate = discountRequestDto.getDiscountRate(); + this.siteUrl = discountRequestDto.getSiteUrl(); + this.thumbnailUrl = discountRequestDto.getThumbnailUrl(); + } + } From 59f1d3ad768a0be4ca6ceb3f498ac9098214bdcb Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Wed, 31 Jul 2024 00:51:04 +0900 Subject: [PATCH 248/307] =?UTF-8?q?[feat]=20CommentService=20=EC=9E=AC?= =?UTF-8?q?=ED=86=B5=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/AbstractCommentService.java | 29 +++++ .../comment/service/CommentService.java | 43 ++++---- .../service/DiscountCommentService.java | 103 +++++++++++++++++ .../service/SupportCommentService.java | 104 ++++++++++++++++++ 4 files changed, 255 insertions(+), 24 deletions(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/AbstractCommentService.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/AbstractCommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/AbstractCommentService.java new file mode 100644 index 00000000..fa5f87f9 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/AbstractCommentService.java @@ -0,0 +1,29 @@ +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.entity.Comment; +import com.bbteam.budgetbuddies.domain.comment.repository.CommentRepository; + +import java.util.NoSuchElementException; +import java.util.Optional; + +public abstract class AbstractCommentService implements CommentService { + + protected final CommentRepository commentRepository; + + public AbstractCommentService(CommentRepository commentRepository) { + this.commentRepository = commentRepository; + } + + @Override + public void deleteComment(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); + commentRepository.delete(comment); + } + + @Override + public Optional findById(Long commentId) { + return commentRepository.findById(commentId); + } +} 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 19aaa266..29661e29 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 @@ -1,44 +1,39 @@ 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.discountinfo.entity.DiscountInfo; +import com.bbteam.budgetbuddies.domain.user.entity.User; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.stream.Collectors; -public interface CommentService { - CommentResponseDto.SupportInfoSuccessDto saveSupportComment(Long userId, CommentRequestDto.SupportInfoCommentDto dto); - CommentResponseDto.DiscountInfoSuccessDto saveDiscountComment(Long userId, CommentRequestDto.DiscountInfoCommentDto dto); +public interface CommentService { - /** - * - * @param discountInfoId - * @return List - * 해당 로직은 익명 구분을 위한 익명 구분 숫자도 같이 return 합니다. - */ - List findByDiscountInfo(Long discountInfoId); + T saveComment(Long userId, R dto); - /** - * - * @param supportInfoId - * @return List - * 해당 로직은 익명 구분을 위한 익명 구분 숫자도 같이 return 합니다. - */ - List findBySupportInfo(Long supportInfoId); - Page findByDiscountInfoWithPaging(Long discountInfoId, Pageable pageable); - Page findBySupportInfoWithPaging(Long supportInfoId, Pageable pageable); + List findByInfo(Long infoId); + + + Page findByInfoWithPaging(Long infoId, Pageable pageable); + void deleteComment(Long commentId); - CommentResponseDto.DiscountInfoCommentDto findDiscountCommentOne(Long commentId); - CommentResponseDto.SupportInfoCommentDto findSupportCommentOne(Long commentId); + T findCommentOne(Long commentId); + - //dirty checking 사용해서 변경 - CommentResponseDto.DiscountInfoCommentDto modifyDiscountComment(CommentRequestDto.DiscountInfoCommentDto dto); - CommentResponseDto.SupportInfoCommentDto modifySupportComment(CommentRequestDto.SupportInfoCommentDto dto); + T modifyComment(CommentRequestDto.CommentModifyDto dto); + Optional findById(Long commentId); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java new file mode 100644 index 00000000..b5a146a4 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java @@ -0,0 +1,103 @@ +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.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.stream.Collectors; + +@Service("discountCommentService") +@Transactional(readOnly = true) +public class DiscountCommentService extends AbstractCommentService { + private final UserRepository userRepository; + private final DiscountInfoRepository discountInfoRepository; + + public DiscountCommentService(CommentRepository commentRepository, UserRepository userRepository, DiscountInfoRepository discountInfoRepository) { + super(commentRepository); + this.userRepository = userRepository; + this.discountInfoRepository = discountInfoRepository; + } + + @Override + @Transactional + public CommentResponseDto.DiscountInfoCommentDto saveComment(Long userId, CommentRequestDto.DiscountInfoCommentDto dto) { + User user = userRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("유저 존재 x")); + DiscountInfo info = discountInfoRepository.findById(dto.getDiscountInfoId()).orElseThrow(() -> new NoSuchElementException("정보 존재 x")); // dto에서 infoId를 추출하여 찾는 메서드 + int anonymousNumber = getAnonymousNumber(user, info); + Comment comment = CommentConverter.toDiscountComment(dto, user, info, anonymousNumber); + Comment savedComment = commentRepository.save(comment); + + return CommentConverter.toDiscountInfoCommentDto(savedComment); + } + + + + private int getAnonymousNumber(User user, DiscountInfo info) { + int anonymousNumber; + Optional foundComment = commentRepository.findTopByUserAndDiscountInfo(user, info); + if (foundComment.isEmpty()) { + anonymousNumber = info.addAndGetAnonymousNumber(); + } else { + anonymousNumber = foundComment.get().getAnonymousNumber(); + } + return anonymousNumber; + } + + @Override + public List findByInfo(Long infoId) { + List commentList = commentRepository.findByDiscountInfo(infoId); + List collect = commentList.stream() + .map(CommentConverter::toDiscountInfoCommentDto) + .collect(Collectors.toList()); + return collect; + } + + @Override + public Page findByInfoWithPaging(Long infoId, Pageable pageable) { + Page commentPage = commentRepository.findByDiscountInfoWithPaging(infoId, pageable); + Page result = commentPage.map(CommentConverter::toDiscountInfoCommentDto); + return result; + } + + @Override + @Transactional + public void deleteComment(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); + commentRepository.delete(comment); + } + + @Override + public CommentResponseDto.DiscountInfoCommentDto findCommentOne(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such comment")); + if(comment.getDiscountInfo() == null){ + throw new RuntimeException("DiscountInfo comment에 대한 요청이 아닙니다."); + } + return CommentConverter.toDiscountInfoCommentDto(comment); + } + + @Override + @Transactional + public CommentResponseDto.DiscountInfoCommentDto modifyComment(CommentRequestDto.CommentModifyDto dto) { + Comment comment = commentRepository.findById(dto.getCommentId()).orElseThrow(() -> new NoSuchElementException("xxx")); + if (comment.getDiscountInfo() == null) { + throw new RuntimeException("DiscountInfo comment에 대한 요청이 아닙니다."); + } + comment.modifyComment(dto.getContent()); + + return CommentConverter.toDiscountInfoCommentDto(comment); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java new file mode 100644 index 00000000..123483d5 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java @@ -0,0 +1,104 @@ +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.comment.service.before.CommentService; +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.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.stream.Collectors; + +@Service("supportCommentService") +@Transactional(readOnly = true) +public class SupportCommentService extends AbstractCommentService { + + private final UserRepository userRepository; + private final SupportInfoRepository supportInfoRepository; + + public SupportCommentService(CommentRepository commentRepository, UserRepository userRepository, SupportInfoRepository supportInfoRepository) { + super(commentRepository); + this.userRepository = userRepository; + this.supportInfoRepository = supportInfoRepository; + } + + @Override + @Transactional + public CommentResponseDto.SupportInfoCommentDto saveComment(Long userId, CommentRequestDto.SupportInfoCommentDto dto) { + User user = userRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("유저 존재 x")); + SupportInfo info = supportInfoRepository.findById(dto.getSupportInfoId()).orElseThrow(() -> new NoSuchElementException("정보 존재 x")); // dto에서 infoId를 추출하여 찾는 메서드 + int anonymousNumber = getAnonymousNumber(user, info); + Comment comment = CommentConverter.toSupportComment(dto, user, info, anonymousNumber); + Comment savedComment = commentRepository.save(comment); + + return CommentConverter.toSupportInfoCommentDto(savedComment); + } + + private int getAnonymousNumber(User user, SupportInfo info) { + int anonymousNumber; + Optional foundComment = commentRepository.findTopByUserAndSupportInfo(user, info); + if (foundComment.isEmpty()) { + anonymousNumber = info.addAndGetAnonymousNumber(); + } else { + anonymousNumber = foundComment.get().getAnonymousNumber(); + } + return anonymousNumber; + } + + @Override + public List findByInfo(Long infoId) { + List commentList = commentRepository.findBySupportInfo(infoId); + List collect = commentList.stream() + .map(CommentConverter::toSupportInfoCommentDto) + .collect(Collectors.toList()); + return collect; + } + + @Override + public Page findByInfoWithPaging(Long infoId, Pageable pageable) { + Page commentPage = commentRepository.findBySupportInfoWithPaging(infoId, pageable); + Page result = commentPage.map(CommentConverter::toSupportInfoCommentDto); + return result; + } + + @Override + @Transactional + public void deleteComment(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); + commentRepository.delete(comment); + } + + @Override + public CommentResponseDto.SupportInfoCommentDto findCommentOne(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such comment")); + if(comment.getSupportInfo() == null){ + throw new RuntimeException("supportInfo comment에 대한 요청이 아닙니다."); + } + return CommentConverter.toSupportInfoCommentDto(comment); + } + + @Override + @Transactional + public CommentResponseDto.SupportInfoCommentDto modifyComment(CommentRequestDto.CommentModifyDto dto) { + Comment comment = commentRepository.findById(dto.getCommentId()).orElseThrow(() -> new NoSuchElementException("xxx")); + if (comment.getSupportInfo() == null) { + throw new RuntimeException("supportInfo comment에 대한 요청이 아닙니다."); + } + comment.modifyComment(dto.getContent()); + + return CommentConverter.toSupportInfoCommentDto(comment); + } +} From 00882731a9c87a0429a88f3376bd5453eac2fb07 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Wed, 31 Jul 2024 00:51:27 +0900 Subject: [PATCH 249/307] =?UTF-8?q?[test]=20CommentService=20=ED=86=B5?= =?UTF-8?q?=ED=95=A9=EC=97=90=20=EB=94=B0=EB=A5=B8=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 --- .../comment/service/CommentServiceTest.java | 31 +- .../comment/service/CommentServiceTestV2.java | 569 ++++++++++++++++++ 2 files changed, 599 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java 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 47636c82..9dfacb8c 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 @@ -2,6 +2,8 @@ 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.service.before.CommentService; import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; import com.bbteam.budgetbuddies.domain.discountinfo.repository.DiscountInfoRepository; import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; @@ -15,7 +17,6 @@ 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; @@ -558,6 +559,34 @@ void SupportInfoPagingTest() { Assertions.assertThat(list2.get(0).getAnonymousNumber()).isEqualTo(2); } + @Test + void discountInfoCommentModifyTest() { + User user1 = User.builder() + .name("tester1") + .email("1234") + .age(5) + .phoneNumber("123456") + .build(); + userRepository.save(user1); + DiscountInfo sale1 = DiscountInfo.builder().anonymousNumber(0).title("무신사 할인").build(); + discountInfoRepository.save(sale1); + + CommentRequestDto.DiscountInfoCommentDto dto1 = CommentRequestDto.DiscountInfoCommentDto.builder() + .discountInfoId(sale1.getId()) + .content("굿") + .build(); + commentService.saveDiscountComment(user1.getId(), dto1); + CommentResponseDto.DiscountInfoCommentDto test = commentService.findByDiscountInfo(sale1.getId()).get(0); + CommentRequestDto.CommentModifyDto content = CommentRequestDto.CommentModifyDto.builder() + .commentId(test.getCommentId()) + .content("잘했어요!") + .build(); + em.clear(); + commentService.modifyDiscountComment(content); + Comment byId = commentService.findById(1L); + Assertions.assertThat(byId.getContent()).isEqualTo("잘했어요!"); + } + } \ No newline at end of file diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java b/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java new file mode 100644 index 00000000..ff919466 --- /dev/null +++ b/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java @@ -0,0 +1,569 @@ +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.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + + +/** + * comment service는 다음과 같은 기능을 제공해야한다. + * 1. comment 저장 기능 + * 2. 특정 게시글에 따른 comment return + * 현재 게시글의 종류는 2가지로 각각 할인정보, 지원정보이다. + * 즉, 할인정보, 지원정보 ID가 들어오면 해당 게시글에 대한 댓글 정보를 다 가지고 올 수 있어야한다. + * 아마 관리 측면에선 댓글 삭제 기능도 필요할 것이다. + * 3. 특정 userid로 댓글 찾는 기능 + * 얘는 게시글 ID랑 제목 정도 같이??? + * 4. 특정 게시글 id로 댓글 찾는 기능 + */ + + +/* + 테스트마다 테스트케이스가 다를 수 있어서 공통로직으로 처리하지 않아 매우 깁니다... + */ +@SpringBootTest +@Transactional +class CommentServiceTestV2 { + + @Qualifier("discountCommentService") + @Autowired + CommentService discountCommentService; + + @Qualifier("supportCommentService") + @Autowired + com.bbteam.budgetbuddies.domain.comment.service.CommentService supportCommentService; + + @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("무신사 할인") + .anonymousNumber(0) + .build(); + discountInfoRepository.save(sale1); + + CommentRequestDto.DiscountInfoCommentDto dto1 = CommentRequestDto.DiscountInfoCommentDto.builder() + .discountInfoId(sale1.getId()) + .content("굿") + .build(); + + discountCommentService.saveComment(user1.getId(), dto1); + em.flush(); + + List returnDto = discountCommentService.findByInfo(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("무신사 할인") + .anonymousNumber(0) + .build(); + discountInfoRepository.save(sale1); + DiscountInfo sale2 = DiscountInfo.builder().title("핫트랙스 할인") + .anonymousNumber(0) + .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(); + + discountCommentService.saveComment(user1.getId(), dto1); + discountCommentService.saveComment(user2.getId(), dto2); + discountCommentService.saveComment(user1.getId(), dto3); + + em.flush(); + + List returnDto = discountCommentService.findByInfo(sale1.getId()); + List returnDto2 = discountCommentService.findByInfo(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().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(); + + discountCommentService.saveComment(user1.getId(), dto1); + discountCommentService.saveComment(user2.getId(), dto2); + discountCommentService.saveComment(user1.getId(), dto3); + + discountCommentService.saveComment(user1.getId(), dto4); + discountCommentService.saveComment(user3.getId(), dto4); + + em.flush(); + + List result = discountCommentService.findByInfo(sale1.getId()); + 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); + 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().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(); + + supportCommentService.saveComment(user1.getId(), dto1); + supportCommentService.saveComment(user2.getId(), dto2); + supportCommentService.saveComment(user1.getId(), dto3); + + em.flush(); + + List returnDto = supportCommentService.findByInfo(info1.getId()); + List returnDto2 = supportCommentService.findByInfo(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().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(); + + supportCommentService.saveComment(user1.getId(), dto1); + supportCommentService.saveComment(user2.getId(), dto2); + supportCommentService.saveComment(user1.getId(), dto3); + supportCommentService.saveComment(user3.getId(), dto4); + supportCommentService.saveComment(user4.getId(), dto5); + supportCommentService.saveComment(user1.getId(), dto6); + + em.flush(); + + List returnDto = supportCommentService.findByInfo(info1.getId()); + List returnDto2 = supportCommentService.findByInfo(info2.getId()); + + 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); + Assertions.assertThat(test3).isEqualTo(3); + Assertions.assertThat(test4).isEqualTo(4); + 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(); + + discountCommentService.saveComment(user1.getId(), dto1); + discountCommentService.saveComment(user2.getId(), dto2); + discountCommentService.saveComment(user1.getId(), dto3); + + discountCommentService.saveComment(user1.getId(), dto4); + discountCommentService.saveComment(user3.getId(), dto4); + discountCommentService.saveComment(user2.getId(), dto4); + //sale1 = 5 + em.flush(); + + PageRequest pageRequest1 = PageRequest.of(0, 2); + + Page result1 = discountCommentService.findByInfoWithPaging(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 = discountCommentService.findByInfoWithPaging(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(); + + supportCommentService.saveComment(user1.getId(), dto1); + supportCommentService.saveComment(user2.getId(), dto2); + supportCommentService.saveComment(user1.getId(), dto3); // 얘만 info2 + supportCommentService.saveComment(user3.getId(), dto4); + supportCommentService.saveComment(user4.getId(), dto5); + supportCommentService.saveComment(user1.getId(), dto6); + supportCommentService.saveComment(user2.getId(), dto5); + supportCommentService.saveComment(user3.getId(), dto5); + em.flush(); + + PageRequest pageRequest1 = PageRequest.of(0, 2); + Page result1 = supportCommentService.findByInfoWithPaging(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 = supportCommentService.findByInfoWithPaging(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 3eb685ccf19a7a567725bb4105fd54d5e9a77e25 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Wed, 31 Jul 2024 00:55:50 +0900 Subject: [PATCH 250/307] =?UTF-8?q?[refactor]=20Controller=20=EC=9D=B4?= =?UTF-8?q?=EA=B4=80=EC=97=90=20=EB=94=B0=EB=A5=B8=20annotation=20?= =?UTF-8?q?=EB=B9=84=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/controller/CommentController.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 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 6fd4a094..7ebab75e 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 @@ -2,7 +2,7 @@ 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 com.bbteam.budgetbuddies.domain.comment.service.before.CommentService; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -10,17 +10,17 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -@RestController +//@RestController @RequiredArgsConstructor public class CommentController implements CommentControllerApi { private final CommentService commentService; @PostMapping("/discounts/comments") - public ResponseEntity saveDiscountInfoComment( + public ResponseEntity saveDiscountInfoComment( @RequestParam("userId") Long userId, @RequestBody CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto){ - CommentResponseDto.DiscountInfoSuccessDto dto = commentService.saveDiscountComment(userId, discountInfoCommentDto); + CommentResponseDto.DiscountInfoCommentDto dto = commentService.saveDiscountComment(userId, discountInfoCommentDto); return ResponseEntity.ok(dto); } @@ -35,10 +35,10 @@ public ResponseEntity> findAllBy @PostMapping("/supports/comments") - public ResponseEntity saveSupportInfoComment( + public ResponseEntity saveSupportInfoComment( @RequestParam("userId") Long userId, @RequestBody CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto){ - CommentResponseDto.SupportInfoSuccessDto dto = commentService.saveSupportComment(userId, supportInfoCommentDto); + CommentResponseDto.SupportInfoCommentDto dto = commentService.saveSupportComment(userId, supportInfoCommentDto); return ResponseEntity.ok(dto); } @@ -51,10 +51,12 @@ public ResponseEntity> findAllByS return ResponseEntity.ok(result); } - + @PostMapping("/comments/delete") public ResponseEntity deleteComment(@RequestParam("commentId") Long commentId) { commentService.deleteComment(commentId); return ResponseEntity.ok("ok"); } + + } From e4d9b6db2f1084fa6e17bd5478676ee59bdc4171 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Wed, 31 Jul 2024 00:56:35 +0900 Subject: [PATCH 251/307] =?UTF-8?q?[refactor]=20CommentControllerApi=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=20API=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/comment/controller/CommentControllerApi.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java index 363412ad..730f6b6e 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java @@ -22,7 +22,7 @@ public interface CommentControllerApi { @Parameter(name = "discountInfoId", description = "댓글을 다는 할인 정보 게시글 id입니다. requestBody"), @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), }) - ResponseEntity saveDiscountInfoComment( + ResponseEntity saveDiscountInfoComment( Long userId, CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto); @@ -49,7 +49,7 @@ ResponseEntity> findAllByDiscoun @Parameter(name = "supportInfoId", description = "댓글을 다는 지원 정보 게시글 id입니다. requestBody"), @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), }) - ResponseEntity saveSupportInfoComment( + ResponseEntity saveSupportInfoComment( Long userId, CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto); From fcdb71090f63ec4014e53de170626d174162bd4c Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Wed, 31 Jul 2024 00:57:05 +0900 Subject: [PATCH 252/307] =?UTF-8?q?[remove]=20SuccessDto=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/converter/CommentConverter.java | 17 ----------------- .../domain/comment/dto/CommentResponseDto.java | 16 ---------------- 2 files changed, 33 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 6a5a9f8d..8e424e50 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 @@ -53,22 +53,5 @@ 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()) - .build(); - } - - 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()) - .build(); - } } 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 1e7bcb9e..932cad45 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 @@ -31,22 +31,6 @@ public static class SupportInfoCommentDto{ private LocalDateTime createdAt; } - @Getter - @Builder - public static class DiscountInfoSuccessDto{ - private Long commentId; - private Long userId; - private Long discountInfoId; - private String content; - } - @Getter - @Builder - public static class SupportInfoSuccessDto{ - private Long commentId; - private Long userId; - private Long supportInfoId; - private String content; - } } From 5aa7531f971744beac504e8e78818f585e9f6006 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Wed, 31 Jul 2024 00:57:33 +0900 Subject: [PATCH 253/307] =?UTF-8?q?[feat]=20CommentModifyDto=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EC=97=90=20=EC=82=AC=EC=9A=A9=ED=95=A0=20Dto=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 --- .../domain/comment/dto/CommentRequestDto.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 45b91e8e..9b516614 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 @@ -2,7 +2,6 @@ import lombok.Builder; import lombok.Getter; -import lombok.Setter; public class CommentRequestDto { @@ -19,4 +18,11 @@ public static class SupportInfoCommentDto { private String content; private Long supportInfoId; } + + @Getter + @Builder + public static class CommentModifyDto { + private String content; + private Long commentId; + } } From d58fcb41e7047f756cbe182b2b3a7b4e842f5318 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Wed, 31 Jul 2024 00:59:37 +0900 Subject: [PATCH 254/307] =?UTF-8?q?[remove]=20=EA=B5=AC=20CommentService?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/service/CommentServiceImpl.java | 180 ------ .../comment/service/CommentServiceTest.java | 592 ------------------ 2 files changed, 772 deletions(-) delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java delete 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/CommentServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java deleted file mode 100644 index 97ee1ea3..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java +++ /dev/null @@ -1,180 +0,0 @@ -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.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.*; -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()); - 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 - @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()); - 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); - - HashMap anonymousMapping = countAnonymousNumber(commentList); - List collect = commentList.stream() - .map(CommentConverter::toDiscountInfoCommentDto) - .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(CommentConverter::toSupportInfoCommentDto) - .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; - } - - @Override - public Page findByDiscountInfoWithPaging(Long discountInfoId, Pageable pageable) { - Page commentPage = commentRepository.findByDiscountInfoWithPaging(discountInfoId, pageable); - Page result = commentPage.map(CommentConverter::toDiscountInfoCommentDto); - return result; - } - - @Override - public Page findBySupportInfoWithPaging(Long supportInfoId, Pageable pageable) { - Page commentPage = commentRepository.findBySupportInfoWithPaging(supportInfoId, pageable); - Page result = commentPage.map(CommentConverter::toSupportInfoCommentDto); - return result; - } - - @Override - @Transactional - public void deleteComment(Long commentId) { - Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); - commentRepository.delete(comment); - } - - @Override - public CommentResponseDto.DiscountInfoCommentDto findDiscountCommentOne(Long commentId) { - Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such comment")); - if(comment.getDiscountInfo() == null){ - throw new RuntimeException("discountInfo comment에 대한 요청이 아닙니다."); - } - return CommentConverter.toDiscountInfoCommentDto(comment); - - } - - @Override - public CommentResponseDto.SupportInfoCommentDto findSupportCommentOne(Long commentId) { - Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such comment")); - if(comment.getSupportInfo() == null){ - throw new RuntimeException("supportInfo comment에 대한 요청이 아닙니다."); - } - return CommentConverter.toSupportInfoCommentDto(comment); - } - - @Override - @Transactional - public CommentResponseDto.DiscountInfoCommentDto modifyDiscountComment(CommentRequestDto.DiscountInfoCommentDto dto) { - Comment comment = commentRepository.findById(dto.getDiscountInfoId()).orElseThrow(() -> new NoSuchElementException("xxx")); - if(comment.getDiscountInfo() == null) { - throw new RuntimeException("discountInfo comment에 대한 요청이 아닙니다."); - } - comment.modifyComment(dto.getContent()); - - return CommentConverter.toDiscountInfoCommentDto(comment); - } - - @Override - @Transactional - public CommentResponseDto.SupportInfoCommentDto modifySupportComment(CommentRequestDto.SupportInfoCommentDto dto) { - Comment comment = commentRepository.findById(dto.getSupportInfoId()).orElseThrow(() -> new NoSuchElementException("xxx")); - if (comment.getSupportInfo() == null) { - throw new RuntimeException("supportInfo comment에 대한 요청이 아닙니다."); - } - comment.modifyComment(dto.getContent()); - - return CommentConverter.toSupportInfoCommentDto(comment); - } -} 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 deleted file mode 100644 index 9dfacb8c..00000000 --- a/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTest.java +++ /dev/null @@ -1,592 +0,0 @@ -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.comment.entity.Comment; -import com.bbteam.budgetbuddies.domain.comment.service.before.CommentService; -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.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - - -/** - * 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("무신사 할인") - .anonymousNumber(0) - .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("무신사 할인") - .anonymousNumber(0) - .build(); - discountInfoRepository.save(sale1); - DiscountInfo sale2 = DiscountInfo.builder().title("핫트랙스 할인") - .anonymousNumber(0) - .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().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); - - em.flush(); - - List result = commentService.findByDiscountInfo(sale1.getId()); - 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); - 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().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(); - - 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().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); - 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()); - - 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); - Assertions.assertThat(test3).isEqualTo(3); - Assertions.assertThat(test4).isEqualTo(4); - 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); - } - - @Test - void discountInfoCommentModifyTest() { - User user1 = User.builder() - .name("tester1") - .email("1234") - .age(5) - .phoneNumber("123456") - .build(); - userRepository.save(user1); - DiscountInfo sale1 = DiscountInfo.builder().anonymousNumber(0).title("무신사 할인").build(); - discountInfoRepository.save(sale1); - - CommentRequestDto.DiscountInfoCommentDto dto1 = CommentRequestDto.DiscountInfoCommentDto.builder() - .discountInfoId(sale1.getId()) - .content("굿") - .build(); - commentService.saveDiscountComment(user1.getId(), dto1); - CommentResponseDto.DiscountInfoCommentDto test = commentService.findByDiscountInfo(sale1.getId()).get(0); - CommentRequestDto.CommentModifyDto content = CommentRequestDto.CommentModifyDto.builder() - .commentId(test.getCommentId()) - .content("잘했어요!") - .build(); - em.clear(); - commentService.modifyDiscountComment(content); - Comment byId = commentService.findById(1L); - Assertions.assertThat(byId.getContent()).isEqualTo("잘했어요!"); - } - - - -} \ No newline at end of file From c3b1aadf197af4217ec113672c32fefed89122ea Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Wed, 31 Jul 2024 01:00:03 +0900 Subject: [PATCH 255/307] =?UTF-8?q?[refactor]=20CommentController=20?= =?UTF-8?q?=EA=B5=90=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CommentControllerImpl.java | 60 ----------- .../controller/CommentControllerV2.java | 102 ++++++++++++++++++ 2 files changed, 102 insertions(+), 60 deletions(-) delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerV2.java 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 deleted file mode 100644 index 8f9691d7..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java +++ /dev/null @@ -1,60 +0,0 @@ -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 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") - 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") - 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") - 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") - 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"); - } - -} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerV2.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerV2.java new file mode 100644 index 00000000..9a4c70a5 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerV2.java @@ -0,0 +1,102 @@ +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 lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Qualifier; +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 +public class CommentControllerV2 implements CommentControllerApi { + + @Qualifier("discountCommentService") + private final CommentService discountCommentService; + + @Qualifier("supportCommentService") + private final CommentService supportCommentService; + + public CommentControllerV2(CommentService discountCommentService, + CommentService supportCommentService) { + this.discountCommentService = discountCommentService; + this.supportCommentService = supportCommentService; + } + + @PostMapping("/discounts/comments") + public ResponseEntity saveDiscountInfoComment( + @RequestParam("userId") Long userId, + @RequestBody CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto){ + CommentResponseDto.DiscountInfoCommentDto dto = discountCommentService.saveComment(userId, discountInfoCommentDto); + return ResponseEntity.ok(dto); + } + + + @GetMapping("/discounts/comments") + public ResponseEntity> findAllByDiscountInfo( + @RequestParam("discountInfoId") Long discountInfoId, + @PageableDefault(size = 20, page = 0) Pageable pageable){ + Page result = discountCommentService.findByInfoWithPaging(discountInfoId, pageable); + return ResponseEntity.ok(result); + } + + + @PostMapping("/supports/comments") + public ResponseEntity saveSupportInfoComment( + @RequestParam("userId") Long userId, + @RequestBody CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto){ + CommentResponseDto.SupportInfoCommentDto dto = supportCommentService.saveComment(userId, supportInfoCommentDto); + return ResponseEntity.ok(dto); + } + + + @GetMapping("/supports/comments") + public ResponseEntity> findAllBySupportInfo( + @RequestParam("supportInfoId") Long supportInfoId, + @PageableDefault(size = 20, page = 0)Pageable pageable){ + Page result = supportCommentService.findByInfoWithPaging(supportInfoId, pageable); + return ResponseEntity.ok(result); + } + + @PostMapping("/comments/delete") + public ResponseEntity deleteComment(@RequestParam("commentId") Long commentId) { + discountCommentService.deleteComment(commentId); + return ResponseEntity.ok("ok"); + } + + @GetMapping("/supports/comments/modify") + public ResponseEntity findSupportOne(@RequestParam("commentId")Long commentId) { + CommentResponseDto.SupportInfoCommentDto result = supportCommentService.findCommentOne(commentId); + return ResponseEntity.ok(result); + } + + @PostMapping("/supports/comments/modify") + public ResponseEntity modifySupportOne( + @RequestBody CommentRequestDto.CommentModifyDto dto) { + CommentResponseDto.SupportInfoCommentDto result = supportCommentService.modifyComment(dto); + return ResponseEntity.ok(result); + } + + @GetMapping("/discounts/comments/modify") + public ResponseEntity findDiscountOne(@RequestParam("commentId")Long commentId) { + CommentResponseDto.DiscountInfoCommentDto result = discountCommentService.findCommentOne(commentId); + return ResponseEntity.ok(result); + } + + @PostMapping("/discounts/comments/modify") + public ResponseEntity modifyDiscountOne( + @RequestBody CommentRequestDto.CommentModifyDto dto) { + CommentResponseDto.DiscountInfoCommentDto result = discountCommentService.modifyComment(dto); + return ResponseEntity.ok(result); + } + + + +} From 4aed8c3e885b5d89aa90bea1e0b9b5a63da528fb Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Wed, 31 Jul 2024 01:01:11 +0900 Subject: [PATCH 256/307] =?UTF-8?q?[remove]=20CommentController=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/controller/CommentController.java | 62 ------------------- 1 file changed, 62 deletions(-) delete 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 deleted file mode 100644 index 7ebab75e..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java +++ /dev/null @@ -1,62 +0,0 @@ -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.before.CommentService; -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 CommentController implements CommentControllerApi { - - private final CommentService commentService; - - @PostMapping("/discounts/comments") - public ResponseEntity saveDiscountInfoComment( - @RequestParam("userId") Long userId, - @RequestBody CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto){ - CommentResponseDto.DiscountInfoCommentDto dto = commentService.saveDiscountComment(userId, discountInfoCommentDto); - return ResponseEntity.ok(dto); - } - - - @GetMapping("/discounts/comments") - 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") - public ResponseEntity saveSupportInfoComment( - @RequestParam("userId") Long userId, - @RequestBody CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto){ - CommentResponseDto.SupportInfoCommentDto dto = commentService.saveSupportComment(userId, supportInfoCommentDto); - return ResponseEntity.ok(dto); - } - - - @GetMapping("/supports/comments") - public ResponseEntity> findAllBySupportInfo( - @RequestParam("supportInfoId") Long supportInfoId, - @PageableDefault(size = 20, page = 0)Pageable pageable){ - Page result = commentService.findBySupportInfoWithPaging(supportInfoId, pageable); - return ResponseEntity.ok(result); - } - - @PostMapping("/comments/delete") - public ResponseEntity deleteComment(@RequestParam("commentId") Long commentId) { - commentService.deleteComment(commentId); - return ResponseEntity.ok("ok"); - } - - - -} From 90a86ad3555cfadee9ef593555fe1a8c93630fab Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Wed, 31 Jul 2024 22:04:15 +0900 Subject: [PATCH 257/307] =?UTF-8?q?[refactor]=20DiscountRequest=20DTO?= =?UTF-8?q?=EB=A5=BC=20=ED=95=98=EC=9C=84=20static=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EB=A1=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discountinfo/dto/DiscountRequest.java | 50 +++++++++++++++++++ .../discountinfo/dto/DiscountRequestDto.java | 25 ---------- 2 files changed, 50 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequest.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequest.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequest.java new file mode 100644 index 00000000..490565bf --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequest.java @@ -0,0 +1,50 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.dto; + +import lombok.*; + +import java.time.LocalDate; + +public class DiscountRequest { + + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class RegisterDto { + + private String title; + + private LocalDate startDate; + + private LocalDate endDate; + + private Integer discountRate; + + private String siteUrl; + + private String thumbnailUrl; + } + + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class UpdateDto { + + private Long id; + + private String title; + + private LocalDate startDate; + + private LocalDate endDate; + + private Integer discountRate; + + private String siteUrl; + + private String thumbnailUrl; + } + + +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java deleted file mode 100644 index 573a9715..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.bbteam.budgetbuddies.domain.discountinfo.dto; - -import lombok.*; - -import java.time.LocalDate; - -@Getter -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class DiscountRequestDto { - - private String title; - - private LocalDate startDate; - - private LocalDate endDate; - - private Integer discountRate; - - private String siteUrl; - - private String thumbnailUrl; - -} From 277290d793b3564bc1bc480d17e81d5577b95a8d Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Wed, 31 Jul 2024 22:05:09 +0900 Subject: [PATCH 258/307] =?UTF-8?q?[feat]=20DiscountInfo=20=EC=88=98?= =?UTF-8?q?=EC=A0=95/=EC=82=AD=EC=A0=9C=20API=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DiscountInfoApi.java | 40 +++++++++++++++++-- .../controller/DiscountInfoController.java | 32 +++++++++++---- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java index f381f94f..6aff66cb 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java @@ -1,6 +1,6 @@ package com.bbteam.budgetbuddies.domain.discountinfo.controller; -import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -8,7 +8,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import org.springframework.data.domain.Page; 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.RequestBody; import org.springframework.web.bind.annotation.RequestParam; @@ -41,9 +40,12 @@ ResponseEntity> getDiscountsByYearAndMonth( // @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 = "discountRequestDto", description = "등록할 할인 정보의 전체 내용입니다."), }) public ResponseEntity registerDiscountInfo( - @RequestBody DiscountRequestDto discountRequestDto + @RequestBody DiscountRequest.RegisterDto discountRequestDto ); @Operation(summary = "[User] 특정 할인정보에 좋아요 클릭 API", description = "특정 할인정보에 좋아요 버튼을 클릭하는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)") @@ -62,4 +64,36 @@ public ResponseEntity likeDiscountInfo( @PathVariable Long discountInfoId ); + @Operation(summary = "[ADMIN] 특정 할인정보 수정하기 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 = "discountRequestDto", description = "수정할 할인 정보의 전체 내용입니다."), + }) + public ResponseEntity updateDiscountInfo( + @RequestParam Long userId, + @RequestBody DiscountRequest.UpdateDto discountRequestDto + ); + + @Operation(summary = "[ADMIN] 특정 할인정보 삭제하기 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 = "discountInfoId", description = "삭제할 할인 정보의 id입니다."), + }) + public ResponseEntity deleteDiscountInfo( + @RequestParam Long userId, + @PathVariable Long discountInfoId + ); + } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java index cd129809..835c941b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java @@ -1,12 +1,8 @@ package com.bbteam.budgetbuddies.domain.discountinfo.controller; -import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; import com.bbteam.budgetbuddies.domain.discountinfo.service.DiscountInfoService; -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; @@ -35,7 +31,7 @@ public ResponseEntity> getDiscountsByYearAndMonth( @Override @PostMapping("") public ResponseEntity registerDiscountInfo( - @RequestBody DiscountRequestDto discountRequestDto + @RequestBody DiscountRequest.RegisterDto discountRequestDto ) { DiscountResponseDto discountResponseDto = discountInfoService.registerDiscountInfo(discountRequestDto); @@ -43,7 +39,7 @@ public ResponseEntity registerDiscountInfo( } @Override - @PostMapping("/{discountInfoId}/likes") + @PostMapping("/likes/{discountInfoId}") public ResponseEntity likeDiscountInfo( @RequestParam Long userId, @PathVariable Long discountInfoId @@ -53,4 +49,26 @@ public ResponseEntity likeDiscountInfo( return ResponseEntity.ok(discountResponseDto); } + @Override + @PutMapping("") + public ResponseEntity updateDiscountInfo( + @RequestParam Long userId, + @RequestBody DiscountRequest.UpdateDto discountRequestDto + ) { + DiscountResponseDto discountResponseDto = discountInfoService.updateDiscountInfo(userId, discountRequestDto); + + return ResponseEntity.ok(discountResponseDto); + } + + @Override + @DeleteMapping("{discountInfoId}") + public ResponseEntity deleteDiscountInfo( + @RequestParam Long userId, + @PathVariable Long discountInfoId + ) { + String message = discountInfoService.deleteDiscountInfo(userId, discountInfoId); + + return ResponseEntity.ok(message); + } + } From 3a3b839fafe12a0ec7966df894a3ea7eeaa8694a Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Wed, 31 Jul 2024 22:05:26 +0900 Subject: [PATCH 259/307] =?UTF-8?q?[feat]=20DiscountInfo=20=EC=88=98?= =?UTF-8?q?=EC=A0=95/=EC=82=AD=EC=A0=9C=20API=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=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/DiscountInfoService.java | 7 ++- .../service/DiscountInfoServiceImpl.java | 48 ++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java index 5be85054..e2900be6 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java @@ -1,6 +1,6 @@ package com.bbteam.budgetbuddies.domain.discountinfo.service; -import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; import org.springframework.data.domain.Page; @@ -12,9 +12,12 @@ Page getDiscountsByYearAndMonth( Integer size ); - DiscountResponseDto registerDiscountInfo(DiscountRequestDto discountRequestDto); + DiscountResponseDto registerDiscountInfo(DiscountRequest.RegisterDto discountRequestDto); DiscountResponseDto toggleLike(Long userId, Long discountInfoId); + DiscountResponseDto updateDiscountInfo(Long userId, DiscountRequest.UpdateDto discountRequestDto); + + public String deleteDiscountInfo(Long userId, Long discountInfoId); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java index a1ef0604..f7764463 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java @@ -1,7 +1,7 @@ package com.bbteam.budgetbuddies.domain.discountinfo.service; import com.bbteam.budgetbuddies.domain.discountinfo.converter.DiscountInfoConverter; -import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; import com.bbteam.budgetbuddies.domain.discountinfo.repository.DiscountInfoRepository; @@ -53,7 +53,7 @@ public Page getDiscountsByYearAndMonth(Integer year, Intege @Transactional @Override - public DiscountResponseDto registerDiscountInfo(DiscountRequestDto discountRequestDto) { + public DiscountResponseDto registerDiscountInfo(DiscountRequest.RegisterDto discountRequestDto) { /** * 1. RequestDto -> Entity로 변환 * 2. Entity 저장 @@ -115,5 +115,49 @@ public DiscountResponseDto toggleLike(Long userId, Long discountInfoId) { return discountInfoConverter.toDto(savedEntity); } + @Transactional + @Override + public DiscountResponseDto updateDiscountInfo(Long userId, DiscountRequest.UpdateDto discountRequestDto) { + /** + * 1. 사용자 조회 -> 없으면 에러 + * 2. 할인정보 조회 -> 없으면 에러 + * 3. 변경사항 업데이트 + * 4. 변경사항 저장 + * 5. Entity -> ResponseDto로 변환 후 리턴 + */ + + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + + DiscountInfo discountInfo = discountInfoRepository.findById(discountRequestDto.getId()) + .orElseThrow(() -> new IllegalArgumentException("DiscountInfo not found")); + + discountInfo.update(discountRequestDto); // 변경사항 업데이트 + discountInfoRepository.save(discountInfo); // 변경사항 저장 + + return discountInfoConverter.toDto(discountInfo); + } + + @Transactional + @Override + public String deleteDiscountInfo(Long userId, Long discountInfoId) { + /** + * 1. 사용자 조회 -> 없으면 에러 + * 2. 할인정보 조회 -> 없으면 에러 + * 3. Entity 삭제 + * 4. 성공여부 반환 + */ + + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + + DiscountInfo discountInfo = discountInfoRepository.findById(discountInfoId) + .orElseThrow(() -> new IllegalArgumentException("DiscountInfo not found")); + + discountInfoRepository.deleteById(discountInfoId); + + return "Success"; + + } } From befa219442866c6c57b86aa64b42c11e7afc0aef Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Wed, 31 Jul 2024 22:06:02 +0900 Subject: [PATCH 260/307] =?UTF-8?q?[feat]=20DiscountRequest=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81=EC=97=90=20=EB=A7=9E=EA=B2=8C=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20toEntity=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=98=A4=EB=B2=84=EB=A1=9C?= =?UTF-8?q?=EB=94=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/DiscountInfoConverter.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java index 81e76f77..787e76de 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java @@ -1,6 +1,6 @@ package com.bbteam.budgetbuddies.domain.discountinfo.converter; -import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; import org.springframework.stereotype.Service; @@ -32,7 +32,26 @@ public DiscountResponseDto toDto(DiscountInfo entity) { * @param requestDto * @return entity */ - public DiscountInfo toEntity(DiscountRequestDto requestDto) { + public DiscountInfo toEntity(DiscountRequest.RegisterDto requestDto) { + + return DiscountInfo.builder() + .title(requestDto.getTitle()) + .startDate(requestDto.getStartDate()) + .endDate(requestDto.getEndDate()) + .anonymousNumber(0) + .discountRate(requestDto.getDiscountRate()) + .likeCount(0) + .siteUrl(requestDto.getSiteUrl()) + .thumbnailUrl(requestDto.getThumbnailUrl()) + .build(); + } + + /** + * + * @param requestDto + * @return entity + */ + public DiscountInfo toEntity(DiscountRequest.UpdateDto requestDto) { return DiscountInfo.builder() .title(requestDto.getTitle()) From 257e0190c24b18b087c21d6d345ccfa457a84c7e Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Wed, 31 Jul 2024 22:07:02 +0900 Subject: [PATCH 261/307] =?UTF-8?q?[refactor]=20DiscountRequest=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=EC=97=90=20=EB=A7=9E?= =?UTF-8?q?=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 --- .../discountinfo/service/DiscountInfoServiceTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceTest.java index 3733a825..0fee5041 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceTest.java @@ -1,7 +1,7 @@ package com.bbteam.budgetbuddies.domain.discountinfo.service; import com.bbteam.budgetbuddies.domain.discountinfo.converter.DiscountInfoConverter; -import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; import com.bbteam.budgetbuddies.domain.discountinfo.repository.DiscountInfoRepository; @@ -103,12 +103,13 @@ void getDiscountsByYearAndMonthTest() { @DisplayName("할인 정보 등록이 정상적으로 되는지 검증") void registerDiscountInfoTest() { // given - DiscountRequestDto requestDto = DiscountRequestDto.builder() + DiscountRequest.RegisterDto requestDto = DiscountRequest.RegisterDto.builder() .title("할인 정보 제목") .startDate(LocalDate.of(2024, 7, 1)) .endDate(LocalDate.of(2024, 7, 21)) .discountRate(30) .siteUrl("http://example.com") + .thumbnailUrl("http://example.com2") .build(); DiscountInfo entity = DiscountInfo.builder() @@ -117,6 +118,7 @@ void registerDiscountInfoTest() { .endDate(LocalDate.of(2024, 7, 21)) .discountRate(30) .siteUrl("http://example.com") + .thumbnailUrl("http://example.com2") .build(); DiscountResponseDto responseDto = DiscountResponseDto.builder() @@ -126,6 +128,7 @@ void registerDiscountInfoTest() { .endDate(LocalDate.of(2024, 7, 21)) .discountRate(30) .siteUrl("http://example.com") + .thumbnailUrl("http://example.com2") .likeCount(0) .anonymousNumber(0) .build(); From b81baaaf81976313d541d8bda03133f71f95359f Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Wed, 31 Jul 2024 22:08:09 +0900 Subject: [PATCH 262/307] =?UTF-8?q?[fix]=20Merge=20=EC=8B=9C=20=EB=88=84?= =?UTF-8?q?=EB=9D=BD=EB=90=9C=20=EC=BD=94=EB=93=9C=20=EC=9E=AC=EC=82=BD?= =?UTF-8?q?=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supportinfo/repository/SupportInfoRepositoryTest.java | 7 +++++++ 1 file changed, 7 insertions(+) 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 index 9bb09ce0..e460d8cb 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepositoryTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepositoryTest.java @@ -31,6 +31,13 @@ class SupportInfoRepositoryTest { @DisplayName("@SoftDelete 테스트") void deletedTest() { // given + SupportInfo discount1 = SupportInfo.builder() + .title("지원정보1") + .startDate(LocalDate.of(2024, 7, 1)) + .endDate(LocalDate.of(2024, 7, 21)) + .siteUrl("http://example1.com") + .build(); + SupportInfo discount2 = SupportInfo.builder() .title("지원정보2") .startDate(LocalDate.of(2024, 7, 1)) From 0cbf688e9b818aedcdc9a316a1d463733b302256 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Wed, 31 Jul 2024 22:08:21 +0900 Subject: [PATCH 263/307] =?UTF-8?q?[fix]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20import=EB=AC=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supportinfo/service/SupportInfoServiceTest.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java index c8aa3ddd..fe5214df 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java @@ -1,13 +1,5 @@ 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.discountinfo.service.DiscountInfoServiceImpl; -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; @@ -36,11 +28,9 @@ import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.*; -import static org.mockito.Mockito.times; @Transactional @ExtendWith(MockitoExtension.class) From 271006c0189a343028468f2f5e656c824c44e996 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Wed, 31 Jul 2024 22:08:52 +0900 Subject: [PATCH 264/307] =?UTF-8?q?[fix]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20import=EB=AC=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/supportinfo/converter/SupportInfoConverter.java | 3 --- 1 file changed, 3 deletions(-) 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 index 6bc8a7be..d06abcc6 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/converter/SupportInfoConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/converter/SupportInfoConverter.java @@ -1,8 +1,5 @@ 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; From 1b95fcc357610e5fbb64e17161f12bb9af8945e2 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 1 Aug 2024 11:50:04 +0900 Subject: [PATCH 265/307] =?UTF-8?q?[feat]=20Swagger=20API=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 --- ...ntrollerV2.java => CommentController.java} | 7 ++- .../controller/CommentControllerApi.java | 48 ++++++++++++++++++- 2 files changed, 50 insertions(+), 5 deletions(-) rename src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/{CommentControllerV2.java => CommentController.java} (94%) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerV2.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java similarity index 94% rename from src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerV2.java rename to src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java index 9a4c70a5..96f7e436 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerV2.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java @@ -3,7 +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 lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -12,7 +11,7 @@ import org.springframework.web.bind.annotation.*; @RestController -public class CommentControllerV2 implements CommentControllerApi { +public class CommentController implements CommentControllerApi { @Qualifier("discountCommentService") private final CommentService supportCommentService; - public CommentControllerV2(CommentService discountCommentService, - CommentService supportCommentService) { this.discountCommentService = discountCommentService; this.supportCommentService = supportCommentService; diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java index 730f6b6e..ecaa37a4 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java @@ -11,6 +11,9 @@ import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; public interface CommentControllerApi { @Operation(summary = "[User] 특정 할인 정보 게시글에 댓글달기", description = "특정 할인 정보 게시글에 댓글을 다는 API입니다.") @@ -75,6 +78,49 @@ ResponseEntity> findAllBySupportI @Parameters({ @Parameter(name = "commentId", description = "삭제할 댓글 id 입니다. parameter") }) - @GetMapping("/comments/delete") ResponseEntity deleteComment(Long commentId); + + @Operation(summary = "[User] SupportInfo의 댓글 요청 API ", description = "특정 댓글을 요청하는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "commentId", description = "조회할 댓글 id 입니다. parameter") + }) + ResponseEntity findSupportOne(@RequestParam("commentId")Long commentId); + + @Operation(summary = "[User] SupprotInfo의 댓글 변경 API", description = "특정 댓글을 변경하는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "commentId", description = "변경할 댓글 id 입니다. requestbody"), + @Parameter(name = "comment", description = "변경할 댓글 내용입니다.. requestbody") + + }) + ResponseEntity modifySupportOne( + @RequestBody CommentRequestDto.CommentModifyDto dto); + + + @Operation(summary = "[User] DiscountInfo의 댓글 요청 API ", description = "특정 댓글을 요청하는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "commentId", description = "조회할 댓글 id 입니다. parameter") + }) + ResponseEntity findDiscountOne(@RequestParam("commentId")Long commentId); + + @Operation(summary = "[User] DiscountInfo의 댓글 변경 API", description = "특정 댓글을 변경하는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "commentId", description = "변경할 댓글 id 입니다. requestbody"), + @Parameter(name = "comment", description = "변경할 댓글 내용입니다.. requestbody") + + }) + ResponseEntity modifyDiscountOne( + @RequestBody CommentRequestDto.CommentModifyDto dto); + } From ab07c624be698e1a150e1c9854280de8cfc76c9f Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 1 Aug 2024 11:53:18 +0900 Subject: [PATCH 266/307] =?UTF-8?q?[remove]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=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/service/AbstractCommentService.java | 2 -- .../domain/comment/service/SupportCommentService.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/AbstractCommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/AbstractCommentService.java index fa5f87f9..9bf31236 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/AbstractCommentService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/AbstractCommentService.java @@ -1,7 +1,5 @@ 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.entity.Comment; import com.bbteam.budgetbuddies.domain.comment.repository.CommentRepository; diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java index 123483d5..9e46d66b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java @@ -5,12 +5,10 @@ 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.comment.service.before.CommentService; 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.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; From b9e4011cc0ee2af269e72d155ab8d82d3325ad6d Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 1 Aug 2024 16:37:06 +0900 Subject: [PATCH 267/307] =?UTF-8?q?[refactor,=20fix]=20URL=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EB=B0=8F=20API=20=EC=98=A4=ED=91=9C=EA=B8=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/controller/CommentController.java | 20 +++++++++---------- .../controller/CommentControllerApi.java | 18 ++++++++--------- 2 files changed, 18 insertions(+), 20 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 96f7e436..f77b4d33 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 @@ -38,9 +38,9 @@ public ResponseEntity saveDiscountInf } - @GetMapping("/discounts/comments") + @GetMapping("/discounts/{discountInfoId}/comments") public ResponseEntity> findAllByDiscountInfo( - @RequestParam("discountInfoId") Long discountInfoId, + @PathVariable("discountInfoId") Long discountInfoId, @PageableDefault(size = 20, page = 0) Pageable pageable){ Page result = discountCommentService.findByInfoWithPaging(discountInfoId, pageable); return ResponseEntity.ok(result); @@ -56,22 +56,22 @@ public ResponseEntity saveSupportInfoC } - @GetMapping("/supports/comments") + @GetMapping("/supports/{supportInfoId}/comments") public ResponseEntity> findAllBySupportInfo( - @RequestParam("supportInfoId") Long supportInfoId, + @PathVariable("supportInfoId") Long supportInfoId, @PageableDefault(size = 20, page = 0)Pageable pageable){ Page result = supportCommentService.findByInfoWithPaging(supportInfoId, pageable); return ResponseEntity.ok(result); } - @PostMapping("/comments/delete") - public ResponseEntity deleteComment(@RequestParam("commentId") Long commentId) { + @PostMapping("/comments/{commentId}/delete") + public ResponseEntity deleteComment(@PathVariable("commentId") Long commentId) { discountCommentService.deleteComment(commentId); return ResponseEntity.ok("ok"); } - @GetMapping("/supports/comments/modify") - public ResponseEntity findSupportOne(@RequestParam("commentId")Long commentId) { + @GetMapping("/supports/comments/{commentId}/getOne") + public ResponseEntity findSupportOne(@PathVariable("commentId")Long commentId) { CommentResponseDto.SupportInfoCommentDto result = supportCommentService.findCommentOne(commentId); return ResponseEntity.ok(result); } @@ -83,8 +83,8 @@ public ResponseEntity modifySupportOne return ResponseEntity.ok(result); } - @GetMapping("/discounts/comments/modify") - public ResponseEntity findDiscountOne(@RequestParam("commentId")Long commentId) { + @GetMapping("/discounts/comments/{commentId}/getOne") + public ResponseEntity findDiscountOne(@PathVariable("commentId")Long commentId) { CommentResponseDto.DiscountInfoCommentDto result = discountCommentService.findCommentOne(commentId); return ResponseEntity.ok(result); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java index ecaa37a4..1a2a396b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java @@ -10,8 +10,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; @@ -35,7 +33,7 @@ ResponseEntity saveDiscountInfoCommen @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) @Parameters({ - @Parameter(name = "discountInfoId", description = "댓글을 가져올 할인 정보 게시글 id입니다. parameter"), + @Parameter(name = "discountInfoId", description = "댓글을 가져올 할인 정보 게시글 id입니다. pathVariable"), @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") }) @@ -61,7 +59,7 @@ ResponseEntity saveSupportInfoComment( @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) @Parameters({ - @Parameter(name = "supportInfoId", description = "댓글을 가져올 지원 정보 게시글 id입니다. parameter"), + @Parameter(name = "supportInfoId", description = "댓글을 가져올 지원 정보 게시글 id입니다. pathVariable"), @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") @@ -76,7 +74,7 @@ ResponseEntity> findAllBySupportI @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) @Parameters({ - @Parameter(name = "commentId", description = "삭제할 댓글 id 입니다. parameter") + @Parameter(name = "commentId", description = "삭제할 댓글 id 입니다. pathVariable") }) ResponseEntity deleteComment(Long commentId); @@ -85,17 +83,17 @@ ResponseEntity> findAllBySupportI @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) @Parameters({ - @Parameter(name = "commentId", description = "조회할 댓글 id 입니다. parameter") + @Parameter(name = "commentId", description = "조회할 댓글 id 입니다. pathVariable") }) ResponseEntity findSupportOne(@RequestParam("commentId")Long commentId); - @Operation(summary = "[User] SupprotInfo의 댓글 변경 API", description = "특정 댓글을 변경하는 API입니다.") + @Operation(summary = "[User] SupportInfo의 댓글 변경 API", description = "특정 댓글을 변경하는 API입니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) @Parameters({ @Parameter(name = "commentId", description = "변경할 댓글 id 입니다. requestbody"), - @Parameter(name = "comment", description = "변경할 댓글 내용입니다.. requestbody") + @Parameter(name = "content", description = "변경할 댓글 내용입니다.. requestbody") }) ResponseEntity modifySupportOne( @@ -107,7 +105,7 @@ ResponseEntity modifySupportOne( @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) @Parameters({ - @Parameter(name = "commentId", description = "조회할 댓글 id 입니다. parameter") + @Parameter(name = "commentId", description = "조회할 댓글 id 입니다. pathVariable") }) ResponseEntity findDiscountOne(@RequestParam("commentId")Long commentId); @@ -117,7 +115,7 @@ ResponseEntity modifySupportOne( }) @Parameters({ @Parameter(name = "commentId", description = "변경할 댓글 id 입니다. requestbody"), - @Parameter(name = "comment", description = "변경할 댓글 내용입니다.. requestbody") + @Parameter(name = "content", description = "변경할 댓글 내용입니다.. requestbody") }) ResponseEntity modifyDiscountOne( From 30d1969d8eec6c3e449380c91ad40d8f57a6d241 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 1 Aug 2024 16:37:40 +0900 Subject: [PATCH 268/307] =?UTF-8?q?[feat]=20createdAt=EC=97=90=20JsonForma?= =?UTF-8?q?t=20=EC=B6=94=EA=B0=80=EB=A1=9C=20=EB=82=A0=EC=A7=9C=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../budgetbuddies/domain/comment/dto/CommentResponseDto.java | 3 +++ 1 file changed, 3 insertions(+) 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 932cad45..48931147 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 @@ -1,6 +1,7 @@ package com.bbteam.budgetbuddies.domain.comment.dto; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Builder; import lombok.Getter; @@ -17,6 +18,7 @@ public static class DiscountInfoCommentDto{ private Long discountInfoId; private String content; private Integer anonymousNumber; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "Asia/Seoul") private LocalDateTime createdAt; } @@ -28,6 +30,7 @@ public static class SupportInfoCommentDto{ private Long supportInfoId; private String content; private Integer anonymousNumber; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "Asia/Seoul") private LocalDateTime createdAt; } From 72fc3c7c06264a57c41899767b90150e3218edcf Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 1 Aug 2024 18:46:11 +0900 Subject: [PATCH 269/307] =?UTF-8?q?[fix]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EB=A9=94=EC=86=8C=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 --- .../converter/DiscountInfoConverter.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java index 787e76de..7a9e39eb 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java @@ -46,23 +46,4 @@ public DiscountInfo toEntity(DiscountRequest.RegisterDto requestDto) { .build(); } - /** - * - * @param requestDto - * @return entity - */ - public DiscountInfo toEntity(DiscountRequest.UpdateDto requestDto) { - - return DiscountInfo.builder() - .title(requestDto.getTitle()) - .startDate(requestDto.getStartDate()) - .endDate(requestDto.getEndDate()) - .anonymousNumber(0) - .discountRate(requestDto.getDiscountRate()) - .likeCount(0) - .siteUrl(requestDto.getSiteUrl()) - .thumbnailUrl(requestDto.getThumbnailUrl()) - .build(); - } - } From bcdb3867490084bfd42e9c088ccc95c5391c1486 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 1 Aug 2024 18:46:57 +0900 Subject: [PATCH 270/307] =?UTF-8?q?[feat]=20getDiscountInfo=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20(=ED=95=A0=EC=9D=B8=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EB=8B=A8=EA=B1=B4=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discountinfo/controller/DiscountInfoApi.java | 16 ++++++++++++++++ .../controller/DiscountInfoController.java | 14 +++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java index 6aff66cb..5603e0f3 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java @@ -96,4 +96,20 @@ public ResponseEntity deleteDiscountInfo( @PathVariable Long discountInfoId ); + @Operation(summary = "[ADMIN] 특정 할인정보 가져오기 API", description = "ID를 통해 특정 할인정보를 가져오는 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 = "discountInfoId", description = "조회할 할인 정보의 id입니다."), + }) + public ResponseEntity getDiscountInfo( + @RequestParam Long userId, + @PathVariable Long discountInfoId + ); + } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java index 835c941b..ec1c51d7 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java @@ -61,7 +61,7 @@ public ResponseEntity updateDiscountInfo( } @Override - @DeleteMapping("{discountInfoId}") + @DeleteMapping("/{discountInfoId}") public ResponseEntity deleteDiscountInfo( @RequestParam Long userId, @PathVariable Long discountInfoId @@ -71,4 +71,16 @@ public ResponseEntity deleteDiscountInfo( return ResponseEntity.ok(message); } + + @Override + @GetMapping("/{discountInfoId}") + public ResponseEntity getDiscountInfo( + @RequestParam Long userId, + @PathVariable Long discountInfoId + ) { + DiscountResponseDto discountResponseDto = discountInfoService.getDiscountInfoById(userId, discountInfoId); + + return ResponseEntity.ok(discountResponseDto); + } + } From 817c7bb629cb7f7a95b4e1c21574d37d02cfee88 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 1 Aug 2024 18:47:09 +0900 Subject: [PATCH 271/307] =?UTF-8?q?[feat]=20getDiscountInfo=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B5=AC=ED=98=84=20(=ED=95=A0=EC=9D=B8=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EB=8B=A8=EA=B1=B4=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/DiscountInfoService.java | 6 ++++-- .../service/DiscountInfoServiceImpl.java | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java index e2900be6..cd8d54de 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java @@ -18,6 +18,8 @@ Page getDiscountsByYearAndMonth( DiscountResponseDto updateDiscountInfo(Long userId, DiscountRequest.UpdateDto discountRequestDto); - public String deleteDiscountInfo(Long userId, Long discountInfoId); + String deleteDiscountInfo(Long userId, Long discountInfoId); -} + DiscountResponseDto getDiscountInfoById(Long userId, Long discountInfoId); + +} \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java index f7764463..b7348821 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java @@ -160,4 +160,23 @@ public String deleteDiscountInfo(Long userId, Long discountInfoId) { return "Success"; } + + @Transactional + @Override + public DiscountResponseDto getDiscountInfoById(Long userId, Long discountInfoId) { + /** + * 1. 사용자 조회 -> 없으면 에러 + * 2. 할인정보 조회 -> 없으면 에러 + * 3. Entity 조회 + * 4. Entity -> ResponseDto로 변환 후 리턴 + */ + + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + + DiscountInfo discountInfo = discountInfoRepository.findById(discountInfoId) + .orElseThrow(() -> new IllegalArgumentException("DiscountInfo not found")); + + return discountInfoConverter.toDto(discountInfo); + } } From e038d3c66dcfae1ea54060bee46b679f60ac8895 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 1 Aug 2024 20:25:23 +0900 Subject: [PATCH 272/307] =?UTF-8?q?[feat]=20SupportInfo=20update=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=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/supportinfo/entity/SupportInfo.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 752341b7..93d43d0d 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 @@ -1,6 +1,8 @@ package com.bbteam.budgetbuddies.domain.supportinfo.entity; import com.bbteam.budgetbuddies.common.BaseEntity; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequest; import jakarta.persistence.Column; import jakarta.persistence.Entity; import lombok.*; @@ -48,4 +50,12 @@ public Integer addAndGetAnonymousNumber() { return anonymousNumber; } + public void update(SupportRequest.UpdateDto supportRequestDto) { + this.title = supportRequestDto.getTitle(); + this.startDate = supportRequestDto.getStartDate(); + this.endDate = supportRequestDto.getEndDate(); + this.siteUrl = supportRequestDto.getSiteUrl(); + this.thumbnailUrl = supportRequestDto.getThumbnailUrl(); + } + } From 9d675459cd843de8989a5f66963ea9db5833dbc1 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 1 Aug 2024 20:26:04 +0900 Subject: [PATCH 273/307] =?UTF-8?q?[refactor]=20SupportRequest=20DTO?= =?UTF-8?q?=EB=A5=BC=20=ED=95=98=EC=9C=84=20static=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EB=A1=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supportinfo/dto/SupportRequest.java | 52 +++++++++++++++++++ .../supportinfo/dto/SupportRequestDto.java | 26 ---------- 2 files changed, 52 insertions(+), 26 deletions(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequest.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequestDto.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequest.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequest.java new file mode 100644 index 00000000..a9ba1405 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequest.java @@ -0,0 +1,52 @@ +package com.bbteam.budgetbuddies.domain.supportinfo.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + + +public class SupportRequest { + + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class RegisterDto { + + private String title; + + private LocalDate startDate; + + private LocalDate endDate; + + private String siteUrl; + + private String thumbnailUrl; + + } + + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class UpdateDto { + + private Long id; + + private String title; + + private LocalDate startDate; + + private LocalDate endDate; + + private String siteUrl; + + private String thumbnailUrl; + + } + + +} 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 deleted file mode 100644 index c008de0a..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequestDto.java +++ /dev/null @@ -1,26 +0,0 @@ -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; - - private String thumbnailUrl; - -} From b82d680799a5aec3785e9cb91fb89bcd10d9b534 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 1 Aug 2024 20:26:33 +0900 Subject: [PATCH 274/307] =?UTF-8?q?[feat]=20SupportInfo=20=EC=88=98?= =?UTF-8?q?=EC=A0=95/=EC=82=AD=EC=A0=9C=20API=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SupportInfoApi.java | 57 +++++++++++++++++-- .../controller/SupportInfoController.java | 49 ++++++++++++---- 2 files changed, 91 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java index 94f0d16c..0bdba4ab 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java @@ -1,6 +1,6 @@ package com.bbteam.budgetbuddies.domain.supportinfo.controller; -import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequestDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequest; import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -27,7 +27,7 @@ public interface SupportInfoApi { @Parameter(name = "page", description = "페이지 번호, 0번이 1 페이지 입니다. (기본값은 0입니다.)"), @Parameter(name = "size", description = "한 페이지에 불러올 데이터 개수입니다. (기본값은 10개입니다.)") }) - public ResponseEntity> getSupportsByYearAndMonth( + ResponseEntity> getSupportsByYearAndMonth( @RequestParam Integer year, @RequestParam Integer month, @RequestParam(defaultValue = "0") Integer page, @@ -41,8 +41,8 @@ public ResponseEntity> getSupportsByYearAndMonth( // @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))) }) - public ResponseEntity registerDiscountInfo( - @RequestBody SupportRequestDto requestDto + ResponseEntity registerSupportInfo( + @RequestBody SupportRequest.RegisterDto requestDto ); @Operation(summary = "[User] 특정 지원정보에 좋아요 클릭 API", description = "특정 지원정보에 좋아요 버튼을 클릭하는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)") @@ -56,7 +56,54 @@ public ResponseEntity registerDiscountInfo( @Parameter(name = "userId", description = "좋아요를 누른 사용자의 id입니다."), @Parameter(name = "supportInfoId", description = "좋아요를 누를 지원정보의 id입니다."), }) - public ResponseEntity likeDiscountInfo( + ResponseEntity likeSupportInfo( + @RequestParam Long userId, + @PathVariable Long supportInfoId + ); + + @Operation(summary = "[ADMIN] 특정 지원정보 수정하기 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입니다."), + }) + ResponseEntity updateSupportInfo( + @RequestParam Long userId, + @RequestBody SupportRequest.UpdateDto supportRequestDto + ); + + @Operation(summary = "[ADMIN] 특정 지원정보 삭제하기 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입니다."), + }) + ResponseEntity deleteSupportInfo( + @RequestParam Long userId, + @PathVariable Long supportInfoId + ); + + @Operation(summary = "[ADMIN] 특정 지원정보 가져오기 API", description = "ID를 통해 특정 지원정보를 가져오는 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입니다."), + }) + ResponseEntity getSupportInfo( @RequestParam Long userId, @PathVariable Long supportInfoId ); 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 index beba1301..4a5eccb9 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoController.java @@ -1,14 +1,10 @@ package com.bbteam.budgetbuddies.domain.supportinfo.controller; -import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; -import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequestDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequest; 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; @@ -36,8 +32,8 @@ public ResponseEntity> getSupportsByYearAndMonth( @Override @PostMapping("") - public ResponseEntity registerDiscountInfo( - @RequestBody SupportRequestDto requestDto + public ResponseEntity registerSupportInfo( + @RequestBody SupportRequest.RegisterDto requestDto ) { SupportResponseDto supportResponseDto = supportInfoService.registerSupportInfo(requestDto); @@ -45,8 +41,8 @@ public ResponseEntity registerDiscountInfo( } @Override - @PostMapping("/{supportInfoId}/likes") - public ResponseEntity likeDiscountInfo( + @PostMapping("/likes/{supportInfoId}") + public ResponseEntity likeSupportInfo( @RequestParam Long userId, @PathVariable Long supportInfoId ) { @@ -55,4 +51,37 @@ public ResponseEntity likeDiscountInfo( return ResponseEntity.ok(supportResponseDto); } + @Override + @PutMapping("") + public ResponseEntity updateSupportInfo( + @RequestParam Long userId, + @RequestBody SupportRequest.UpdateDto supportRequestDto + ) { + SupportResponseDto supportResponseDto = supportInfoService.updateSupportInfo(userId, supportRequestDto); + + return ResponseEntity.ok(supportResponseDto); + } + + @Override + @DeleteMapping("/{supportInfoId}") + public ResponseEntity deleteSupportInfo( + @RequestParam Long userId, + @PathVariable Long supportInfoId + ) { + String message = supportInfoService.deleteSupportInfo(userId, supportInfoId); + + return ResponseEntity.ok(message); + } + + @Override + @GetMapping("/{supportInfoId}") + public ResponseEntity getSupportInfo( + @RequestParam Long userId, + @PathVariable Long supportInfoId + ) { + SupportResponseDto supportResponseDto = supportInfoService.getSupportInfoById(userId, supportInfoId); + + return ResponseEntity.ok(supportResponseDto); + } + } From 99c546ba458fccb603ce5eec5e1e6c6acfe15052 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 1 Aug 2024 20:26:49 +0900 Subject: [PATCH 275/307] =?UTF-8?q?[feat]=20SupportInfo=20=EC=88=98?= =?UTF-8?q?=EC=A0=95/=EC=82=AD=EC=A0=9C=20API=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=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 | 15 ++-- .../service/SupportInfoServiceImpl.java | 78 ++++++++++++++++--- 2 files changed, 78 insertions(+), 15 deletions(-) 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 index bc01ebd9..b56e149f 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoService.java @@ -1,8 +1,6 @@ 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.SupportRequest; import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; import org.springframework.data.domain.Page; @@ -14,7 +12,14 @@ Page getSupportsByYearAndMonth( Integer size ); - SupportResponseDto registerSupportInfo(SupportRequestDto supportRequestDto); + SupportResponseDto registerSupportInfo(SupportRequest.RegisterDto supportRequest); SupportResponseDto toggleLike(Long userId, Long supportInfoId); -} + + SupportResponseDto updateSupportInfo(Long userId, SupportRequest.UpdateDto supportRequestDto); + + String deleteSupportInfo(Long userId, Long supportInfoId); + + SupportResponseDto getSupportInfoById(Long userId, Long supportInfoId); + +} \ No newline at end of file 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 index 25530dd8..aecff710 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java @@ -1,14 +1,7 @@ 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.SupportRequest; import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; import com.bbteam.budgetbuddies.domain.supportinfo.repository.SupportInfoRepository; @@ -60,13 +53,13 @@ public Page getSupportsByYearAndMonth(Integer year, Integer @Transactional @Override - public SupportResponseDto registerSupportInfo(SupportRequestDto supportRequestDto) { + public SupportResponseDto registerSupportInfo(SupportRequest.RegisterDto supportRequest) { /** * 1. RequestDto -> Entity로 변환 * 2. Entity 저장 * 3. Entity -> ResponseDto로 변환 후 리턴 */ - SupportInfo entity = supportInfoConverter.toEntity(supportRequestDto); + SupportInfo entity = supportInfoConverter.toEntity(supportRequest); supportInfoRepository.save(entity); @@ -121,4 +114,69 @@ public SupportResponseDto toggleLike(Long userId, Long supportInfoId) { return supportInfoConverter.toDto(savedEntity); } + + @Transactional + @Override + public SupportResponseDto updateSupportInfo(Long userId, SupportRequest.UpdateDto supportRequestDto) { + /** + * 1. 사용자 조회 -> 없으면 에러 + * 2. 지원정보 조회 -> 없으면 에러 + * 3. 변경사항 업데이트 + * 4. 변경사항 저장 + * 5. Entity -> ResponseDto로 변환 후 리턴 + */ + + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + + SupportInfo supportInfo = supportInfoRepository.findById(supportRequestDto.getId()) + .orElseThrow(() -> new IllegalArgumentException("DiscountInfo not found")); + + supportInfo.update(supportRequestDto); // 변경사항 업데이트 + + supportInfoRepository.save(supportInfo); // 변경사항 저장 + + return supportInfoConverter.toDto(supportInfo); + } + + @Transactional + @Override + public String deleteSupportInfo(Long userId, Long supportInfoId) { + /** + * 1. 사용자 조회 -> 없으면 에러 + * 2. 지원정보 조회 -> 없으면 에러 + * 3. Entity 삭제 + * 4. 성공여부 반환 + */ + + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + + SupportInfo supportInfo = supportInfoRepository.findById(supportInfoId) + .orElseThrow(() -> new IllegalArgumentException("SupportInfo not found")); + + supportInfoRepository.deleteById(supportInfoId); + + return "Success"; + + } + + @Transactional + @Override + public SupportResponseDto getSupportInfoById(Long userId, Long supportInfoId) { + /** + * 1. 사용자 조회 -> 없으면 에러 + * 2. 지원정보 조회 -> 없으면 에러 + * 3. Entity 조회 + * 4. Entity -> ResponseDto로 변환 후 리턴 + */ + + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + + SupportInfo supportInfo = supportInfoRepository.findById(supportInfoId) + .orElseThrow(() -> new IllegalArgumentException("SupportInfo not found")); + + return supportInfoConverter.toDto(supportInfo); + } } From 43b8d8581b8b066eaf54e385ea786bdd390c656c Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 1 Aug 2024 20:27:27 +0900 Subject: [PATCH 276/307] =?UTF-8?q?[refactor]=20SupportRequest=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81=EC=97=90=20=EB=A7=9E=EA=B2=8C=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/supportinfo/converter/SupportInfoConverter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index d06abcc6..5c70330b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/converter/SupportInfoConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/converter/SupportInfoConverter.java @@ -1,6 +1,6 @@ package com.bbteam.budgetbuddies.domain.supportinfo.converter; -import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequestDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequest; import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; import org.springframework.stereotype.Service; @@ -30,7 +30,7 @@ public SupportResponseDto toDto(SupportInfo entity) { * @param requestDto * @return entity */ - public SupportInfo toEntity(SupportRequestDto requestDto) { + public SupportInfo toEntity(SupportRequest.RegisterDto requestDto) { return SupportInfo.builder() .title(requestDto.getTitle()) From ed2f5a7c9759485c9d1fcc9509892a32f17b9d5a Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 1 Aug 2024 20:27:43 +0900 Subject: [PATCH 277/307] =?UTF-8?q?[refactor]=20SupportRequest=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81=EC=97=90=20=EB=A7=9E=EA=B2=8C=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/supportinfo/service/SupportInfoServiceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java index fe5214df..0c360ecf 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java @@ -1,7 +1,7 @@ package com.bbteam.budgetbuddies.domain.supportinfo.service; import com.bbteam.budgetbuddies.domain.supportinfo.converter.SupportInfoConverter; -import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequestDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequest; import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; import com.bbteam.budgetbuddies.domain.supportinfo.repository.SupportInfoRepository; @@ -103,7 +103,7 @@ void getSupportsByYearAndMonthTest() { @DisplayName("지원 정보 등록이 정상적으로 되는지 검증") void registerSupportInfoTest() { // given - SupportRequestDto requestDto = SupportRequestDto.builder() + SupportRequest.RegisterDto requestDto = SupportRequest.RegisterDto.builder() .title("지원 정보 제목") .startDate(LocalDate.of(2024, 7, 1)) .endDate(LocalDate.of(2024, 7, 21)) From 667692815ba2c5e10f5ea2be0e12ae76a087fd51 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Thu, 1 Aug 2024 23:19:09 +0900 Subject: [PATCH 278/307] =?UTF-8?q?[fix]=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/supportinfo/service/SupportInfoServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index aecff710..86a781b0 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java @@ -130,7 +130,7 @@ public SupportResponseDto updateSupportInfo(Long userId, SupportRequest.UpdateDt .orElseThrow(() -> new IllegalArgumentException("User not found")); SupportInfo supportInfo = supportInfoRepository.findById(supportRequestDto.getId()) - .orElseThrow(() -> new IllegalArgumentException("DiscountInfo not found")); + .orElseThrow(() -> new IllegalArgumentException("SupportInfo not found")); supportInfo.update(supportRequestDto); // 변경사항 업데이트 From 4a8d77d33dcce197e8bf69dd28f1b83cdef74648 Mon Sep 17 00:00:00 2001 From: MJJ Date: Fri, 2 Aug 2024 20:18:46 +0900 Subject: [PATCH 279/307] =?UTF-8?q?[feat]=20=EB=98=90=EB=9E=98=EB=93=A4?= =?UTF-8?q?=EC=9D=B4=20=EA=B0=80=EC=9E=A5=20=EB=A7=8E=EC=9D=B4=ED=95=9C=20?= =?UTF-8?q?=EC=86=8C=EB=B9=84=20top3=20=EC=A1=B0=ED=9A=8C=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/TopConsumptionResponseDTO.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopConsumptionResponseDTO.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopConsumptionResponseDTO.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopConsumptionResponseDTO.java new file mode 100644 index 00000000..2282c163 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopConsumptionResponseDTO.java @@ -0,0 +1,17 @@ +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 TopConsumptionResponseDTO { + + private String category; + + private Long consumeAmount; +} From b6ecc2b9bdd8b571a7a7650ba14d414710c62152 Mon Sep 17 00:00:00 2001 From: MJJ Date: Fri, 2 Aug 2024 20:21:07 +0900 Subject: [PATCH 280/307] =?UTF-8?q?[feat]=20=EB=98=90=EB=9E=98=EB=93=A4?= =?UTF-8?q?=EC=9D=B4=20=EA=B0=80=EC=9E=A5=20=EB=A7=8E=EC=9D=B4=ED=95=9C=20?= =?UTF-8?q?=EC=86=8C=EB=B9=84=20top3=20=EC=A1=B0=ED=9A=8C=20converter=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/TopConsumptionConverter.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopConsumptionConverter.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopConsumptionConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopConsumptionConverter.java new file mode 100644 index 00000000..976ce898 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopConsumptionConverter.java @@ -0,0 +1,17 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.converter; + +import org.springframework.stereotype.Component; + +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopConsumptionResponseDTO; +import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; + +@Component +public class TopConsumptionConverter { + public static TopConsumptionResponseDTO fromEntity(ConsumptionGoal consumptionGoal) { + + return TopConsumptionResponseDTO.builder() + .category(consumptionGoal.getCategory().getName()) + .consumeAmount(consumptionGoal.getConsumeAmount()) + .build(); + } +} From c94aca850152392ca5bf4669103c904b82d2d76f Mon Sep 17 00:00:00 2001 From: MJJ Date: Fri, 2 Aug 2024 20:21:13 +0900 Subject: [PATCH 281/307] =?UTF-8?q?[feat]=20=EB=98=90=EB=9E=98=EB=93=A4?= =?UTF-8?q?=EC=9D=B4=20=EA=B0=80=EC=9E=A5=20=EB=A7=8E=EC=9D=B4=ED=95=9C=20?= =?UTF-8?q?=EC=86=8C=EB=B9=84=20top3=20=EC=A1=B0=ED=9A=8C=20service=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalService.java | 5 ++++ .../service/ConsumptionGoalServiceImpl.java | 25 +++++++++++++++---- 2 files changed, 25 insertions(+), 5 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 1114920e..cd9a923c 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 @@ -9,6 +9,7 @@ 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.TopConsumptionResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; @Service @@ -25,5 +26,9 @@ ConsumptionGoalResponseListDto updateConsumptionGoals(Long userId, ConsumptionGoalListRequestDto consumptionGoalListRequestDto); ConsumptionAnalysisResponseDTO getTopCategoryAndConsumptionAmount(Long userId); + void updateConsumeAmount(Long userId, Long categoryId, Long amount); + + List getTopConsumption(int top, Long userId, int peerAgeS, int peerAgeE, + String peerG); } \ 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 e1cd675c..82ca25a3 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,12 +19,14 @@ 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.converter.TopConsumptionConverter; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionAnalysisResponseDTO; 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; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopConsumptionResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; import com.bbteam.budgetbuddies.domain.consumptiongoal.repository.ConsumptionGoalRepository; @@ -84,7 +86,8 @@ public ConsumptionAnalysisResponseDTO getTopCategoryAndConsumptionAmount(Long us ConsumptionGoal currentWeekConsumptionAmount = consumptionGoalRepository.findTopConsumptionByCategoryIdAndCurrentWeek( topConsumptionGoal.getCategory().getId(), startOfWeek, endOfWeek) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new IllegalArgumentException("카테고리 ID " + + topConsumptionGoal.getCategory().getId() + "에 대한 현재 주 소비 데이터가 없습니다.")); Long totalConsumptionAmountForCurrentWeek = currentWeekConsumptionAmount.getConsumeAmount(); @@ -216,17 +219,29 @@ private void updateGoalMap(Long userId, LocalDate month, Map new IllegalArgumentException("Not found user")); + .orElseThrow(() -> new IllegalArgumentException("Not found user")); Category category = categoryRepository.findById(categoryId) - .orElseThrow(() -> new IllegalArgumentException("Not found Category")); + .orElseThrow(() -> new IllegalArgumentException("Not found Category")); LocalDate thisMonth = LocalDate.now().withDayOfMonth(1); ConsumptionGoal consumptionGoal = consumptionGoalRepository - .findConsumptionGoalByUserAndCategoryAndGoalMonth(user, category, thisMonth) - .orElseGet(() -> generateConsumptionGoal(user, category, thisMonth)); + .findConsumptionGoalByUserAndCategoryAndGoalMonth(user, category, thisMonth) + .orElseGet(() -> generateConsumptionGoal(user, category, thisMonth)); consumptionGoal.updateConsumeAmount(amount); consumptionGoalRepository.save(consumptionGoal); } + + @Override + public List getTopConsumption(int top, Long userId, int peerAgeS, int peerAgeE, + String peerG) { + + checkPeerInfo(userId, peerAgeS, peerAgeE, peerG); + + List topConsumptions = consumptionGoalRepository.findTopConsumptionAndConsumeAmount(top, + peerAgeStart, + peerAgeEnd, peerGender); + return topConsumptions.stream().map(TopConsumptionConverter::fromEntity).collect(Collectors.toList()); + } } From 2de6a3c46957f81fd224454ceab1b71408b47bc6 Mon Sep 17 00:00:00 2001 From: MJJ Date: Fri, 2 Aug 2024 20:21:23 +0900 Subject: [PATCH 282/307] =?UTF-8?q?[feat]=20=EB=98=90=EB=9E=98=EB=93=A4?= =?UTF-8?q?=EC=9D=B4=20=EA=B0=80=EC=9E=A5=20=EB=A7=8E=EC=9D=B4=ED=95=9C=20?= =?UTF-8?q?=EC=86=8C=EB=B9=84=20top3=20=EC=A1=B0=ED=9A=8C=20repository=20?= =?UTF-8?q?=EA=B5=AC=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 972a8c7c..a5444e5f 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 @@ -33,4 +33,10 @@ Optional findConsumptionGoalByUserAndCategoryAndGoalMonth(User + "BETWEEN :startOfWeek AND :endOfWeek ORDER BY cg.consumeAmount DESC limit 1") Optional findTopConsumptionByCategoryIdAndCurrentWeek(@Param("categoryId") Long categoryId, @Param("startOfWeek") LocalDate startOfWeek, @Param("endOfWeek") LocalDate endOfWeek); + + @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.consumeAmount DESC limit :top") + List findTopConsumptionAndConsumeAmount(@Param("top") int top, @Param("peerAgeStart") int peerAgeStart, + @Param("peerAgeEnd") int peerAgeEnd, @Param("peerGender") Gender peerGender); } \ No newline at end of file From c72363c2fa0753d97312352905f92e5d13fdd736 Mon Sep 17 00:00:00 2001 From: MJJ Date: Fri, 2 Aug 2024 20:21:33 +0900 Subject: [PATCH 283/307] =?UTF-8?q?[feat]=20=EB=98=90=EB=9E=98=EB=93=A4?= =?UTF-8?q?=EC=9D=B4=20=EA=B0=80=EC=9E=A5=20=EB=A7=8E=EC=9D=B4=ED=95=9C=20?= =?UTF-8?q?=EC=86=8C=EB=B9=84=20top3=20=EC=A1=B0=ED=9A=8C=20controller=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= 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 1cf418c1..24d4d454 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 @@ -17,6 +17,7 @@ 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.TopConsumptionResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.service.ConsumptionGoalService; @@ -71,4 +72,15 @@ public ResponseEntity updateOrElseGenerateConsum return ResponseEntity.ok() .body(consumptionGoalService.updateConsumptionGoals(userId, consumptionGoalListRequestDto)); } + + @GetMapping("/top-consumption") + public ResponseEntity getConsumptionGoal(@RequestParam(name = "top", defaultValue = "3") 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 response = consumptionGoalService.getTopConsumption(top, userId, + peerAgeStart, peerAgeEnd, peerGender); + return ResponseEntity.ok(response); + } } \ No newline at end of file From 74db37d0be28535b0c74e3c8392619f44b37666a Mon Sep 17 00:00:00 2001 From: MJJ Date: Fri, 2 Aug 2024 20:26:11 +0900 Subject: [PATCH 284/307] =?UTF-8?q?[fix]=20=EB=98=90=EB=9E=98=EB=93=A4?= =?UTF-8?q?=EC=9D=B4=20=EA=B0=80=EC=9E=A5=20=EB=A7=8E=EC=9D=B4=ED=95=9C=20?= =?UTF-8?q?=EC=86=8C=EB=B9=84=20=EA=B8=B0=EB=B3=B8=20top=203=20->=205?= 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 24d4d454..639828e2 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 @@ -74,7 +74,7 @@ public ResponseEntity updateOrElseGenerateConsum } @GetMapping("/top-consumption") - public ResponseEntity getConsumptionGoal(@RequestParam(name = "top", defaultValue = "3") int top, + public ResponseEntity getConsumptionGoal(@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, From 328174e61cab17f50554fe86a825878a20ac757d Mon Sep 17 00:00:00 2001 From: MJJ Date: Fri, 2 Aug 2024 20:26:57 +0900 Subject: [PATCH 285/307] =?UTF-8?q?[feat]=20=EB=98=90=EB=9E=98=EB=93=A4?= =?UTF-8?q?=EC=9D=B4=20=EA=B0=80=EC=9E=A5=20=EB=A7=8E=EC=9D=B4=ED=95=9C=20?= =?UTF-8?q?=EC=86=8C=EB=B9=84=20=EC=A1=B0=ED=9A=8C=20swagger=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/controller/ConsumptionGoalApi.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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 index 4e739a8a..3a8c2f7b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalApi.java @@ -46,4 +46,12 @@ ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaultValue ResponseEntity updateOrElseGenerateConsumptionGoal(Long userId, ConsumptionGoalListRequestDto consumptionGoalListRequestDto); + @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 getConsumptionGoal(int top, Long userId, int peerAgeStart, int peerAgeEnd, String peerGender); } From 981a06e37810cc6bad5cdc2366ad829ddb243727 Mon Sep 17 00:00:00 2001 From: MJJ Date: Fri, 2 Aug 2024 20:35:39 +0900 Subject: [PATCH 286/307] =?UTF-8?q?[fix]=20ConsumptionGoalController=20?= =?UTF-8?q?=EC=97=94=EB=93=9C=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ConsumptionGoalController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 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 639828e2..76609073 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 @@ -30,7 +30,7 @@ public class ConsumptionGoalController implements ConsumptionGoalApi { private final ConsumptionGoalService consumptionGoalService; - @GetMapping("/top-categories") + @GetMapping("/top-categories/top-goal") public ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaultValue = "5") int top, @RequestParam(name = "userId") Long userId, @RequestParam(name = "peerAgeStart", defaultValue = "0") int peerAgeStart, @@ -41,7 +41,7 @@ public ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaul return ResponseEntity.ok(topCategory); } - @GetMapping("/top-category") + @GetMapping("/top-category/top-goal") public ResponseEntity getTopGoalCategory(@RequestParam(name = "userId") Long userId) { ConsumptionAnalysisResponseDTO response = consumptionGoalService.getTopCategoryAndConsumptionAmount(userId); return ResponseEntity.ok(response); @@ -73,7 +73,7 @@ public ResponseEntity updateOrElseGenerateConsum .body(consumptionGoalService.updateConsumptionGoals(userId, consumptionGoalListRequestDto)); } - @GetMapping("/top-consumption") + @GetMapping("/top-categories/top-consumption") public ResponseEntity getConsumptionGoal(@RequestParam(name = "top", defaultValue = "5") int top, @RequestParam(name = "userId") Long userId, @RequestParam(name = "peerAgeStart", defaultValue = "0") int peerAgeStart, From 192c35e839b663550d87188028574f0ae85d7c13 Mon Sep 17 00:00:00 2001 From: MJJ Date: Fri, 2 Aug 2024 21:25:12 +0900 Subject: [PATCH 287/307] =?UTF-8?q?[fix]=20categoryName=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 --- .../consumptiongoal/converter/TopConsumptionConverter.java | 2 +- .../domain/consumptiongoal/dto/TopConsumptionResponseDTO.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopConsumptionConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopConsumptionConverter.java index 976ce898..9f37e9c1 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopConsumptionConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopConsumptionConverter.java @@ -10,7 +10,7 @@ public class TopConsumptionConverter { public static TopConsumptionResponseDTO fromEntity(ConsumptionGoal consumptionGoal) { return TopConsumptionResponseDTO.builder() - .category(consumptionGoal.getCategory().getName()) + .categoryName(consumptionGoal.getCategory().getName()) .consumeAmount(consumptionGoal.getConsumeAmount()) .build(); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopConsumptionResponseDTO.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopConsumptionResponseDTO.java index 2282c163..e6041e2b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopConsumptionResponseDTO.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopConsumptionResponseDTO.java @@ -11,7 +11,7 @@ @AllArgsConstructor public class TopConsumptionResponseDTO { - private String category; + private String categoryName; private Long consumeAmount; } From 9a77990c59bb9c56290a2dc2c9ebe54a76b81002 Mon Sep 17 00:00:00 2001 From: MJJ Date: Fri, 2 Aug 2024 21:26:32 +0900 Subject: [PATCH 288/307] =?UTF-8?q?[test]=20=EB=98=90=EB=9E=98=EB=93=A4?= =?UTF-8?q?=EC=9D=B4=20=EA=B0=80=EC=9E=A5=20=EB=A7=8E=EC=9D=B4=20=EC=86=8C?= =?UTF-8?q?=EB=B9=84=ED=95=9C=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=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalServiceTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) 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 2e09a47d..109c474b 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 @@ -31,6 +31,7 @@ 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.TopConsumptionResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; import com.bbteam.budgetbuddies.domain.consumptiongoal.repository.ConsumptionGoalRepository; @@ -385,4 +386,53 @@ void getTopGoalCategories_Success() { assertThat(result.get(3).getCategoryName()).isEqualTo(defaultCategory4.getName()); assertThat(result.get(3).getGoalAmount()).isEqualTo(topConsumptionGoal4.getGoalAmount()); } + + @Test + @DisplayName("getTopConsumption : 또래들이 가장 많이 소비한 카테고리 top3 조회 성공") + void getTopConsumptionCategories_Success() { + // given + Category defaultCategory = Mockito.spy(Category.builder().name("디폴트 카테고리").user(null).isDefault(true).build()); + Category defaultCategory2 = Mockito.spy(Category.builder().name("디폴트 카테고리2").user(null).isDefault(true).build()); + Category defaultCategory3 = Mockito.spy(Category.builder().name("디폴트 카테고리3").user(null).isDefault(true).build()); + + ConsumptionGoal topConsumptionGoal1 = ConsumptionGoal.builder() + .goalAmount(5000L) + .consumeAmount(3000L) + .user(user) + .category(defaultCategory) + .goalMonth(goalMonthRandomDay) + .build(); + + ConsumptionGoal topConsumptionGoal2 = ConsumptionGoal.builder() + .goalAmount(6000L) + .consumeAmount(3000L) + .user(user) + .category(defaultCategory2) + .goalMonth(goalMonthRandomDay) + .build(); + + ConsumptionGoal topConsumptionGoal3 = ConsumptionGoal.builder() + .goalAmount(7000L) + .consumeAmount(3000L) + .user(user) + .category(defaultCategory3) + .goalMonth(goalMonthRandomDay) + .build(); + + given(userRepository.findById(user.getId())).willReturn(Optional.of(user)); + given(consumptionGoalRepository.findTopConsumptionAndConsumeAmount(3, 23, 25, Gender.MALE)).willReturn( + List.of(topConsumptionGoal1, topConsumptionGoal2, topConsumptionGoal3)); + + // when + List result = consumptionGoalService.getTopConsumption(3, user.getId(), 23, 25, "MALE"); + + // then + assertThat(result).hasSize(3); + assertThat(result.get(0).getCategoryName()).isEqualTo(defaultCategory.getName()); + assertThat(result.get(0).getConsumeAmount()).isEqualTo(topConsumptionGoal1.getConsumeAmount()); + assertThat(result.get(1).getCategoryName()).isEqualTo(defaultCategory2.getName()); + assertThat(result.get(1).getConsumeAmount()).isEqualTo(topConsumptionGoal2.getConsumeAmount()); + assertThat(result.get(2).getCategoryName()).isEqualTo(defaultCategory3.getName()); + assertThat(result.get(2).getConsumeAmount()).isEqualTo(topConsumptionGoal3.getConsumeAmount()); + } } \ No newline at end of file From 88d37b9a5195c0752ac271b7def0c0dfdef4f112 Mon Sep 17 00:00:00 2001 From: MJJ Date: Fri, 2 Aug 2024 21:27:08 +0900 Subject: [PATCH 289/307] =?UTF-8?q?[test]=20=EB=98=90=EB=9E=98=EB=93=A4?= =?UTF-8?q?=EC=9D=B4=20=EA=B0=80=EC=9E=A5=20=EB=A7=8E=EC=9D=B4=20=EC=86=8C?= =?UTF-8?q?=EB=B9=84=ED=95=9C=20=EC=86=8C=EB=B9=84=EB=AA=A9=ED=91=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConsumptionGoalRepositoryTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) 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 13deca84..dc5e29e7 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 @@ -188,4 +188,48 @@ private void setUnselectedConsumptionGoal(User mainUser, LocalDate goalMonth, Ca .category(defaultCategory) .build()); } + + @Test + @DisplayName("또래 나이와 성별 정보를 통해 GoalConsumption 조회 성공") + void findTopConsumptionAndConsumeAmount_Success() { + //given + User mainUser = userRepository.save( + User.builder() + .email("email") + .age(24) + .name("name") + .gender(Gender.MALE) + .phoneNumber("010-1234-5678") + .build()); + + Category defaultCategory = categoryRepository.save( + Category.builder().name("디폴트 카테고리").user(null).isDefault(true).build()); + + LocalDate goalMonth = LocalDate.of(2024, 07, 01); + + ConsumptionGoal defaultCategoryConsumptionGoal = consumptionGoalRepository.save(ConsumptionGoal.builder() + .goalAmount(1L) + .consumeAmount(1L) + .user(mainUser) + .goalMonth(goalMonth) + .category(defaultCategory) + .build()); + + // when + int top = 4; + int peerAgeStart = 23; + int peerAgeEnd = 25; + Gender peerGender = Gender.MALE; + + List result = consumptionGoalRepository.findTopConsumptionAndConsumeAmount( + top, peerAgeStart, peerAgeEnd, peerGender); + + // then + ConsumptionGoal resultGoal = result.get(0); + assertThat(resultGoal.getGoalAmount()).isEqualTo(1L); + assertThat(resultGoal.getConsumeAmount()).isEqualTo(1L); + assertThat(resultGoal.getUser().getAge()).isEqualTo(24); + assertThat(resultGoal.getCategory().getName()).isEqualTo("디폴트 카테고리"); + assertThat(resultGoal.getUser().getGender()).isEqualTo(Gender.MALE); + } } \ No newline at end of file From d15199fe3a4483700267228cf25130fb3c5a5318 Mon Sep 17 00:00:00 2001 From: JunRain Date: Sat, 3 Aug 2024 14:59:20 +0900 Subject: [PATCH 290/307] =?UTF-8?q?[feat]=20Expense=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EC=86=8C=EB=B9=84=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/expense/entity/Expense.java | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/entity/Expense.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/entity/Expense.java index 814aad79..254059ee 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/entity/Expense.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/entity/Expense.java @@ -1,18 +1,23 @@ package com.bbteam.budgetbuddies.domain.expense.entity; +import java.time.LocalDateTime; + import com.bbteam.budgetbuddies.common.BaseEntity; import com.bbteam.budgetbuddies.domain.category.entity.Category; +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseUpdateRequestDto; 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; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; -import org.hibernate.annotations.Where; - -import java.time.LocalDateTime; @Entity @Getter @@ -21,20 +26,25 @@ @SuperBuilder public class Expense extends BaseEntity { - @Column(nullable = false) - @Min(value = 1, message = "0 또는 음수의 비용을 지출할 수 없습니다.") - private Long amount; + @Column(nullable = false) + @Min(value = 1, message = "0 또는 음수의 비용을 지출할 수 없습니다.") + private Long amount; - private String description; + private String description; - private LocalDateTime expenseDate; + private LocalDateTime expenseDate; - @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; + public void updateExpenseFromRequest(ExpenseUpdateRequestDto request, Category category) { + this.amount = request.getAmount(); + this.expenseDate = request.getExpenseDate(); + this.category = category; + } } From af87de69ba2af1bb871bcfcc55d06cb8b47c7b0d Mon Sep 17 00:00:00 2001 From: JunRain Date: Sat, 3 Aug 2024 15:00:19 +0900 Subject: [PATCH 291/307] =?UTF-8?q?[feat]=20ExpenseService=20Expense=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=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 --- .../expense/service/ExpenseService.java | 3 ++ .../expense/service/ExpenseServiceImpl.java | 30 ++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) 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 773e59bc..4bd0d69e 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 @@ -6,6 +6,7 @@ import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseRequestDto; import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseUpdateRequestDto; import com.bbteam.budgetbuddies.domain.expense.dto.MonthlyExpenseCompactResponseDto; public interface ExpenseService { @@ -14,4 +15,6 @@ public interface ExpenseService { MonthlyExpenseCompactResponseDto getMonthlyExpense(Pageable pageable, Long userId, LocalDate localDate); ExpenseResponseDto findExpenseResponseFromUserIdAndExpenseId(Long userId, Long expenseId); + + ExpenseResponseDto updateExpense(Long userId, ExpenseUpdateRequestDto request); } 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 index 44f6c514..808857ef 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java @@ -9,9 +9,12 @@ import com.bbteam.budgetbuddies.domain.category.entity.Category; import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; +import com.bbteam.budgetbuddies.domain.category.service.CategoryService; +import com.bbteam.budgetbuddies.domain.consumptiongoal.service.ConsumptionGoalService; 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.dto.ExpenseUpdateRequestDto; import com.bbteam.budgetbuddies.domain.expense.dto.MonthlyExpenseCompactResponseDto; import com.bbteam.budgetbuddies.domain.expense.entity.Expense; import com.bbteam.budgetbuddies.domain.expense.repository.ExpenseRepository; @@ -27,7 +30,9 @@ public class ExpenseServiceImpl implements ExpenseService { private final ExpenseRepository expenseRepository; private final UserRepository userRepository; private final CategoryRepository categoryRepository; + private final CategoryService categoryService; private final ExpenseConverter expenseConverter; + private final ConsumptionGoalService consumptionGoalService; @Override public ExpenseResponseDto createExpense(ExpenseRequestDto expenseRequestDto) { @@ -61,13 +66,30 @@ public ExpenseResponseDto findExpenseResponseFromUserIdAndExpenseId(Long userId, Expense expense = expenseRepository.findById(expenseId) .orElseThrow(() -> new IllegalArgumentException("Not found expense")); - if (isAllowedUser(userId, expense)) - throw new IllegalArgumentException("Unauthorized user"); + checkUserAuthority(userId, expense); return expenseConverter.toExpenseResponseDto(expense); } - private boolean isAllowedUser(Long userId, Expense expense) { - return expense.getUser().getId() != userId; + private void checkUserAuthority(Long userId, Expense expense) { + if (!expense.getUser().getId().equals(userId)) + throw new IllegalArgumentException("Unauthorized user"); + } + + @Override + @Transactional + public ExpenseResponseDto updateExpense(Long userId, ExpenseUpdateRequestDto request) { + Expense expense = expenseRepository.findById(request.getExpenseId()) + .orElseThrow(() -> new IllegalArgumentException("Not found expense")); + + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("Not found user")); + checkUserAuthority(userId, expense); + + Category categoryToReplace = categoryService.handleCategoryChange(expense, request, user); + + expense.updateExpenseFromRequest(request, categoryToReplace); + + return expenseConverter.toExpenseResponseDto(expenseRepository.save(expense)); } } From 91335bf5bffccdc49fbfbad12560fd53ab0c4c94 Mon Sep 17 00:00:00 2001 From: JunRain Date: Sat, 3 Aug 2024 15:02:34 +0900 Subject: [PATCH 292/307] =?UTF-8?q?[feat]=20ExpenseService=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=8B=A4=ED=96=89=EC=8B=9C=20=EB=B3=80=EA=B2=BD=EB=90=9C=20?= =?UTF-8?q?=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../category/service/CategoryService.java | 15 ++-- .../category/service/CategoryServiceImpl.java | 71 +++++++++++-------- 2 files changed, 54 insertions(+), 32 deletions(-) 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 index 1ba8ec9c..1a15b327 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/service/CategoryService.java @@ -1,12 +1,19 @@ package com.bbteam.budgetbuddies.domain.category.service; +import java.util.List; + import com.bbteam.budgetbuddies.domain.category.dto.CategoryRequestDTO; import com.bbteam.budgetbuddies.domain.category.dto.CategoryResponseDTO; - -import java.util.List; +import com.bbteam.budgetbuddies.domain.category.entity.Category; +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseUpdateRequestDto; +import com.bbteam.budgetbuddies.domain.expense.entity.Expense; +import com.bbteam.budgetbuddies.domain.user.entity.User; public interface CategoryService { - CategoryResponseDTO createCategory(CategoryRequestDTO categoryRequestDTO); - List getUserCategories(Long userId); + CategoryResponseDTO createCategory(CategoryRequestDTO categoryRequestDTO); + + List getUserCategories(Long userId); + + Category handleCategoryChange(Expense expense, ExpenseUpdateRequestDto request, User user); } 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 2df03410..2c2f314a 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 @@ -1,53 +1,68 @@ package com.bbteam.budgetbuddies.domain.category.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.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.consumptiongoal.service.ConsumptionGoalService; +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseUpdateRequestDto; +import com.bbteam.budgetbuddies.domain.expense.entity.Expense; 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.List; -import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; @Service @RequiredArgsConstructor @Transactional public class CategoryServiceImpl implements CategoryService { - private final CategoryRepository categoryRepository; - private final UserRepository userRepository; - private final CategoryConverter categoryConverter; + private final CategoryRepository categoryRepository; + private final ConsumptionGoalService consumptionGoalService; + private final UserRepository userRepository; + private final CategoryConverter categoryConverter; + + @Override + public CategoryResponseDTO createCategory(CategoryRequestDTO categoryRequestDTO) { + User user = userRepository.findById(categoryRequestDTO.getUserId()) + .orElseThrow(() -> new IllegalArgumentException("cannot find 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); - @Override - public CategoryResponseDTO createCategory(CategoryRequestDTO categoryRequestDTO) { - User user = userRepository.findById(categoryRequestDTO.getUserId()) - .orElseThrow(() -> new IllegalArgumentException("cannot find user")); + return categoryConverter.toCategoryResponseDTO(savedCategory); + } - if (categoryRepository.existsByUserIdAndName(categoryRequestDTO.getUserId(), categoryRequestDTO.getName())) { - throw new IllegalArgumentException("User already has a category with the same name"); - } + @Override + public List getUserCategories(Long userId) { + userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found with id: " + userId)); - Category category = categoryConverter.toCategoryEntity(categoryRequestDTO, user); - Category savedCategory = categoryRepository.save(category); + List categories = categoryRepository.findUserCategoryByUserId(userId); + return categories.stream().map(categoryConverter::toCategoryResponseDTO).collect(Collectors.toList()); + } - return categoryConverter.toCategoryResponseDTO(savedCategory); - } + @Override + @Transactional(readOnly = true) + public Category handleCategoryChange(Expense expense, ExpenseUpdateRequestDto request, User user) { + Category categoryToReplace = categoryRepository.findById(request.getCategoryId()) + .orElseThrow(() -> new IllegalArgumentException("Not found category")); - @Override - public List getUserCategories(Long userId) { + consumptionGoalService.recalculateConsumptionAmount(expense, request, user); - userRepository.findById(userId) - .orElseThrow(() -> new IllegalArgumentException("User not found with id: " + userId)); + return categoryToReplace; + } - List categories = categoryRepository.findUserCategoryByUserId(userId); - return categories.stream() - .map(categoryConverter::toCategoryResponseDTO) - .collect(Collectors.toList()); - } } \ No newline at end of file From b6cd4e571d543c6b20ac04adca44752477637513 Mon Sep 17 00:00:00 2001 From: JunRain Date: Sat, 3 Aug 2024 15:04:20 +0900 Subject: [PATCH 293/307] =?UTF-8?q?[feat]=20ConsumptionGoal=20Expense?= =?UTF-8?q?=EC=9D=98=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=EC=86=8C?= =?UTF-8?q?=EB=B9=84=20=EA=B8=88=EC=95=A1=20=EA=B3=84=EC=82=B0=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EB=A9=94=EC=84=9C=EB=93=9C=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 --- .../domain/consumptiongoal/entity/ConsumptionGoal.java | 8 ++++++++ 1 file changed, 8 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 a0df97bc..b9af57d0 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 @@ -47,4 +47,12 @@ public class ConsumptionGoal extends BaseEntity { public void updateGoalAmount(Long goalAmount) { this.goalAmount = goalAmount; } + + public void restoreConsumeAmount(Long previousAmount) { + this.consumeAmount -= previousAmount; + } + + public void consume(Long amount) { + this.consumeAmount += amount; + } } From d1d2d2854dc5de0aa3ab9f9d47f8216ff871bbae Mon Sep 17 00:00:00 2001 From: JunRain Date: Sat, 3 Aug 2024 15:07:13 +0900 Subject: [PATCH 294/307] =?UTF-8?q?[feat]=20Expense=EC=9D=98=20=EC=86=8C?= =?UTF-8?q?=EB=B9=84=EA=B8=88=EC=95=A1=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EC=9D=B8=ED=95=9C=20=EC=86=8C=EB=B9=84=EB=AA=A9?= =?UTF-8?q?=ED=91=9C=EC=9D=98=20=EC=86=8C=EB=B9=84=EA=B8=88=EC=95=A1=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=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 --- .../service/ConsumptionGoalService.java | 7 +- .../service/ConsumptionGoalServiceImpl.java | 70 ++++++++++++++++--- 2 files changed, 68 insertions(+), 9 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 cb4d297b..9416f0f9 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 @@ -10,6 +10,9 @@ 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.expense.dto.ExpenseUpdateRequestDto; +import com.bbteam.budgetbuddies.domain.expense.entity.Expense; +import com.bbteam.budgetbuddies.domain.user.entity.User; @Service public interface ConsumptionGoalService { @@ -17,7 +20,7 @@ public interface ConsumptionGoalService { List getTopGoalCategories(int top, Long userId, int peerAgeStart, int peerAgeEnd, String peerGender); - ConsumptionGoalResponseListDto findUserConsumptionGoal(Long userId, LocalDate date); + ConsumptionGoalResponseListDto findUserConsumptionGoalList(Long userId, LocalDate date); PeerInfoResponseDTO getPeerInfo(Long userId, int peerAgeStart, int peerAgeEnd, String peerGender); @@ -25,4 +28,6 @@ ConsumptionGoalResponseListDto updateConsumptionGoals(Long userId, ConsumptionGoalListRequestDto consumptionGoalListRequestDto); ConsumptionAnalysisResponseDTO getTopCategoryAndConsumptionAmount(Long userId); + + void recalculateConsumptionAmount(Expense expense, ExpenseUpdateRequestDto request, User user); } \ 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 4afa9f99..27115930 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 @@ -28,6 +28,8 @@ 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.expense.dto.ExpenseUpdateRequestDto; +import com.bbteam.budgetbuddies.domain.expense.entity.Expense; import com.bbteam.budgetbuddies.domain.user.entity.User; import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; import com.bbteam.budgetbuddies.enums.Gender; @@ -174,18 +176,24 @@ private ConsumptionGoal updateConsumptionGoalWithRequestDto(User user, private ConsumptionGoal findOrElseGenerateConsumptionGoal(User user, Category category, LocalDate goalMonth) { return consumptionGoalRepository.findConsumptionGoalByUserAndCategoryAndGoalMonth(user, category, goalMonth) - .orElseGet(() -> generateConsumptionGoal(user, category, goalMonth)); + .orElseGet(() -> generateNewConsumptionGoal(user, category, goalMonth)); } - private ConsumptionGoal generateConsumptionGoal(User user, Category category, LocalDate goalMonth) { - return ConsumptionGoal.builder().goalMonth(goalMonth).user(user).category(category).consumeAmount(0L).build(); + private ConsumptionGoal generateNewConsumptionGoal(User user, Category category, LocalDate goalMonth) { + return ConsumptionGoal.builder() + .goalMonth(goalMonth) + .user(user) + .category(category) + .consumeAmount(0L) + .goalAmount(0L) + .build(); } @Override @Transactional(readOnly = true) - public ConsumptionGoalResponseListDto findUserConsumptionGoal(Long userId, LocalDate date) { + public ConsumptionGoalResponseListDto findUserConsumptionGoalList(Long userId, LocalDate date) { LocalDate goalMonth = date.withDayOfMonth(1); - Map goalMap = initializeGoalMap(userId, goalMonth); + Map goalMap = initializeGoalMap(userId); updateGoalMapWithPreviousMonth(userId, goalMonth, goalMap); updateGoalMapWithCurrentMonth(userId, goalMonth, goalMap); @@ -193,11 +201,10 @@ public ConsumptionGoalResponseListDto findUserConsumptionGoal(Long userId, Local return consumptionGoalConverter.toConsumptionGoalResponseListDto(new ArrayList<>(goalMap.values()), goalMonth); } - private Map initializeGoalMap(Long userId, LocalDate goalMonth) { + private Map initializeGoalMap(Long userId) { return categoryRepository.findUserCategoryByUserId(userId) .stream() - .collect(Collectors.toMap(Category::getId, - category -> consumptionGoalConverter.toConsumptionGoalResponseDto(category))); + .collect(Collectors.toMap(Category::getId, consumptionGoalConverter::toConsumptionGoalResponseDto)); } private void updateGoalMapWithPreviousMonth(Long userId, LocalDate goalMonth, @@ -216,4 +223,51 @@ private void updateGoalMap(Long userId, LocalDate month, Map goalMap.put(goal.getCategoryId(), goal)); } + + @Override + @Transactional + public void recalculateConsumptionAmount(Expense expense, ExpenseUpdateRequestDto request, User user) { + restorePreviousGoalConsumptionAmount(expense, user); + calculatePresentGoalConsumptionAmount(request, user); + } + + private void restorePreviousGoalConsumptionAmount(Expense expense, User user) { + ConsumptionGoal previousConsumptionGoal = consumptionGoalRepository.findConsumptionGoalByUserAndCategoryAndGoalMonth( + user, expense.getCategory(), expense.getExpenseDate().toLocalDate().withDayOfMonth(1)) + .orElseThrow(() -> new IllegalArgumentException("Not found consumptionGoal")); + + previousConsumptionGoal.restoreConsumeAmount(expense.getAmount()); + consumptionGoalRepository.save(previousConsumptionGoal); + } + + private void calculatePresentGoalConsumptionAmount(ExpenseUpdateRequestDto request, User user) { + Category categoryToReplace = categoryRepository.findById(request.getCategoryId()) + .orElseThrow(() -> new IllegalArgumentException("Not found category")); + + ConsumptionGoal consumptionGoal = consumptionGoalRepository.findConsumptionGoalByUserAndCategoryAndGoalMonth( + user, categoryToReplace, request.getExpenseDate().toLocalDate().withDayOfMonth(1)) + .orElseGet(() -> this.generateGoalByPreviousOrElseNew(user, categoryToReplace, + request.getExpenseDate().toLocalDate().withDayOfMonth(1))); + + consumptionGoal.consume(request.getAmount()); + consumptionGoalRepository.save(consumptionGoal); + } + + private ConsumptionGoal generateGoalByPreviousOrElseNew(User user, Category category, LocalDate goalMonth) { + LocalDate previousMonth = goalMonth.minusMonths(1); + + return consumptionGoalRepository.findConsumptionGoalByUserAndCategoryAndGoalMonth(user, category, previousMonth) + .map(this::generateGoalByPrevious) + .orElseGet(() -> generateNewConsumptionGoal(user, category, goalMonth)); + } + + private ConsumptionGoal generateGoalByPrevious(ConsumptionGoal consumptionGoal) { + return ConsumptionGoal.builder() + .goalMonth(consumptionGoal.getGoalMonth().plusMonths(1)) + .user(consumptionGoal.getUser()) + .category(consumptionGoal.getCategory()) + .consumeAmount(0L) + .goalAmount(consumptionGoal.getGoalAmount()) + .build(); + } } From d68ff58fb6353e5d3ecc5ee74225af0446369c24 Mon Sep 17 00:00:00 2001 From: JunRain Date: Sat, 3 Aug 2024 15:11:44 +0900 Subject: [PATCH 295/307] =?UTF-8?q?[feat]=20ExpenseController=20ExpenseUpd?= =?UTF-8?q?ate=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/expense/controller/ExpenseApi.java | 8 ++++++++ .../expense/controller/ExpenseController.java | 13 ++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java index 3db10871..0db91b3b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java @@ -6,9 +6,13 @@ import org.springframework.data.repository.query.Param; 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 com.bbteam.budgetbuddies.domain.expense.dto.ExpenseRequestDto; import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseUpdateRequestDto; import com.bbteam.budgetbuddies.domain.expense.dto.MonthlyExpenseCompactResponseDto; import io.swagger.v3.oas.annotations.Operation; @@ -45,4 +49,8 @@ ResponseEntity findExpensesForMonth(Pageable p @ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class)))}) @GetMapping("/{userId}/{expenseId}") ResponseEntity findExpense(@Param("userId") Long userId, @Param("expenseId") Long expenseId); + + @PostMapping("/{userId}") + ResponseEntity updateExpense(@PathVariable @Param("userId") Long userId, + @RequestBody ExpenseUpdateRequestDto request); } 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 index 3321950b..c9ce1519 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java @@ -16,6 +16,7 @@ import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseRequestDto; import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseResponseDto; +import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseUpdateRequestDto; import com.bbteam.budgetbuddies.domain.expense.dto.MonthlyExpenseCompactResponseDto; import com.bbteam.budgetbuddies.domain.expense.service.ExpenseService; @@ -47,8 +48,18 @@ public ResponseEntity findExpensesForMonth(Pag @Override @GetMapping("/{userId}/{expenseId}") - public ResponseEntity findExpense(@PathVariable Long userId, @PathVariable Long expenseId) { + public ResponseEntity findExpense(@PathVariable @Param("userId") Long userId, + @PathVariable @Param("expenseId") Long expenseId) { return ResponseEntity.ok(expenseService.findExpenseResponseFromUserIdAndExpenseId(userId, expenseId)); } + + @Override + @PostMapping("/{userId}") + public ResponseEntity updateExpense(@PathVariable @Param("userId") Long userId, + @RequestBody ExpenseUpdateRequestDto request) { + ExpenseResponseDto response = expenseService.updateExpense(userId, request); + + return ResponseEntity.ok(response); + } } From 3115d4686d3970f4afe4b6efc40ad968db754bd4 Mon Sep 17 00:00:00 2001 From: JunRain Date: Sat, 3 Aug 2024 15:12:08 +0900 Subject: [PATCH 296/307] =?UTF-8?q?[fix]=20=EB=88=84=EB=9D=BD=EB=90=9C=20@?= =?UTF-8?q?Override=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 | 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 1cf418c1..077dd557 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 @@ -29,6 +29,7 @@ public class ConsumptionGoalController implements ConsumptionGoalApi { private final ConsumptionGoalService consumptionGoalService; + @Override @GetMapping("/top-categories") public ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaultValue = "5") int top, @RequestParam(name = "userId") Long userId, @@ -40,12 +41,14 @@ public ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaul return ResponseEntity.ok(topCategory); } + @Override @GetMapping("/top-category") public ResponseEntity getTopGoalCategory(@RequestParam(name = "userId") Long userId) { ConsumptionAnalysisResponseDTO response = consumptionGoalService.getTopCategoryAndConsumptionAmount(userId); return ResponseEntity.ok(response); } + @Override @GetMapping("/peer-info") public ResponseEntity getPeerInfo(@RequestParam(name = "userId") Long userId, @RequestParam(name = "peerAgeStart", defaultValue = "0") int peerAgeStart, @@ -55,15 +58,17 @@ public ResponseEntity getPeerInfo(@RequestParam(name = "userId") Long userId, return ResponseEntity.ok(response); } + @Override @GetMapping("/{userId}") public ResponseEntity findUserConsumptionGoal( @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date, @PathVariable Long userId) { - ConsumptionGoalResponseListDto response = consumptionGoalService.findUserConsumptionGoal(userId, date); + ConsumptionGoalResponseListDto response = consumptionGoalService.findUserConsumptionGoalList(userId, date); return ResponseEntity.ok(response); } + @Override @PostMapping("/{userId}") public ResponseEntity updateOrElseGenerateConsumptionGoal(@PathVariable Long userId, @RequestBody ConsumptionGoalListRequestDto consumptionGoalListRequestDto) { From bc09b99fd6402b32bfede212f084f02336d39e54 Mon Sep 17 00:00:00 2001 From: JunRain Date: Sat, 3 Aug 2024 23:59:59 +0900 Subject: [PATCH 297/307] =?UTF-8?q?[fix]=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD=EC=9C=BC=EB=A1=9C=20=EB=8B=A4?= =?UTF-8?q?=EB=A5=B8=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalServiceImpl.java | 2 +- .../domain/expense/dto/ExpenseUpdateRequestDto.java | 2 ++ .../mainpage/service/MainPageServiceImpl.java | 2 +- .../service/ConsumptionGoalServiceTest.java | 13 +++++++------ 4 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseUpdateRequestDto.java 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 27115930..04a715c2 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 @@ -24,11 +24,11 @@ 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.expense.dto.ExpenseUpdateRequestDto; 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; -import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseUpdateRequestDto; import com.bbteam.budgetbuddies.domain.expense.entity.Expense; import com.bbteam.budgetbuddies.domain.user.entity.User; import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseUpdateRequestDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseUpdateRequestDto.java new file mode 100644 index 00000000..ba4a4358 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseUpdateRequestDto.java @@ -0,0 +1,2 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.dto;public class ExpenseUpdateRequestDto { +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/service/MainPageServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/service/MainPageServiceImpl.java index 15752357..1fb55e1f 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/service/MainPageServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/service/MainPageServiceImpl.java @@ -40,7 +40,7 @@ public MainPageResponseDto getMainPage(Long userId) { } TopGoalCategoryResponseDTO topGoalCategoryResponseDTO = topGoalCategoryResponseDTOList.get(0); - ConsumptionGoalResponseListDto userConsumptionGoal = consumptionGoalService.findUserConsumptionGoal(userId, now); + ConsumptionGoalResponseListDto userConsumptionGoal = consumptionGoalService.findUserConsumptionGoalList(userId, now); return MainPageConverter.toMainPageResponseDto(discountResponseDtoList, supportResponseDtoList, topGoalCategoryResponseDTO, userConsumptionGoal); 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 23601804..9349c68b 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 @@ -91,7 +91,7 @@ void findUserConsumptionGoal_onlyCategory() { .toList(); // when - ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoal(user.getId(), + ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoalList(user.getId(), goalMonthRandomDay); // then @@ -138,7 +138,7 @@ void findUserConsumptionGoal_previousMonth() { .toList(); // when - ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoal(user.getId(), + ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoalList(user.getId(), goalMonthRandomDay); // then @@ -175,7 +175,7 @@ void findUserConsumptionGoal_previousMonthAndGoalMonth() { List.of(goalMonthUserCategoryGoal)); // when - ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoal(user.getId(), + ConsumptionGoalResponseListDto result = consumptionGoalService.findUserConsumptionGoalList(user.getId(), goalMonthRandomDay); // then @@ -189,6 +189,7 @@ void updateConsumptionGoal_Success() { // given Long defaultGoalAmount = 100L; Long userGoalAmount = 200L; + LocalDate thisMonth = LocalDate.now().withDayOfMonth(1); given(userRepository.findById(user.getId())).willReturn(Optional.ofNullable(user)); @@ -209,13 +210,13 @@ void updateConsumptionGoal_Success() { .consumeAmount(20_000L) .user(user) .category(defaultCategory) - .goalMonth(GOAL_MONTH) + .goalMonth(thisMonth) .build(); given(consumptionGoalRepository.findConsumptionGoalByUserAndCategoryAndGoalMonth(user, defaultCategory, - GOAL_MONTH)).willReturn(Optional.ofNullable(defaultCategoryGoal)); + thisMonth)).willReturn(Optional.ofNullable(defaultCategoryGoal)); given(consumptionGoalRepository.findConsumptionGoalByUserAndCategoryAndGoalMonth(user, userCategory, - GOAL_MONTH)).willReturn(Optional.ofNullable(null)); + thisMonth)).willReturn(Optional.ofNullable(null)); when(consumptionGoalRepository.saveAll(any())).thenAnswer(invocation -> { List goalsToSave = invocation.getArgument(0); From 8b21c3007f0e071005963aa6a958e75e96fc5a0f Mon Sep 17 00:00:00 2001 From: JunRain Date: Sun, 4 Aug 2024 00:00:19 +0900 Subject: [PATCH 298/307] =?UTF-8?q?[feat]=20ExpenseUpdateRequestDto=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../expense/dto/ExpenseUpdateRequestDto.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseUpdateRequestDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseUpdateRequestDto.java index ba4a4358..7491c95c 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseUpdateRequestDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseUpdateRequestDto.java @@ -1,2 +1,16 @@ -package com.bbteam.budgetbuddies.domain.consumptiongoal.dto;public class ExpenseUpdateRequestDto { +package com.bbteam.budgetbuddies.domain.expense.dto; + +import java.time.LocalDateTime; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ExpenseUpdateRequestDto { + private Long expenseId; + private Long categoryId; + private LocalDateTime expenseDate; + private Long amount; } From 57d9f6e0d9fedd85687c10baa2535b0cf7788f3c Mon Sep 17 00:00:00 2001 From: JunRain Date: Sun, 4 Aug 2024 00:42:38 +0900 Subject: [PATCH 299/307] [fix] feat/#58 merge dev --- .../domain/category/entity/Category.java | 6 +- .../comment/controller/CommentController.java | 166 ++++++++++-------- .../controller/CommentControllerApi.java | 126 +++++++++++++ .../controller/CommentControllerImpl.java | 60 ------- .../comment/converter/CommentConverter.java | 19 +- .../domain/comment/dto/CommentRequestDto.java | 8 +- .../comment/dto/CommentResponseDto.java | 21 +-- .../domain/comment/entity/Comment.java | 5 + .../service/AbstractCommentService.java | 27 +++ .../comment/service/CommentService.java | 37 ++-- .../comment/service/CommentServiceImpl.java | 140 --------------- .../service/DiscountCommentService.java | 103 +++++++++++ .../service/SupportCommentService.java | 102 +++++++++++ .../controller/ConsumptionGoalApi.java | 8 + .../controller/ConsumptionGoalController.java | 17 +- .../converter/TopConsumptionConverter.java | 17 ++ .../dto/TopConsumptionResponseDTO.java | 17 ++ .../entity/ConsumptionGoal.java | 8 +- .../repository/ConsumptionGoalRepository.java | 6 + .../service/ConsumptionGoalService.java | 5 + .../service/ConsumptionGoalServiceImpl.java | 51 ++++-- .../controller/DiscountInfoApi.java | 56 +++++- .../controller/DiscountInfoController.java | 44 ++++- .../converter/DiscountInfoConverter.java | 6 +- .../discountinfo/dto/DiscountRequest.java | 50 ++++++ .../discountinfo/dto/DiscountRequestDto.java | 23 --- .../discountinfo/dto/DiscountResponseDto.java | 2 + .../discountinfo/entity/DiscountInfo.java | 13 ++ .../service/DiscountInfoService.java | 11 +- .../service/DiscountInfoServiceImpl.java | 67 ++++++- .../expense/repository/ExpenseRepository.java | 10 +- .../expense/service/ExpenseServiceImpl.java | 31 +++- .../controller/SupportInfoApi.java | 57 +++++- .../controller/SupportInfoController.java | 49 ++++-- .../converter/SupportInfoConverter.java | 9 +- .../supportinfo/dto/SupportRequest.java | 52 ++++++ .../supportinfo/dto/SupportRequestDto.java | 24 --- .../supportinfo/dto/SupportResponseDto.java | 2 + .../supportinfo/entity/SupportInfo.java | 13 ++ .../service/SupportInfoService.java | 15 +- .../service/SupportInfoServiceImpl.java | 78 ++++++-- ...iceTest.java => CommentServiceTestV2.java} | 100 ++++++----- .../ConsumptionGoalRepositoryTest.java | 44 +++++ .../service/ConsumptionGoalServiceTest.java | 54 +++++- .../service/DiscountInfoServiceTest.java | 7 +- .../repository/SupportInfoRepositoryTest.java | 7 + .../service/SupportInfoServiceTest.java | 14 +- 47 files changed, 1264 insertions(+), 523 deletions(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/AbstractCommentService.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopConsumptionConverter.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopConsumptionResponseDTO.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequest.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequest.java delete mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequestDto.java rename src/test/java/com/bbteam/budgetbuddies/domain/comment/service/{CommentServiceTest.java => CommentServiceTestV2.java} (87%) 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 0d0c761a..788bf807 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,14 +3,12 @@ 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 lombok.*; import org.hibernate.annotations.ColumnDefault; @Entity @Getter +@Setter @NoArgsConstructor @AllArgsConstructor @Builder 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 36500a8b..96f7e436 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,83 +1,101 @@ package com.bbteam.budgetbuddies.domain.comment.controller; - import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; -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 com.bbteam.budgetbuddies.domain.comment.service.CommentService; +import org.springframework.beans.factory.annotation.Qualifier; 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.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, 성공"), - }) - @Parameters({ - @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), - @Parameter(name = "discountInfoId", description = "댓글을 다는 할인 정보 게시글 id입니다. requestBody"), - @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), - }) - ResponseEntity saveDiscountInfoComment( - Long userId, - CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto); - - - @Operation(summary = "[User] 특정 할인 정보 게시글의 댓글 조회하기", description = "특정 할인 정보 게시글의 댓글을 가져오는 API입니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), - }) - @Parameters({ - @Parameter(name = "discountInfoId", description = "댓글을 가져올 할인 정보 게시글 id입니다. parameter"), - @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), - @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") - }) - ResponseEntity> findAllByDiscountInfo( - Long discountInfoId, - Pageable pageable); - - @Operation(summary = "[User] 특정 지원 정보 게시글에 댓글달기", description = "특정 지원 정보 게시글에 댓글을 다는 API입니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), - }) - @Parameters({ - @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), - @Parameter(name = "supportInfoId", description = "댓글을 다는 지원 정보 게시글 id입니다. requestBody"), - @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), - }) - ResponseEntity saveSupportInfoComment( - Long userId, - CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto); - - @Operation(summary = "[User] 특정 지원 정보 게시글의 댓글 조회하기", description = "특정 지원 정보 게시글의 댓글을 가져오는 API입니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), - }) - @Parameters({ - @Parameter(name = "supportInfoId", description = "댓글을 가져올 지원 정보 게시글 id입니다. parameter"), - @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), - @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") - - - }) - ResponseEntity> findAllBySupportInfo( - Long supportInfoId, - Pageable pageable); - - @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") - ResponseEntity deleteComment(Long commentId); +import org.springframework.web.bind.annotation.*; + +@RestController +public class CommentController implements CommentControllerApi { + + @Qualifier("discountCommentService") + private final CommentService discountCommentService; + + @Qualifier("supportCommentService") + private final CommentService supportCommentService; + + public CommentController(CommentService discountCommentService, + CommentService supportCommentService) { + this.discountCommentService = discountCommentService; + this.supportCommentService = supportCommentService; + } + + @PostMapping("/discounts/comments") + public ResponseEntity saveDiscountInfoComment( + @RequestParam("userId") Long userId, + @RequestBody CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto){ + CommentResponseDto.DiscountInfoCommentDto dto = discountCommentService.saveComment(userId, discountInfoCommentDto); + return ResponseEntity.ok(dto); + } + + + @GetMapping("/discounts/comments") + public ResponseEntity> findAllByDiscountInfo( + @RequestParam("discountInfoId") Long discountInfoId, + @PageableDefault(size = 20, page = 0) Pageable pageable){ + Page result = discountCommentService.findByInfoWithPaging(discountInfoId, pageable); + return ResponseEntity.ok(result); + } + + + @PostMapping("/supports/comments") + public ResponseEntity saveSupportInfoComment( + @RequestParam("userId") Long userId, + @RequestBody CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto){ + CommentResponseDto.SupportInfoCommentDto dto = supportCommentService.saveComment(userId, supportInfoCommentDto); + return ResponseEntity.ok(dto); + } + + + @GetMapping("/supports/comments") + public ResponseEntity> findAllBySupportInfo( + @RequestParam("supportInfoId") Long supportInfoId, + @PageableDefault(size = 20, page = 0)Pageable pageable){ + Page result = supportCommentService.findByInfoWithPaging(supportInfoId, pageable); + return ResponseEntity.ok(result); + } + + @PostMapping("/comments/delete") + public ResponseEntity deleteComment(@RequestParam("commentId") Long commentId) { + discountCommentService.deleteComment(commentId); + return ResponseEntity.ok("ok"); + } + + @GetMapping("/supports/comments/modify") + public ResponseEntity findSupportOne(@RequestParam("commentId")Long commentId) { + CommentResponseDto.SupportInfoCommentDto result = supportCommentService.findCommentOne(commentId); + return ResponseEntity.ok(result); + } + + @PostMapping("/supports/comments/modify") + public ResponseEntity modifySupportOne( + @RequestBody CommentRequestDto.CommentModifyDto dto) { + CommentResponseDto.SupportInfoCommentDto result = supportCommentService.modifyComment(dto); + return ResponseEntity.ok(result); + } + + @GetMapping("/discounts/comments/modify") + public ResponseEntity findDiscountOne(@RequestParam("commentId")Long commentId) { + CommentResponseDto.DiscountInfoCommentDto result = discountCommentService.findCommentOne(commentId); + return ResponseEntity.ok(result); + } + + @PostMapping("/discounts/comments/modify") + public ResponseEntity modifyDiscountOne( + @RequestBody CommentRequestDto.CommentModifyDto dto) { + CommentResponseDto.DiscountInfoCommentDto result = discountCommentService.modifyComment(dto); + return ResponseEntity.ok(result); + } + + + } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java new file mode 100644 index 00000000..ecaa37a4 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java @@ -0,0 +1,126 @@ +package com.bbteam.budgetbuddies.domain.comment.controller; + + +import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; +import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; +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 org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + +public interface CommentControllerApi { + @Operation(summary = "[User] 특정 할인 정보 게시글에 댓글달기", description = "특정 할인 정보 게시글에 댓글을 다는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), + @Parameter(name = "discountInfoId", description = "댓글을 다는 할인 정보 게시글 id입니다. requestBody"), + @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), + }) + ResponseEntity saveDiscountInfoComment( + Long userId, + CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto); + + + @Operation(summary = "[User] 특정 할인 정보 게시글의 댓글 조회하기", description = "특정 할인 정보 게시글의 댓글을 가져오는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "discountInfoId", description = "댓글을 가져올 할인 정보 게시글 id입니다. parameter"), + @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), + @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") + }) + ResponseEntity> findAllByDiscountInfo( + Long discountInfoId, + Pageable pageable); + + @Operation(summary = "[User] 특정 지원 정보 게시글에 댓글달기", description = "특정 지원 정보 게시글에 댓글을 다는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), + @Parameter(name = "supportInfoId", description = "댓글을 다는 지원 정보 게시글 id입니다. requestBody"), + @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), + }) + ResponseEntity saveSupportInfoComment( + Long userId, + CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto); + + @Operation(summary = "[User] 특정 지원 정보 게시글의 댓글 조회하기", description = "특정 지원 정보 게시글의 댓글을 가져오는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "supportInfoId", description = "댓글을 가져올 지원 정보 게시글 id입니다. parameter"), + @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), + @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") + + + }) + ResponseEntity> findAllBySupportInfo( + Long supportInfoId, + Pageable pageable); + + @Operation(summary = "[User] 특정 댓글 삭제하기", description = "특정 댓글을 삭제하는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "commentId", description = "삭제할 댓글 id 입니다. parameter") + }) + ResponseEntity deleteComment(Long commentId); + + @Operation(summary = "[User] SupportInfo의 댓글 요청 API ", description = "특정 댓글을 요청하는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "commentId", description = "조회할 댓글 id 입니다. parameter") + }) + ResponseEntity findSupportOne(@RequestParam("commentId")Long commentId); + + @Operation(summary = "[User] SupprotInfo의 댓글 변경 API", description = "특정 댓글을 변경하는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "commentId", description = "변경할 댓글 id 입니다. requestbody"), + @Parameter(name = "comment", description = "변경할 댓글 내용입니다.. requestbody") + + }) + ResponseEntity modifySupportOne( + @RequestBody CommentRequestDto.CommentModifyDto dto); + + + @Operation(summary = "[User] DiscountInfo의 댓글 요청 API ", description = "특정 댓글을 요청하는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "commentId", description = "조회할 댓글 id 입니다. parameter") + }) + ResponseEntity findDiscountOne(@RequestParam("commentId")Long commentId); + + @Operation(summary = "[User] DiscountInfo의 댓글 변경 API", description = "특정 댓글을 변경하는 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + }) + @Parameters({ + @Parameter(name = "commentId", description = "변경할 댓글 id 입니다. requestbody"), + @Parameter(name = "comment", description = "변경할 댓글 내용입니다.. requestbody") + + }) + ResponseEntity modifyDiscountOne( + @RequestBody CommentRequestDto.CommentModifyDto dto); + +} 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 deleted file mode 100644 index 8f9691d7..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerImpl.java +++ /dev/null @@ -1,60 +0,0 @@ -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 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") - 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") - 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") - 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") - 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"); - } - -} 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 626a1e6f..8e424e50 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 @@ -36,6 +36,7 @@ public static CommentResponseDto.DiscountInfoCommentDto toDiscountInfoCommentDto .userId(comment.getUser().getId()) .content(comment.getContent()) .anonymousNumber(comment.getAnonymousNumber()) + .createdAt(comment.getCreatedAt()) .build(); } @@ -47,26 +48,10 @@ public static CommentResponseDto.SupportInfoCommentDto toSupportInfoCommentDto(C .userId(comment.getUser().getId()) .content(comment.getContent()) .anonymousNumber(comment.getAnonymousNumber()) + .createdAt(comment.getCreatedAt()) .build(); } - 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()) - .build(); - } - - 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()) - .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 index 45b91e8e..9b516614 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 @@ -2,7 +2,6 @@ import lombok.Builder; import lombok.Getter; -import lombok.Setter; public class CommentRequestDto { @@ -19,4 +18,11 @@ public static class SupportInfoCommentDto { private String content; private Long supportInfoId; } + + @Getter + @Builder + public static class CommentModifyDto { + private String content; + private Long commentId; + } } 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 bfc27405..932cad45 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 @@ -4,6 +4,9 @@ import lombok.Builder; import lombok.Getter; +import java.time.LocalDate; +import java.time.LocalDateTime; + public class CommentResponseDto { @Getter @@ -14,6 +17,7 @@ public static class DiscountInfoCommentDto{ private Long discountInfoId; private String content; private Integer anonymousNumber; + private LocalDateTime createdAt; } @Getter @@ -24,24 +28,9 @@ public static class SupportInfoCommentDto{ private Long supportInfoId; private String content; private Integer anonymousNumber; + private LocalDateTime createdAt; } - @Getter - @Builder - public static class DiscountInfoSuccessDto{ - private Long commentId; - private Long userId; - private Long discountInfoId; - private String content; - } - @Getter - @Builder - public static class SupportInfoSuccessDto{ - private Long commentId; - private Long userId; - private Long supportInfoId; - private String content; - } } 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 ce3ecccc..81827240 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 @@ -41,4 +41,9 @@ public class Comment extends BaseEntity { @Column(nullable = false) private Integer anonymousNumber; + public void modifyComment(String newComment) { + this.content = newComment; + return; + } + } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/AbstractCommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/AbstractCommentService.java new file mode 100644 index 00000000..9bf31236 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/AbstractCommentService.java @@ -0,0 +1,27 @@ +package com.bbteam.budgetbuddies.domain.comment.service; + +import com.bbteam.budgetbuddies.domain.comment.entity.Comment; +import com.bbteam.budgetbuddies.domain.comment.repository.CommentRepository; + +import java.util.NoSuchElementException; +import java.util.Optional; + +public abstract class AbstractCommentService implements CommentService { + + protected final CommentRepository commentRepository; + + public AbstractCommentService(CommentRepository commentRepository) { + this.commentRepository = commentRepository; + } + + @Override + public void deleteComment(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); + commentRepository.delete(comment); + } + + @Override + public Optional findById(Long commentId) { + return commentRepository.findById(commentId); + } +} 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 ac49bc5a..29661e29 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 @@ -1,40 +1,39 @@ 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.discountinfo.entity.DiscountInfo; +import com.bbteam.budgetbuddies.domain.user.entity.User; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.stream.Collectors; -public interface CommentService { - CommentResponseDto.SupportInfoSuccessDto saveSupportComment(Long userId, CommentRequestDto.SupportInfoCommentDto dto); - CommentResponseDto.DiscountInfoSuccessDto saveDiscountComment(Long userId, CommentRequestDto.DiscountInfoCommentDto dto); +public interface CommentService { - /** - * - * @param discountInfoId - * @return List - * 해당 로직은 익명 구분을 위한 익명 구분 숫자도 같이 return 합니다. - */ - List findByDiscountInfo(Long discountInfoId); + T saveComment(Long userId, R dto); - /** - * - * @param supportInfoId - * @return List - * 해당 로직은 익명 구분을 위한 익명 구분 숫자도 같이 return 합니다. - */ - List findBySupportInfo(Long supportInfoId); - Page findByDiscountInfoWithPaging(Long discountInfoId, Pageable pageable); - Page findBySupportInfoWithPaging(Long supportInfoId, Pageable pageable); + List findByInfo(Long infoId); + + + Page findByInfoWithPaging(Long infoId, Pageable pageable); + void deleteComment(Long commentId); + T findCommentOne(Long commentId); + T modifyComment(CommentRequestDto.CommentModifyDto dto); + Optional findById(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 deleted file mode 100644 index df8063fa..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceImpl.java +++ /dev/null @@ -1,140 +0,0 @@ -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.data.domain.Page; -import org.springframework.data.domain.Pageable; -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.Optional; -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()); - 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 - @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()); - 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); - - HashMap anonymousMapping = countAnonymousNumber(commentList); - List collect = commentList.stream() - .map(CommentConverter::toDiscountInfoCommentDto) - .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(CommentConverter::toSupportInfoCommentDto) - .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; - } - - @Override - public Page findByDiscountInfoWithPaging(Long discountInfoId, Pageable pageable) { - Page commentPage = commentRepository.findByDiscountInfoWithPaging(discountInfoId, pageable); - Page result = commentPage.map(CommentConverter::toDiscountInfoCommentDto); - return result; - } - - @Override - public Page findBySupportInfoWithPaging(Long supportInfoId, Pageable pageable) { - Page commentPage = commentRepository.findBySupportInfoWithPaging(supportInfoId, pageable); - Page result = commentPage.map(CommentConverter::toSupportInfoCommentDto); - return result; - } - - @Override - @Transactional - public void deleteComment(Long commentId) { - Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); - commentRepository.delete(comment); - } -} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java new file mode 100644 index 00000000..b5a146a4 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/DiscountCommentService.java @@ -0,0 +1,103 @@ +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.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.stream.Collectors; + +@Service("discountCommentService") +@Transactional(readOnly = true) +public class DiscountCommentService extends AbstractCommentService { + private final UserRepository userRepository; + private final DiscountInfoRepository discountInfoRepository; + + public DiscountCommentService(CommentRepository commentRepository, UserRepository userRepository, DiscountInfoRepository discountInfoRepository) { + super(commentRepository); + this.userRepository = userRepository; + this.discountInfoRepository = discountInfoRepository; + } + + @Override + @Transactional + public CommentResponseDto.DiscountInfoCommentDto saveComment(Long userId, CommentRequestDto.DiscountInfoCommentDto dto) { + User user = userRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("유저 존재 x")); + DiscountInfo info = discountInfoRepository.findById(dto.getDiscountInfoId()).orElseThrow(() -> new NoSuchElementException("정보 존재 x")); // dto에서 infoId를 추출하여 찾는 메서드 + int anonymousNumber = getAnonymousNumber(user, info); + Comment comment = CommentConverter.toDiscountComment(dto, user, info, anonymousNumber); + Comment savedComment = commentRepository.save(comment); + + return CommentConverter.toDiscountInfoCommentDto(savedComment); + } + + + + private int getAnonymousNumber(User user, DiscountInfo info) { + int anonymousNumber; + Optional foundComment = commentRepository.findTopByUserAndDiscountInfo(user, info); + if (foundComment.isEmpty()) { + anonymousNumber = info.addAndGetAnonymousNumber(); + } else { + anonymousNumber = foundComment.get().getAnonymousNumber(); + } + return anonymousNumber; + } + + @Override + public List findByInfo(Long infoId) { + List commentList = commentRepository.findByDiscountInfo(infoId); + List collect = commentList.stream() + .map(CommentConverter::toDiscountInfoCommentDto) + .collect(Collectors.toList()); + return collect; + } + + @Override + public Page findByInfoWithPaging(Long infoId, Pageable pageable) { + Page commentPage = commentRepository.findByDiscountInfoWithPaging(infoId, pageable); + Page result = commentPage.map(CommentConverter::toDiscountInfoCommentDto); + return result; + } + + @Override + @Transactional + public void deleteComment(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); + commentRepository.delete(comment); + } + + @Override + public CommentResponseDto.DiscountInfoCommentDto findCommentOne(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such comment")); + if(comment.getDiscountInfo() == null){ + throw new RuntimeException("DiscountInfo comment에 대한 요청이 아닙니다."); + } + return CommentConverter.toDiscountInfoCommentDto(comment); + } + + @Override + @Transactional + public CommentResponseDto.DiscountInfoCommentDto modifyComment(CommentRequestDto.CommentModifyDto dto) { + Comment comment = commentRepository.findById(dto.getCommentId()).orElseThrow(() -> new NoSuchElementException("xxx")); + if (comment.getDiscountInfo() == null) { + throw new RuntimeException("DiscountInfo comment에 대한 요청이 아닙니다."); + } + comment.modifyComment(dto.getContent()); + + return CommentConverter.toDiscountInfoCommentDto(comment); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java new file mode 100644 index 00000000..9e46d66b --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/service/SupportCommentService.java @@ -0,0 +1,102 @@ +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.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 org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.stream.Collectors; + +@Service("supportCommentService") +@Transactional(readOnly = true) +public class SupportCommentService extends AbstractCommentService { + + private final UserRepository userRepository; + private final SupportInfoRepository supportInfoRepository; + + public SupportCommentService(CommentRepository commentRepository, UserRepository userRepository, SupportInfoRepository supportInfoRepository) { + super(commentRepository); + this.userRepository = userRepository; + this.supportInfoRepository = supportInfoRepository; + } + + @Override + @Transactional + public CommentResponseDto.SupportInfoCommentDto saveComment(Long userId, CommentRequestDto.SupportInfoCommentDto dto) { + User user = userRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("유저 존재 x")); + SupportInfo info = supportInfoRepository.findById(dto.getSupportInfoId()).orElseThrow(() -> new NoSuchElementException("정보 존재 x")); // dto에서 infoId를 추출하여 찾는 메서드 + int anonymousNumber = getAnonymousNumber(user, info); + Comment comment = CommentConverter.toSupportComment(dto, user, info, anonymousNumber); + Comment savedComment = commentRepository.save(comment); + + return CommentConverter.toSupportInfoCommentDto(savedComment); + } + + private int getAnonymousNumber(User user, SupportInfo info) { + int anonymousNumber; + Optional foundComment = commentRepository.findTopByUserAndSupportInfo(user, info); + if (foundComment.isEmpty()) { + anonymousNumber = info.addAndGetAnonymousNumber(); + } else { + anonymousNumber = foundComment.get().getAnonymousNumber(); + } + return anonymousNumber; + } + + @Override + public List findByInfo(Long infoId) { + List commentList = commentRepository.findBySupportInfo(infoId); + List collect = commentList.stream() + .map(CommentConverter::toSupportInfoCommentDto) + .collect(Collectors.toList()); + return collect; + } + + @Override + public Page findByInfoWithPaging(Long infoId, Pageable pageable) { + Page commentPage = commentRepository.findBySupportInfoWithPaging(infoId, pageable); + Page result = commentPage.map(CommentConverter::toSupportInfoCommentDto); + return result; + } + + @Override + @Transactional + public void deleteComment(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such id")); + commentRepository.delete(comment); + } + + @Override + public CommentResponseDto.SupportInfoCommentDto findCommentOne(Long commentId) { + Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new NoSuchElementException("No such comment")); + if(comment.getSupportInfo() == null){ + throw new RuntimeException("supportInfo comment에 대한 요청이 아닙니다."); + } + return CommentConverter.toSupportInfoCommentDto(comment); + } + + @Override + @Transactional + public CommentResponseDto.SupportInfoCommentDto modifyComment(CommentRequestDto.CommentModifyDto dto) { + Comment comment = commentRepository.findById(dto.getCommentId()).orElseThrow(() -> new NoSuchElementException("xxx")); + if (comment.getSupportInfo() == null) { + throw new RuntimeException("supportInfo comment에 대한 요청이 아닙니다."); + } + comment.modifyComment(dto.getContent()); + + return CommentConverter.toSupportInfoCommentDto(comment); + } +} 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 index 4e739a8a..3a8c2f7b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/controller/ConsumptionGoalApi.java @@ -46,4 +46,12 @@ ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaultValue ResponseEntity updateOrElseGenerateConsumptionGoal(Long userId, ConsumptionGoalListRequestDto consumptionGoalListRequestDto); + @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 getConsumptionGoal(int top, Long userId, int peerAgeStart, int peerAgeEnd, String peerGender); } 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 077dd557..2a179695 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 @@ -17,6 +17,7 @@ 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.TopConsumptionResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.service.ConsumptionGoalService; @@ -30,7 +31,7 @@ public class ConsumptionGoalController implements ConsumptionGoalApi { private final ConsumptionGoalService consumptionGoalService; @Override - @GetMapping("/top-categories") + @GetMapping("/top-categories/top-goal") public ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaultValue = "5") int top, @RequestParam(name = "userId") Long userId, @RequestParam(name = "peerAgeStart", defaultValue = "0") int peerAgeStart, @@ -42,7 +43,7 @@ public ResponseEntity getTopGoalCategories(@RequestParam(name = "top", defaul } @Override - @GetMapping("/top-category") + @GetMapping("/top-category/top-goal") public ResponseEntity getTopGoalCategory(@RequestParam(name = "userId") Long userId) { ConsumptionAnalysisResponseDTO response = consumptionGoalService.getTopCategoryAndConsumptionAmount(userId); return ResponseEntity.ok(response); @@ -58,7 +59,6 @@ public ResponseEntity getPeerInfo(@RequestParam(name = "userId") Long userId, return ResponseEntity.ok(response); } - @Override @GetMapping("/{userId}") public ResponseEntity findUserConsumptionGoal( @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date, @PathVariable Long userId) { @@ -76,4 +76,15 @@ public ResponseEntity updateOrElseGenerateConsum return ResponseEntity.ok() .body(consumptionGoalService.updateConsumptionGoals(userId, consumptionGoalListRequestDto)); } + + @GetMapping("/top-categories/top-consumption") + public ResponseEntity getConsumptionGoal(@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 response = consumptionGoalService.getTopConsumption(top, userId, + peerAgeStart, peerAgeEnd, peerGender); + return ResponseEntity.ok(response); + } } \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopConsumptionConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopConsumptionConverter.java new file mode 100644 index 00000000..9f37e9c1 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/converter/TopConsumptionConverter.java @@ -0,0 +1,17 @@ +package com.bbteam.budgetbuddies.domain.consumptiongoal.converter; + +import org.springframework.stereotype.Component; + +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopConsumptionResponseDTO; +import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; + +@Component +public class TopConsumptionConverter { + public static TopConsumptionResponseDTO fromEntity(ConsumptionGoal consumptionGoal) { + + return TopConsumptionResponseDTO.builder() + .categoryName(consumptionGoal.getCategory().getName()) + .consumeAmount(consumptionGoal.getConsumeAmount()) + .build(); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopConsumptionResponseDTO.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopConsumptionResponseDTO.java new file mode 100644 index 00000000..e6041e2b --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/TopConsumptionResponseDTO.java @@ -0,0 +1,17 @@ +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 TopConsumptionResponseDTO { + + private String categoryName; + + private Long consumeAmount; +} 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 b9af57d0..0c0b5bae 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,6 +44,10 @@ public class ConsumptionGoal extends BaseEntity { @JoinColumn(name = "category_id") private Category category; + public void updateConsumeAmount(Long amount) { + this.consumeAmount += amount; + } + public void updateGoalAmount(Long goalAmount) { this.goalAmount = goalAmount; } @@ -51,8 +55,4 @@ public void updateGoalAmount(Long goalAmount) { public void restoreConsumeAmount(Long previousAmount) { this.consumeAmount -= previousAmount; } - - public void consume(Long amount) { - this.consumeAmount += amount; - } } 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 972a8c7c..a5444e5f 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 @@ -33,4 +33,10 @@ Optional findConsumptionGoalByUserAndCategoryAndGoalMonth(User + "BETWEEN :startOfWeek AND :endOfWeek ORDER BY cg.consumeAmount DESC limit 1") Optional findTopConsumptionByCategoryIdAndCurrentWeek(@Param("categoryId") Long categoryId, @Param("startOfWeek") LocalDate startOfWeek, @Param("endOfWeek") LocalDate endOfWeek); + + @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.consumeAmount DESC limit :top") + List findTopConsumptionAndConsumeAmount(@Param("top") int top, @Param("peerAgeStart") int peerAgeStart, + @Param("peerAgeEnd") int peerAgeEnd, @Param("peerGender") Gender peerGender); } \ No newline at end of file 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 9416f0f9..734ca773 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 @@ -9,6 +9,7 @@ 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.TopConsumptionResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; import com.bbteam.budgetbuddies.domain.expense.dto.ExpenseUpdateRequestDto; import com.bbteam.budgetbuddies.domain.expense.entity.Expense; @@ -30,4 +31,8 @@ ConsumptionGoalResponseListDto updateConsumptionGoals(Long userId, ConsumptionAnalysisResponseDTO getTopCategoryAndConsumptionAmount(Long userId); void recalculateConsumptionAmount(Expense expense, ExpenseUpdateRequestDto request, User user); + + void updateConsumeAmount(Long userId, Long categoryId, Long amount); + + List getTopConsumption(int top, Long userId, int peerAgeS, int peerAgeE, String peerG); } \ 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 04a715c2..b3b9cc81 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,16 +19,18 @@ 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.converter.TopConsumptionConverter; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionAnalysisResponseDTO; 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.expense.dto.ExpenseUpdateRequestDto; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.PeerInfoResponseDTO; +import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopConsumptionResponseDTO; 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.expense.dto.ExpenseUpdateRequestDto; import com.bbteam.budgetbuddies.domain.expense.entity.Expense; import com.bbteam.budgetbuddies.domain.user.entity.User; import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; @@ -55,9 +57,7 @@ public class ConsumptionGoalServiceImpl implements ConsumptionGoalService { public List getTopGoalCategories(int top, Long userId, int peerAgeS, int peerAgeE, String peerG) { - User user = findUserById(userId); - - checkPeerInfo(user, peerAgeS, peerAgeE, peerG); + checkPeerInfo(userId, peerAgeS, peerAgeE, peerG); List topGoals = consumptionGoalRepository.findTopCategoriesAndGoalAmount(top, peerAgeStart, peerAgeEnd, peerGender); @@ -68,9 +68,7 @@ public List getTopGoalCategories(int top, Long userI @Transactional(readOnly = true) public PeerInfoResponseDTO getPeerInfo(Long userId, int peerAgeS, int peerAgeE, String peerG) { - User user = findUserById(userId); - - checkPeerInfo(user, peerAgeS, peerAgeE, peerG); + checkPeerInfo(userId, peerAgeS, peerAgeE, peerG); return PeerInfoConverter.fromEntity(peerAgeStart, peerAgeEnd, peerGender); } @@ -79,9 +77,7 @@ public PeerInfoResponseDTO getPeerInfo(Long userId, int peerAgeS, int peerAgeE, @Transactional(readOnly = true) public ConsumptionAnalysisResponseDTO getTopCategoryAndConsumptionAmount(Long userId) { - User user = findUserById(userId); - - checkPeerInfo(user, 0, 0, "none"); + checkPeerInfo(userId, 0, 0, "none"); ConsumptionGoal topConsumptionGoal = consumptionGoalRepository.findTopCategoriesAndGoalAmount(1, peerAgeStart, peerAgeEnd, peerGender).get(0); @@ -92,7 +88,8 @@ public ConsumptionAnalysisResponseDTO getTopCategoryAndConsumptionAmount(Long us ConsumptionGoal currentWeekConsumptionAmount = consumptionGoalRepository.findTopConsumptionByCategoryIdAndCurrentWeek( topConsumptionGoal.getCategory().getId(), startOfWeek, endOfWeek) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new IllegalArgumentException( + "카테고리 ID " + topConsumptionGoal.getCategory().getId() + "에 대한 현재 주 소비 데이터가 없습니다.")); Long totalConsumptionAmountForCurrentWeek = currentWeekConsumptionAmount.getConsumeAmount(); @@ -109,7 +106,9 @@ private User findUserById(Long userId) { return user.get(); } - private void checkPeerInfo(User user, int peerAgeS, int peerAgeE, String peerG) { + private void checkPeerInfo(Long userId, int peerAgeS, int peerAgeE, String peerG) { + + User user = findUserById(userId); Gender gender = Gender.valueOf(peerG.toUpperCase()); @@ -249,7 +248,7 @@ private void calculatePresentGoalConsumptionAmount(ExpenseUpdateRequestDto reque .orElseGet(() -> this.generateGoalByPreviousOrElseNew(user, categoryToReplace, request.getExpenseDate().toLocalDate().withDayOfMonth(1))); - consumptionGoal.consume(request.getAmount()); + consumptionGoal.updateConsumeAmount(request.getAmount()); consumptionGoalRepository.save(consumptionGoal); } @@ -270,4 +269,30 @@ private ConsumptionGoal generateGoalByPrevious(ConsumptionGoal consumptionGoal) .goalAmount(consumptionGoal.getGoalAmount()) .build(); } + + @Override + public void updateConsumeAmount(Long userId, Long categoryId, Long amount) { + User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("Not found user")); + + Category category = categoryRepository.findById(categoryId) + .orElseThrow(() -> new IllegalArgumentException("Not found Category")); + + LocalDate thisMonth = LocalDate.now().withDayOfMonth(1); + ConsumptionGoal consumptionGoal = consumptionGoalRepository.findConsumptionGoalByUserAndCategoryAndGoalMonth( + user, category, thisMonth).orElseGet(() -> generateNewConsumptionGoal(user, category, thisMonth)); + + consumptionGoal.updateConsumeAmount(amount); + consumptionGoalRepository.save(consumptionGoal); + } + + @Override + public List getTopConsumption(int top, Long userId, int peerAgeS, int peerAgeE, + String peerG) { + + checkPeerInfo(userId, peerAgeS, peerAgeE, peerG); + + List topConsumptions = consumptionGoalRepository.findTopConsumptionAndConsumeAmount(top, + peerAgeStart, peerAgeEnd, peerGender); + return topConsumptions.stream().map(TopConsumptionConverter::fromEntity).collect(Collectors.toList()); + } } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java index f381f94f..5603e0f3 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoApi.java @@ -1,6 +1,6 @@ package com.bbteam.budgetbuddies.domain.discountinfo.controller; -import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -8,7 +8,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import org.springframework.data.domain.Page; 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.RequestBody; import org.springframework.web.bind.annotation.RequestParam; @@ -41,9 +40,12 @@ ResponseEntity> getDiscountsByYearAndMonth( // @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 = "discountRequestDto", description = "등록할 할인 정보의 전체 내용입니다."), }) public ResponseEntity registerDiscountInfo( - @RequestBody DiscountRequestDto discountRequestDto + @RequestBody DiscountRequest.RegisterDto discountRequestDto ); @Operation(summary = "[User] 특정 할인정보에 좋아요 클릭 API", description = "특정 할인정보에 좋아요 버튼을 클릭하는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)") @@ -62,4 +64,52 @@ public ResponseEntity likeDiscountInfo( @PathVariable Long discountInfoId ); + @Operation(summary = "[ADMIN] 특정 할인정보 수정하기 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 = "discountRequestDto", description = "수정할 할인 정보의 전체 내용입니다."), + }) + public ResponseEntity updateDiscountInfo( + @RequestParam Long userId, + @RequestBody DiscountRequest.UpdateDto discountRequestDto + ); + + @Operation(summary = "[ADMIN] 특정 할인정보 삭제하기 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 = "discountInfoId", description = "삭제할 할인 정보의 id입니다."), + }) + public ResponseEntity deleteDiscountInfo( + @RequestParam Long userId, + @PathVariable Long discountInfoId + ); + + @Operation(summary = "[ADMIN] 특정 할인정보 가져오기 API", description = "ID를 통해 특정 할인정보를 가져오는 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 = "discountInfoId", description = "조회할 할인 정보의 id입니다."), + }) + public ResponseEntity getDiscountInfo( + @RequestParam Long userId, + @PathVariable Long discountInfoId + ); + } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java index cd129809..ec1c51d7 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/controller/DiscountInfoController.java @@ -1,12 +1,8 @@ package com.bbteam.budgetbuddies.domain.discountinfo.controller; -import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; import com.bbteam.budgetbuddies.domain.discountinfo.service.DiscountInfoService; -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; @@ -35,7 +31,7 @@ public ResponseEntity> getDiscountsByYearAndMonth( @Override @PostMapping("") public ResponseEntity registerDiscountInfo( - @RequestBody DiscountRequestDto discountRequestDto + @RequestBody DiscountRequest.RegisterDto discountRequestDto ) { DiscountResponseDto discountResponseDto = discountInfoService.registerDiscountInfo(discountRequestDto); @@ -43,7 +39,7 @@ public ResponseEntity registerDiscountInfo( } @Override - @PostMapping("/{discountInfoId}/likes") + @PostMapping("/likes/{discountInfoId}") public ResponseEntity likeDiscountInfo( @RequestParam Long userId, @PathVariable Long discountInfoId @@ -53,4 +49,38 @@ public ResponseEntity likeDiscountInfo( return ResponseEntity.ok(discountResponseDto); } + @Override + @PutMapping("") + public ResponseEntity updateDiscountInfo( + @RequestParam Long userId, + @RequestBody DiscountRequest.UpdateDto discountRequestDto + ) { + DiscountResponseDto discountResponseDto = discountInfoService.updateDiscountInfo(userId, discountRequestDto); + + return ResponseEntity.ok(discountResponseDto); + } + + @Override + @DeleteMapping("/{discountInfoId}") + public ResponseEntity deleteDiscountInfo( + @RequestParam Long userId, + @PathVariable Long discountInfoId + ) { + String message = discountInfoService.deleteDiscountInfo(userId, discountInfoId); + + return ResponseEntity.ok(message); + } + + + @Override + @GetMapping("/{discountInfoId}") + public ResponseEntity getDiscountInfo( + @RequestParam Long userId, + @PathVariable Long discountInfoId + ) { + DiscountResponseDto discountResponseDto = discountInfoService.getDiscountInfoById(userId, discountInfoId); + + return ResponseEntity.ok(discountResponseDto); + } + } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java index 66793215..7a9e39eb 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/converter/DiscountInfoConverter.java @@ -1,6 +1,6 @@ package com.bbteam.budgetbuddies.domain.discountinfo.converter; -import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; import org.springframework.stereotype.Service; @@ -23,6 +23,7 @@ public DiscountResponseDto toDto(DiscountInfo entity) { .discountRate(entity.getDiscountRate()) .likeCount(entity.getLikeCount()) .siteUrl(entity.getSiteUrl()) + .thumbnailUrl(entity.getThumbnailUrl()) .build(); } @@ -31,7 +32,7 @@ public DiscountResponseDto toDto(DiscountInfo entity) { * @param requestDto * @return entity */ - public DiscountInfo toEntity(DiscountRequestDto requestDto) { + public DiscountInfo toEntity(DiscountRequest.RegisterDto requestDto) { return DiscountInfo.builder() .title(requestDto.getTitle()) @@ -41,6 +42,7 @@ public DiscountInfo toEntity(DiscountRequestDto requestDto) { .discountRate(requestDto.getDiscountRate()) .likeCount(0) .siteUrl(requestDto.getSiteUrl()) + .thumbnailUrl(requestDto.getThumbnailUrl()) .build(); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequest.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequest.java new file mode 100644 index 00000000..490565bf --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequest.java @@ -0,0 +1,50 @@ +package com.bbteam.budgetbuddies.domain.discountinfo.dto; + +import lombok.*; + +import java.time.LocalDate; + +public class DiscountRequest { + + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class RegisterDto { + + private String title; + + private LocalDate startDate; + + private LocalDate endDate; + + private Integer discountRate; + + private String siteUrl; + + private String thumbnailUrl; + } + + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class UpdateDto { + + private Long id; + + private String title; + + private LocalDate startDate; + + private LocalDate endDate; + + private Integer discountRate; + + private String siteUrl; + + private String thumbnailUrl; + } + + +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java deleted file mode 100644 index 894f6b3b..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountRequestDto.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.bbteam.budgetbuddies.domain.discountinfo.dto; - -import lombok.*; - -import java.time.LocalDate; - -@Getter -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class DiscountRequestDto { - - private String title; - - private LocalDate startDate; - - private LocalDate endDate; - - private Integer discountRate; - - private String siteUrl; - -} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java index 3cd64ff4..3948f419 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/dto/DiscountResponseDto.java @@ -26,4 +26,6 @@ public class DiscountResponseDto { private String siteUrl; + private String thumbnailUrl; + } 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 2beb881a..3c1d0a5e 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 @@ -1,6 +1,7 @@ package com.bbteam.budgetbuddies.domain.discountinfo.entity; import com.bbteam.budgetbuddies.common.BaseEntity; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import jakarta.persistence.Column; import jakarta.persistence.Entity; import lombok.*; @@ -34,6 +35,9 @@ public class DiscountInfo extends BaseEntity { @Column(length = 1000) private String siteUrl; + @Column(length = 1000) + private String thumbnailUrl; // 카드 썸네일 이미지 + public void addLikeCount() { this.likeCount++; } @@ -47,4 +51,13 @@ public Integer addAndGetAnonymousNumber() { return anonymousNumber; } + public void update(DiscountRequest.UpdateDto discountRequestDto) { + this.title = discountRequestDto.getTitle(); + this.startDate = discountRequestDto.getStartDate(); + this.endDate = discountRequestDto.getEndDate(); + this.discountRate = discountRequestDto.getDiscountRate(); + this.siteUrl = discountRequestDto.getSiteUrl(); + this.thumbnailUrl = discountRequestDto.getThumbnailUrl(); + } + } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java index 5be85054..cd8d54de 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoService.java @@ -1,6 +1,6 @@ package com.bbteam.budgetbuddies.domain.discountinfo.service; -import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; import org.springframework.data.domain.Page; @@ -12,9 +12,14 @@ Page getDiscountsByYearAndMonth( Integer size ); - DiscountResponseDto registerDiscountInfo(DiscountRequestDto discountRequestDto); + DiscountResponseDto registerDiscountInfo(DiscountRequest.RegisterDto discountRequestDto); DiscountResponseDto toggleLike(Long userId, Long discountInfoId); + DiscountResponseDto updateDiscountInfo(Long userId, DiscountRequest.UpdateDto discountRequestDto); -} + String deleteDiscountInfo(Long userId, Long discountInfoId); + + DiscountResponseDto getDiscountInfoById(Long userId, Long discountInfoId); + +} \ No newline at end of file diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java index a1ef0604..b7348821 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceImpl.java @@ -1,7 +1,7 @@ package com.bbteam.budgetbuddies.domain.discountinfo.service; import com.bbteam.budgetbuddies.domain.discountinfo.converter.DiscountInfoConverter; -import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; import com.bbteam.budgetbuddies.domain.discountinfo.repository.DiscountInfoRepository; @@ -53,7 +53,7 @@ public Page getDiscountsByYearAndMonth(Integer year, Intege @Transactional @Override - public DiscountResponseDto registerDiscountInfo(DiscountRequestDto discountRequestDto) { + public DiscountResponseDto registerDiscountInfo(DiscountRequest.RegisterDto discountRequestDto) { /** * 1. RequestDto -> Entity로 변환 * 2. Entity 저장 @@ -115,5 +115,68 @@ public DiscountResponseDto toggleLike(Long userId, Long discountInfoId) { return discountInfoConverter.toDto(savedEntity); } + @Transactional + @Override + public DiscountResponseDto updateDiscountInfo(Long userId, DiscountRequest.UpdateDto discountRequestDto) { + /** + * 1. 사용자 조회 -> 없으면 에러 + * 2. 할인정보 조회 -> 없으면 에러 + * 3. 변경사항 업데이트 + * 4. 변경사항 저장 + * 5. Entity -> ResponseDto로 변환 후 리턴 + */ + + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + + DiscountInfo discountInfo = discountInfoRepository.findById(discountRequestDto.getId()) + .orElseThrow(() -> new IllegalArgumentException("DiscountInfo not found")); + + discountInfo.update(discountRequestDto); // 변경사항 업데이트 + + discountInfoRepository.save(discountInfo); // 변경사항 저장 + + return discountInfoConverter.toDto(discountInfo); + } + + @Transactional + @Override + public String deleteDiscountInfo(Long userId, Long discountInfoId) { + /** + * 1. 사용자 조회 -> 없으면 에러 + * 2. 할인정보 조회 -> 없으면 에러 + * 3. Entity 삭제 + * 4. 성공여부 반환 + */ + + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + + DiscountInfo discountInfo = discountInfoRepository.findById(discountInfoId) + .orElseThrow(() -> new IllegalArgumentException("DiscountInfo not found")); + + discountInfoRepository.deleteById(discountInfoId); + return "Success"; + + } + + @Transactional + @Override + public DiscountResponseDto getDiscountInfoById(Long userId, Long discountInfoId) { + /** + * 1. 사용자 조회 -> 없으면 에러 + * 2. 할인정보 조회 -> 없으면 에러 + * 3. Entity 조회 + * 4. Entity -> ResponseDto로 변환 후 리턴 + */ + + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + + DiscountInfo discountInfo = discountInfoRepository.findById(discountInfoId) + .orElseThrow(() -> new IllegalArgumentException("DiscountInfo not found")); + + return discountInfoConverter.toDto(discountInfo); + } } 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 ab9721e0..2bfef5a4 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 @@ -13,15 +13,7 @@ import com.bbteam.budgetbuddies.domain.user.entity.User; 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); - @Query("SELECT e FROM Expense e WHERE e.user = :user AND e.expenseDate BETWEEN :startDate AND :endDate ORDER BY e.expenseDate DESC") Slice findAllByUserIdForPeriod(Pageable pageable, @Param("user") User user, - @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate); + @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate); } 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 index 808857ef..7fe40b26 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java @@ -41,10 +41,38 @@ public ExpenseResponseDto createExpense(ExpenseRequestDto expenseRequestDto) { Category category = categoryRepository.findById(expenseRequestDto.getCategoryId()) .orElseThrow(() -> new IllegalArgumentException("Invalid category ID")); + /* + case 1) + - 카테고리 ID가 1~10 사이 && default => DB의 immutable 필드인 default category + - DB 관리 이슈로 category에 default 카테고리의 중복이 발생할 경우, 이를 대비하기 위해 1<= id <= 10 조건도 추가 + */ + if (expenseRequestDto.getCategoryId() >= 1 && expenseRequestDto.getCategoryId() <= 10 + && category.getIsDefault()) { + // category.setUser(user); + // default category + } + /* + Case 2) + !default && 키테고리 테이블의 UserId 컬럼의 값이 나와 맞으면 (= custom cateogory) + */ + else if (!category.getIsDefault() && category.getUser().getId().equals(expenseRequestDto.getUserId())) { + // custom category + } else { + throw new IllegalArgumentException("User and category are not matched properly."); + } + Expense expense = expenseConverter.toExpenseEntity(expenseRequestDto, user, category); expenseRepository.save(expense); + // 소비 목표 업데이트 + consumptionGoalService.updateConsumeAmount(expenseRequestDto.getUserId(), expenseRequestDto.getCategoryId(), + expenseRequestDto.getAmount()); + return expenseConverter.toExpenseResponseDto(expense); + /* + 결과 Case 1) 해당 유저의 user_id + immutable 필드 중 하나의 조합으로 Expense 테이블에 저장 + 결과 Case 2) 내가 직접 생성한 카테고리 중 하나로 카테고리를 설정하여 Expense 테이블에 저장 + */ } @Override @@ -82,8 +110,7 @@ public ExpenseResponseDto updateExpense(Long userId, ExpenseUpdateRequestDto req Expense expense = expenseRepository.findById(request.getExpenseId()) .orElseThrow(() -> new IllegalArgumentException("Not found expense")); - User user = userRepository.findById(userId) - .orElseThrow(() -> new IllegalArgumentException("Not found user")); + User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("Not found user")); checkUserAuthority(userId, expense); Category categoryToReplace = categoryService.handleCategoryChange(expense, request, user); diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java index 94f0d16c..0bdba4ab 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoApi.java @@ -1,6 +1,6 @@ package com.bbteam.budgetbuddies.domain.supportinfo.controller; -import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequestDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequest; import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -27,7 +27,7 @@ public interface SupportInfoApi { @Parameter(name = "page", description = "페이지 번호, 0번이 1 페이지 입니다. (기본값은 0입니다.)"), @Parameter(name = "size", description = "한 페이지에 불러올 데이터 개수입니다. (기본값은 10개입니다.)") }) - public ResponseEntity> getSupportsByYearAndMonth( + ResponseEntity> getSupportsByYearAndMonth( @RequestParam Integer year, @RequestParam Integer month, @RequestParam(defaultValue = "0") Integer page, @@ -41,8 +41,8 @@ public ResponseEntity> getSupportsByYearAndMonth( // @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))) }) - public ResponseEntity registerDiscountInfo( - @RequestBody SupportRequestDto requestDto + ResponseEntity registerSupportInfo( + @RequestBody SupportRequest.RegisterDto requestDto ); @Operation(summary = "[User] 특정 지원정보에 좋아요 클릭 API", description = "특정 지원정보에 좋아요 버튼을 클릭하는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)") @@ -56,7 +56,54 @@ public ResponseEntity registerDiscountInfo( @Parameter(name = "userId", description = "좋아요를 누른 사용자의 id입니다."), @Parameter(name = "supportInfoId", description = "좋아요를 누를 지원정보의 id입니다."), }) - public ResponseEntity likeDiscountInfo( + ResponseEntity likeSupportInfo( + @RequestParam Long userId, + @PathVariable Long supportInfoId + ); + + @Operation(summary = "[ADMIN] 특정 지원정보 수정하기 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입니다."), + }) + ResponseEntity updateSupportInfo( + @RequestParam Long userId, + @RequestBody SupportRequest.UpdateDto supportRequestDto + ); + + @Operation(summary = "[ADMIN] 특정 지원정보 삭제하기 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입니다."), + }) + ResponseEntity deleteSupportInfo( + @RequestParam Long userId, + @PathVariable Long supportInfoId + ); + + @Operation(summary = "[ADMIN] 특정 지원정보 가져오기 API", description = "ID를 통해 특정 지원정보를 가져오는 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입니다."), + }) + ResponseEntity getSupportInfo( @RequestParam Long userId, @PathVariable Long supportInfoId ); 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 index beba1301..4a5eccb9 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/controller/SupportInfoController.java @@ -1,14 +1,10 @@ package com.bbteam.budgetbuddies.domain.supportinfo.controller; -import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; -import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequestDto; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequest; 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; @@ -36,8 +32,8 @@ public ResponseEntity> getSupportsByYearAndMonth( @Override @PostMapping("") - public ResponseEntity registerDiscountInfo( - @RequestBody SupportRequestDto requestDto + public ResponseEntity registerSupportInfo( + @RequestBody SupportRequest.RegisterDto requestDto ) { SupportResponseDto supportResponseDto = supportInfoService.registerSupportInfo(requestDto); @@ -45,8 +41,8 @@ public ResponseEntity registerDiscountInfo( } @Override - @PostMapping("/{supportInfoId}/likes") - public ResponseEntity likeDiscountInfo( + @PostMapping("/likes/{supportInfoId}") + public ResponseEntity likeSupportInfo( @RequestParam Long userId, @PathVariable Long supportInfoId ) { @@ -55,4 +51,37 @@ public ResponseEntity likeDiscountInfo( return ResponseEntity.ok(supportResponseDto); } + @Override + @PutMapping("") + public ResponseEntity updateSupportInfo( + @RequestParam Long userId, + @RequestBody SupportRequest.UpdateDto supportRequestDto + ) { + SupportResponseDto supportResponseDto = supportInfoService.updateSupportInfo(userId, supportRequestDto); + + return ResponseEntity.ok(supportResponseDto); + } + + @Override + @DeleteMapping("/{supportInfoId}") + public ResponseEntity deleteSupportInfo( + @RequestParam Long userId, + @PathVariable Long supportInfoId + ) { + String message = supportInfoService.deleteSupportInfo(userId, supportInfoId); + + return ResponseEntity.ok(message); + } + + @Override + @GetMapping("/{supportInfoId}") + public ResponseEntity getSupportInfo( + @RequestParam Long userId, + @PathVariable Long supportInfoId + ) { + SupportResponseDto supportResponseDto = supportInfoService.getSupportInfoById(userId, supportInfoId); + + return ResponseEntity.ok(supportResponseDto); + } + } 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 index 8e9bd62f..5c70330b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/converter/SupportInfoConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/converter/SupportInfoConverter.java @@ -1,9 +1,6 @@ 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.SupportRequest; import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; import org.springframework.stereotype.Service; @@ -24,6 +21,7 @@ public SupportResponseDto toDto(SupportInfo entity) { .anonymousNumber(entity.getAnonymousNumber()) .likeCount(entity.getLikeCount()) .siteUrl(entity.getSiteUrl()) + .thumbnailUrl(entity.getThumbnailUrl()) .build(); } @@ -32,7 +30,7 @@ public SupportResponseDto toDto(SupportInfo entity) { * @param requestDto * @return entity */ - public SupportInfo toEntity(SupportRequestDto requestDto) { + public SupportInfo toEntity(SupportRequest.RegisterDto requestDto) { return SupportInfo.builder() .title(requestDto.getTitle()) @@ -41,6 +39,7 @@ public SupportInfo toEntity(SupportRequestDto requestDto) { .anonymousNumber(0) .likeCount(0) .siteUrl(requestDto.getSiteUrl()) + .thumbnailUrl(requestDto.getThumbnailUrl()) .build(); } } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequest.java b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequest.java new file mode 100644 index 00000000..a9ba1405 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequest.java @@ -0,0 +1,52 @@ +package com.bbteam.budgetbuddies.domain.supportinfo.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + + +public class SupportRequest { + + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class RegisterDto { + + private String title; + + private LocalDate startDate; + + private LocalDate endDate; + + private String siteUrl; + + private String thumbnailUrl; + + } + + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class UpdateDto { + + private Long id; + + private String title; + + private LocalDate startDate; + + private LocalDate endDate; + + private String siteUrl; + + private String thumbnailUrl; + + } + + +} 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 deleted file mode 100644 index ff883f7d..00000000 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportRequestDto.java +++ /dev/null @@ -1,24 +0,0 @@ -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 index b04825f7..5392e54c 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportResponseDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/dto/SupportResponseDto.java @@ -27,4 +27,6 @@ public class SupportResponseDto { private String siteUrl; + private String thumbnailUrl; + } 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 f811f7ee..93d43d0d 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 @@ -1,6 +1,8 @@ package com.bbteam.budgetbuddies.domain.supportinfo.entity; import com.bbteam.budgetbuddies.common.BaseEntity; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; +import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequest; import jakarta.persistence.Column; import jakarta.persistence.Entity; import lombok.*; @@ -32,6 +34,9 @@ public class SupportInfo extends BaseEntity { @Column(length = 1000) private String siteUrl; + @Column(length = 1000) + private String thumbnailUrl; // 카드 썸네일 이미지 + public void addLikeCount() { this.likeCount++; } @@ -45,4 +50,12 @@ public Integer addAndGetAnonymousNumber() { return anonymousNumber; } + public void update(SupportRequest.UpdateDto supportRequestDto) { + this.title = supportRequestDto.getTitle(); + this.startDate = supportRequestDto.getStartDate(); + this.endDate = supportRequestDto.getEndDate(); + this.siteUrl = supportRequestDto.getSiteUrl(); + this.thumbnailUrl = supportRequestDto.getThumbnailUrl(); + } + } 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 index bc01ebd9..b56e149f 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoService.java @@ -1,8 +1,6 @@ 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.SupportRequest; import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; import org.springframework.data.domain.Page; @@ -14,7 +12,14 @@ Page getSupportsByYearAndMonth( Integer size ); - SupportResponseDto registerSupportInfo(SupportRequestDto supportRequestDto); + SupportResponseDto registerSupportInfo(SupportRequest.RegisterDto supportRequest); SupportResponseDto toggleLike(Long userId, Long supportInfoId); -} + + SupportResponseDto updateSupportInfo(Long userId, SupportRequest.UpdateDto supportRequestDto); + + String deleteSupportInfo(Long userId, Long supportInfoId); + + SupportResponseDto getSupportInfoById(Long userId, Long supportInfoId); + +} \ No newline at end of file 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 index 25530dd8..86a781b0 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceImpl.java @@ -1,14 +1,7 @@ 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.SupportRequest; import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; import com.bbteam.budgetbuddies.domain.supportinfo.repository.SupportInfoRepository; @@ -60,13 +53,13 @@ public Page getSupportsByYearAndMonth(Integer year, Integer @Transactional @Override - public SupportResponseDto registerSupportInfo(SupportRequestDto supportRequestDto) { + public SupportResponseDto registerSupportInfo(SupportRequest.RegisterDto supportRequest) { /** * 1. RequestDto -> Entity로 변환 * 2. Entity 저장 * 3. Entity -> ResponseDto로 변환 후 리턴 */ - SupportInfo entity = supportInfoConverter.toEntity(supportRequestDto); + SupportInfo entity = supportInfoConverter.toEntity(supportRequest); supportInfoRepository.save(entity); @@ -121,4 +114,69 @@ public SupportResponseDto toggleLike(Long userId, Long supportInfoId) { return supportInfoConverter.toDto(savedEntity); } + + @Transactional + @Override + public SupportResponseDto updateSupportInfo(Long userId, SupportRequest.UpdateDto supportRequestDto) { + /** + * 1. 사용자 조회 -> 없으면 에러 + * 2. 지원정보 조회 -> 없으면 에러 + * 3. 변경사항 업데이트 + * 4. 변경사항 저장 + * 5. Entity -> ResponseDto로 변환 후 리턴 + */ + + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + + SupportInfo supportInfo = supportInfoRepository.findById(supportRequestDto.getId()) + .orElseThrow(() -> new IllegalArgumentException("SupportInfo not found")); + + supportInfo.update(supportRequestDto); // 변경사항 업데이트 + + supportInfoRepository.save(supportInfo); // 변경사항 저장 + + return supportInfoConverter.toDto(supportInfo); + } + + @Transactional + @Override + public String deleteSupportInfo(Long userId, Long supportInfoId) { + /** + * 1. 사용자 조회 -> 없으면 에러 + * 2. 지원정보 조회 -> 없으면 에러 + * 3. Entity 삭제 + * 4. 성공여부 반환 + */ + + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + + SupportInfo supportInfo = supportInfoRepository.findById(supportInfoId) + .orElseThrow(() -> new IllegalArgumentException("SupportInfo not found")); + + supportInfoRepository.deleteById(supportInfoId); + + return "Success"; + + } + + @Transactional + @Override + public SupportResponseDto getSupportInfoById(Long userId, Long supportInfoId) { + /** + * 1. 사용자 조회 -> 없으면 에러 + * 2. 지원정보 조회 -> 없으면 에러 + * 3. Entity 조회 + * 4. Entity -> ResponseDto로 변환 후 리턴 + */ + + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + + SupportInfo supportInfo = supportInfoRepository.findById(supportInfoId) + .orElseThrow(() -> new IllegalArgumentException("SupportInfo not found")); + + return supportInfoConverter.toDto(supportInfo); + } } diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java similarity index 87% rename from src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTest.java rename to src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java index 47636c82..ff919466 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/comment/service/CommentServiceTestV2.java @@ -12,10 +12,10 @@ import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; 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; @@ -39,9 +39,15 @@ */ @SpringBootTest @Transactional -class CommentServiceTest { +class CommentServiceTestV2 { + + @Qualifier("discountCommentService") + @Autowired + CommentService discountCommentService; + + @Qualifier("supportCommentService") @Autowired - CommentService commentService; + com.bbteam.budgetbuddies.domain.comment.service.CommentService supportCommentService; @Autowired UserRepository userRepository; @@ -72,10 +78,10 @@ public void saveDiscountInfoCommentTest(){ .content("굿") .build(); - commentService.saveDiscountComment(user1.getId(), dto1); + discountCommentService.saveComment(user1.getId(), dto1); em.flush(); - List returnDto = commentService.findByDiscountInfo(sale1.getId()); + List returnDto = discountCommentService.findByInfo(sale1.getId()); Assertions.assertThat(returnDto.size()).isEqualTo(1); Assertions.assertThat(returnDto.get(0).getDiscountInfoId()).isEqualTo(sale1.getId()); @@ -126,14 +132,14 @@ public void saveDiscountInfoCommentTest2(){ .content("유용해요!") .build(); - commentService.saveDiscountComment(user1.getId(), dto1); - commentService.saveDiscountComment(user2.getId(), dto2); - commentService.saveDiscountComment(user1.getId(), dto3); + discountCommentService.saveComment(user1.getId(), dto1); + discountCommentService.saveComment(user2.getId(), dto2); + discountCommentService.saveComment(user1.getId(), dto3); em.flush(); - List returnDto = commentService.findByDiscountInfo(sale1.getId()); - List returnDto2 = commentService.findByDiscountInfo(sale2.getId()); + List returnDto = discountCommentService.findByInfo(sale1.getId()); + List returnDto2 = discountCommentService.findByInfo(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()); @@ -199,16 +205,16 @@ void DiscountAnonymousCommentTest(){ .content("구웃!") .build(); - commentService.saveDiscountComment(user1.getId(), dto1); - commentService.saveDiscountComment(user2.getId(), dto2); - commentService.saveDiscountComment(user1.getId(), dto3); + discountCommentService.saveComment(user1.getId(), dto1); + discountCommentService.saveComment(user2.getId(), dto2); + discountCommentService.saveComment(user1.getId(), dto3); - commentService.saveDiscountComment(user1.getId(), dto4); - commentService.saveDiscountComment(user3.getId(), dto4); + discountCommentService.saveComment(user1.getId(), dto4); + discountCommentService.saveComment(user3.getId(), dto4); em.flush(); - List result = commentService.findByDiscountInfo(sale1.getId()); + List result = discountCommentService.findByInfo(sale1.getId()); Integer test1 = result.get(0).getAnonymousNumber(); Integer test2 = result.get(1).getAnonymousNumber(); Integer test3 = result.get(2).getAnonymousNumber(); @@ -260,14 +266,14 @@ public void saveSupportInfoCommentTest2(){ .content("유용해요!") .build(); - commentService.saveSupportComment(user1.getId(), dto1); - commentService.saveSupportComment(user2.getId(), dto2); - commentService.saveSupportComment(user1.getId(), dto3); + supportCommentService.saveComment(user1.getId(), dto1); + supportCommentService.saveComment(user2.getId(), dto2); + supportCommentService.saveComment(user1.getId(), dto3); em.flush(); - List returnDto = commentService.findBySupportInfo(info1.getId()); - List returnDto2 = commentService.findBySupportInfo(info2.getId()); + List returnDto = supportCommentService.findByInfo(info1.getId()); + List returnDto2 = supportCommentService.findByInfo(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()); @@ -347,17 +353,17 @@ void supportAnonymousCommentTest(){ .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); + supportCommentService.saveComment(user1.getId(), dto1); + supportCommentService.saveComment(user2.getId(), dto2); + supportCommentService.saveComment(user1.getId(), dto3); + supportCommentService.saveComment(user3.getId(), dto4); + supportCommentService.saveComment(user4.getId(), dto5); + supportCommentService.saveComment(user1.getId(), dto6); em.flush(); - List returnDto = commentService.findBySupportInfo(info1.getId()); - List returnDto2 = commentService.findBySupportInfo(info2.getId()); + List returnDto = supportCommentService.findByInfo(info1.getId()); + List returnDto2 = supportCommentService.findByInfo(info2.getId()); Integer test1 = returnDto.get(0).getAnonymousNumber(); Integer test2 = returnDto.get(1).getAnonymousNumber(); @@ -422,19 +428,19 @@ void DiscountInfoCommentPagingTest() { .content("구웃!") .build(); - commentService.saveDiscountComment(user1.getId(), dto1); - commentService.saveDiscountComment(user2.getId(), dto2); - commentService.saveDiscountComment(user1.getId(), dto3); + discountCommentService.saveComment(user1.getId(), dto1); + discountCommentService.saveComment(user2.getId(), dto2); + discountCommentService.saveComment(user1.getId(), dto3); - commentService.saveDiscountComment(user1.getId(), dto4); - commentService.saveDiscountComment(user3.getId(), dto4); - commentService.saveDiscountComment(user2.getId(), dto4); + discountCommentService.saveComment(user1.getId(), dto4); + discountCommentService.saveComment(user3.getId(), dto4); + discountCommentService.saveComment(user2.getId(), dto4); //sale1 = 5 em.flush(); PageRequest pageRequest1 = PageRequest.of(0, 2); - Page result1 = commentService.findByDiscountInfoWithPaging(sale1.getId(), pageRequest1); + Page result1 = discountCommentService.findByInfoWithPaging(sale1.getId(), pageRequest1); Assertions.assertThat(result1.getTotalElements()).isEqualTo(5); Assertions.assertThat(result1.getTotalPages()).isEqualTo(3); Assertions.assertThat(result1.hasNext()).isTrue(); @@ -446,7 +452,7 @@ void DiscountInfoCommentPagingTest() { PageRequest pageRequest2 = PageRequest.of(1, 3); - Page result2 = commentService.findByDiscountInfoWithPaging(sale1.getId(), pageRequest2); + Page result2 = discountCommentService.findByInfoWithPaging(sale1.getId(), pageRequest2); Assertions.assertThat(result2.getTotalElements()).isEqualTo(5); Assertions.assertThat(result2.getTotalPages()).isEqualTo(2); Assertions.assertThat(result2.hasNext()).isFalse(); @@ -523,18 +529,18 @@ void SupportInfoPagingTest() { .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); + supportCommentService.saveComment(user1.getId(), dto1); + supportCommentService.saveComment(user2.getId(), dto2); + supportCommentService.saveComment(user1.getId(), dto3); // 얘만 info2 + supportCommentService.saveComment(user3.getId(), dto4); + supportCommentService.saveComment(user4.getId(), dto5); + supportCommentService.saveComment(user1.getId(), dto6); + supportCommentService.saveComment(user2.getId(), dto5); + supportCommentService.saveComment(user3.getId(), dto5); em.flush(); PageRequest pageRequest1 = PageRequest.of(0, 2); - Page result1 = commentService.findBySupportInfoWithPaging(info1.getId(), pageRequest1); + Page result1 = supportCommentService.findByInfoWithPaging(info1.getId(), pageRequest1); Assertions.assertThat(result1.getTotalElements()).isEqualTo(7); Assertions.assertThat(result1.getTotalPages()).isEqualTo(4); @@ -546,7 +552,7 @@ void SupportInfoPagingTest() { Assertions.assertThat(list1.get(0).getAnonymousNumber()).isEqualTo(1); PageRequest pageRequest2 = PageRequest.of(1, 5); - Page result2 = commentService.findBySupportInfoWithPaging(info1.getId(), pageRequest2); + Page result2 = supportCommentService.findByInfoWithPaging(info1.getId(), pageRequest2); Assertions.assertThat(result2.getTotalElements()).isEqualTo(7); Assertions.assertThat(result2.getTotalPages()).isEqualTo(2); 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 13deca84..dc5e29e7 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 @@ -188,4 +188,48 @@ private void setUnselectedConsumptionGoal(User mainUser, LocalDate goalMonth, Ca .category(defaultCategory) .build()); } + + @Test + @DisplayName("또래 나이와 성별 정보를 통해 GoalConsumption 조회 성공") + void findTopConsumptionAndConsumeAmount_Success() { + //given + User mainUser = userRepository.save( + User.builder() + .email("email") + .age(24) + .name("name") + .gender(Gender.MALE) + .phoneNumber("010-1234-5678") + .build()); + + Category defaultCategory = categoryRepository.save( + Category.builder().name("디폴트 카테고리").user(null).isDefault(true).build()); + + LocalDate goalMonth = LocalDate.of(2024, 07, 01); + + ConsumptionGoal defaultCategoryConsumptionGoal = consumptionGoalRepository.save(ConsumptionGoal.builder() + .goalAmount(1L) + .consumeAmount(1L) + .user(mainUser) + .goalMonth(goalMonth) + .category(defaultCategory) + .build()); + + // when + int top = 4; + int peerAgeStart = 23; + int peerAgeEnd = 25; + Gender peerGender = Gender.MALE; + + List result = consumptionGoalRepository.findTopConsumptionAndConsumeAmount( + top, peerAgeStart, peerAgeEnd, peerGender); + + // then + ConsumptionGoal resultGoal = result.get(0); + assertThat(resultGoal.getGoalAmount()).isEqualTo(1L); + assertThat(resultGoal.getConsumeAmount()).isEqualTo(1L); + assertThat(resultGoal.getUser().getAge()).isEqualTo(24); + assertThat(resultGoal.getCategory().getName()).isEqualTo("디폴트 카테고리"); + assertThat(resultGoal.getUser().getGender()).isEqualTo(Gender.MALE); + } } \ No newline at end of file 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 9349c68b..5b83331f 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 @@ -31,6 +31,7 @@ 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.TopConsumptionResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO; import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; import com.bbteam.budgetbuddies.domain.consumptiongoal.repository.ConsumptionGoalRepository; @@ -287,12 +288,14 @@ void getTopCategoryAndConsumptionAmount_Success() { Category defaultCategory = Mockito.spy(Category.builder().name("디폴트 카테고리").user(null).isDefault(true).build()); given(defaultCategory.getId()).willReturn(-1L); + LocalDate goalMonthRandomDay = LocalDate.now(); + ConsumptionGoal topConsumptionGoal = ConsumptionGoal.builder() .goalAmount(5000L) .consumeAmount(3000L) .user(user) .category(defaultCategory) - .goalMonth(goalMonthRandomDay) + .goalMonth(goalMonthRandomDay.minusWeeks(1)) .build(); ConsumptionGoal currentWeekConsumptionGoal = ConsumptionGoal.builder() @@ -384,4 +387,53 @@ void getTopGoalCategories_Success() { assertThat(result.get(3).getCategoryName()).isEqualTo(defaultCategory4.getName()); assertThat(result.get(3).getGoalAmount()).isEqualTo(topConsumptionGoal4.getGoalAmount()); } + + @Test + @DisplayName("getTopConsumption : 또래들이 가장 많이 소비한 카테고리 top3 조회 성공") + void getTopConsumptionCategories_Success() { + // given + Category defaultCategory = Mockito.spy(Category.builder().name("디폴트 카테고리").user(null).isDefault(true).build()); + Category defaultCategory2 = Mockito.spy(Category.builder().name("디폴트 카테고리2").user(null).isDefault(true).build()); + Category defaultCategory3 = Mockito.spy(Category.builder().name("디폴트 카테고리3").user(null).isDefault(true).build()); + + ConsumptionGoal topConsumptionGoal1 = ConsumptionGoal.builder() + .goalAmount(5000L) + .consumeAmount(3000L) + .user(user) + .category(defaultCategory) + .goalMonth(goalMonthRandomDay) + .build(); + + ConsumptionGoal topConsumptionGoal2 = ConsumptionGoal.builder() + .goalAmount(6000L) + .consumeAmount(3000L) + .user(user) + .category(defaultCategory2) + .goalMonth(goalMonthRandomDay) + .build(); + + ConsumptionGoal topConsumptionGoal3 = ConsumptionGoal.builder() + .goalAmount(7000L) + .consumeAmount(3000L) + .user(user) + .category(defaultCategory3) + .goalMonth(goalMonthRandomDay) + .build(); + + given(userRepository.findById(user.getId())).willReturn(Optional.of(user)); + given(consumptionGoalRepository.findTopConsumptionAndConsumeAmount(3, 23, 25, Gender.MALE)).willReturn( + List.of(topConsumptionGoal1, topConsumptionGoal2, topConsumptionGoal3)); + + // when + List result = consumptionGoalService.getTopConsumption(3, user.getId(), 23, 25, "MALE"); + + // then + assertThat(result).hasSize(3); + assertThat(result.get(0).getCategoryName()).isEqualTo(defaultCategory.getName()); + assertThat(result.get(0).getConsumeAmount()).isEqualTo(topConsumptionGoal1.getConsumeAmount()); + assertThat(result.get(1).getCategoryName()).isEqualTo(defaultCategory2.getName()); + assertThat(result.get(1).getConsumeAmount()).isEqualTo(topConsumptionGoal2.getConsumeAmount()); + assertThat(result.get(2).getCategoryName()).isEqualTo(defaultCategory3.getName()); + assertThat(result.get(2).getConsumeAmount()).isEqualTo(topConsumptionGoal3.getConsumeAmount()); + } } \ No newline at end of file diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceTest.java index 3733a825..0fee5041 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/discountinfo/service/DiscountInfoServiceTest.java @@ -1,7 +1,7 @@ package com.bbteam.budgetbuddies.domain.discountinfo.service; import com.bbteam.budgetbuddies.domain.discountinfo.converter.DiscountInfoConverter; -import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto; +import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest; import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto; import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; import com.bbteam.budgetbuddies.domain.discountinfo.repository.DiscountInfoRepository; @@ -103,12 +103,13 @@ void getDiscountsByYearAndMonthTest() { @DisplayName("할인 정보 등록이 정상적으로 되는지 검증") void registerDiscountInfoTest() { // given - DiscountRequestDto requestDto = DiscountRequestDto.builder() + DiscountRequest.RegisterDto requestDto = DiscountRequest.RegisterDto.builder() .title("할인 정보 제목") .startDate(LocalDate.of(2024, 7, 1)) .endDate(LocalDate.of(2024, 7, 21)) .discountRate(30) .siteUrl("http://example.com") + .thumbnailUrl("http://example.com2") .build(); DiscountInfo entity = DiscountInfo.builder() @@ -117,6 +118,7 @@ void registerDiscountInfoTest() { .endDate(LocalDate.of(2024, 7, 21)) .discountRate(30) .siteUrl("http://example.com") + .thumbnailUrl("http://example.com2") .build(); DiscountResponseDto responseDto = DiscountResponseDto.builder() @@ -126,6 +128,7 @@ void registerDiscountInfoTest() { .endDate(LocalDate.of(2024, 7, 21)) .discountRate(30) .siteUrl("http://example.com") + .thumbnailUrl("http://example.com2") .likeCount(0) .anonymousNumber(0) .build(); 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 index 9bb09ce0..e460d8cb 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepositoryTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/repository/SupportInfoRepositoryTest.java @@ -31,6 +31,13 @@ class SupportInfoRepositoryTest { @DisplayName("@SoftDelete 테스트") void deletedTest() { // given + SupportInfo discount1 = SupportInfo.builder() + .title("지원정보1") + .startDate(LocalDate.of(2024, 7, 1)) + .endDate(LocalDate.of(2024, 7, 21)) + .siteUrl("http://example1.com") + .build(); + SupportInfo discount2 = SupportInfo.builder() .title("지원정보2") .startDate(LocalDate.of(2024, 7, 1)) diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java index c8aa3ddd..0c360ecf 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/supportinfo/service/SupportInfoServiceTest.java @@ -1,15 +1,7 @@ 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.discountinfo.service.DiscountInfoServiceImpl; -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.SupportRequest; import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto; import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; import com.bbteam.budgetbuddies.domain.supportinfo.repository.SupportInfoRepository; @@ -36,11 +28,9 @@ import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.*; -import static org.mockito.Mockito.times; @Transactional @ExtendWith(MockitoExtension.class) @@ -113,7 +103,7 @@ void getSupportsByYearAndMonthTest() { @DisplayName("지원 정보 등록이 정상적으로 되는지 검증") void registerSupportInfoTest() { // given - SupportRequestDto requestDto = SupportRequestDto.builder() + SupportRequest.RegisterDto requestDto = SupportRequest.RegisterDto.builder() .title("지원 정보 제목") .startDate(LocalDate.of(2024, 7, 1)) .endDate(LocalDate.of(2024, 7, 21)) From 3b285a364c95bed4a1e0b8e3d5848ca813832777 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Sun, 4 Aug 2024 21:42:02 +0900 Subject: [PATCH 300/307] =?UTF-8?q?[refactor]=20CommentController=20getOne?= =?UTF-8?q?,=20delete=20URL=20=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 | 6 +++--- 1 file changed, 3 insertions(+), 3 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 f77b4d33..18ba0126 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 @@ -64,13 +64,13 @@ public ResponseEntity> findAllByS return ResponseEntity.ok(result); } - @PostMapping("/comments/{commentId}/delete") + @PostMapping("/comments/delete/{commentId}") public ResponseEntity deleteComment(@PathVariable("commentId") Long commentId) { discountCommentService.deleteComment(commentId); return ResponseEntity.ok("ok"); } - @GetMapping("/supports/comments/{commentId}/getOne") + @GetMapping("/supports/comments/getOne/{commentId}") public ResponseEntity findSupportOne(@PathVariable("commentId")Long commentId) { CommentResponseDto.SupportInfoCommentDto result = supportCommentService.findCommentOne(commentId); return ResponseEntity.ok(result); @@ -83,7 +83,7 @@ public ResponseEntity modifySupportOne return ResponseEntity.ok(result); } - @GetMapping("/discounts/comments/{commentId}/getOne") + @GetMapping("/discounts/comments/getOne/{commentId}") public ResponseEntity findDiscountOne(@PathVariable("commentId")Long commentId) { CommentResponseDto.DiscountInfoCommentDto result = discountCommentService.findCommentOne(commentId); return ResponseEntity.ok(result); From 490926ef7bc58fb3576f0597d9997bbdf0b91db3 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Mon, 5 Aug 2024 15:26:32 +0900 Subject: [PATCH 301/307] =?UTF-8?q?[feat]=20=EA=B3=B5=ED=86=B5=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=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 --- .../budgetbuddies/apiPayload/ApiResponse.java | 15 +-- .../apiPayload/code/BaseCode.java | 8 +- .../apiPayload/code/BaseErrorCode.java | 4 + .../apiPayload/code/ErrorReasonDto.java | 16 +++ .../apiPayload/code/ReasonDto.java | 16 +++ .../code/status/CommonErrorStatus.java | 41 ++++++ .../apiPayload/code/status/ErrorStatus.java | 55 ++++++++ .../apiPayload/code/status/SuccessStatus.java | 9 +- .../apiPayload/exception/ExceptionAdvice.java | 125 ++++++++++++++++++ .../exception/GeneralException.java | 21 +++ 10 files changed, 293 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/apiPayload/code/ErrorReasonDto.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/apiPayload/code/ReasonDto.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/CommonErrorStatus.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/ErrorStatus.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/apiPayload/exception/ExceptionAdvice.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/apiPayload/exception/GeneralException.java diff --git a/src/main/java/com/bbteam/budgetbuddies/apiPayload/ApiResponse.java b/src/main/java/com/bbteam/budgetbuddies/apiPayload/ApiResponse.java index b9d069a0..86a85c2d 100644 --- a/src/main/java/com/bbteam/budgetbuddies/apiPayload/ApiResponse.java +++ b/src/main/java/com/bbteam/budgetbuddies/apiPayload/ApiResponse.java @@ -1,5 +1,6 @@ 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; @@ -12,7 +13,6 @@ @AllArgsConstructor @JsonPropertyOrder({"isSuccess", "code", "message", "result"}) public class ApiResponse { - @JsonProperty("isSuccess") private final Boolean isSuccess; private final String code; @@ -20,19 +20,18 @@ public class ApiResponse { @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); + 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); + 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); + return new ApiResponse<>(false, 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 index d5fb4d79..f21b4b56 100644 --- a/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/BaseCode.java +++ b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/BaseCode.java @@ -1,10 +1,8 @@ package com.bbteam.budgetbuddies.apiPayload.code; public interface BaseCode { - ReasonHttpStatus getReasonHttpStatus(); - interface ReasonHttpStatus { - String getCode(); - String getMessage(); - } + ReasonDto getReason(); + + ReasonDto getReasonHttpStatus(); } diff --git a/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/BaseErrorCode.java b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/BaseErrorCode.java index c3388e55..ee2f3d25 100644 --- a/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/BaseErrorCode.java +++ b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/BaseErrorCode.java @@ -1,4 +1,8 @@ package com.bbteam.budgetbuddies.apiPayload.code; public interface BaseErrorCode { + + ErrorReasonDto getReason(); + + ErrorReasonDto getReasonHttpStatus(); } diff --git a/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/ErrorReasonDto.java b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/ErrorReasonDto.java new file mode 100644 index 00000000..61469c9e --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/ErrorReasonDto.java @@ -0,0 +1,16 @@ +package com.bbteam.budgetbuddies.apiPayload.code; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Builder +@Getter +@AllArgsConstructor +public class ErrorReasonDto { + String message; + String code; + Boolean isSuccess; + HttpStatus httpStatus; +} diff --git a/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/ReasonDto.java b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/ReasonDto.java new file mode 100644 index 00000000..aa642b35 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/ReasonDto.java @@ -0,0 +1,16 @@ +package com.bbteam.budgetbuddies.apiPayload.code; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Builder +@AllArgsConstructor +@Getter +public class ReasonDto { + String message; + String code; + Boolean isSuccess; + HttpStatus httpStatus; +} diff --git a/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/CommonErrorStatus.java b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/CommonErrorStatus.java new file mode 100644 index 00000000..e88c7f5b --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/CommonErrorStatus.java @@ -0,0 +1,41 @@ +package com.bbteam.budgetbuddies.apiPayload.code.status; + +import com.bbteam.budgetbuddies.apiPayload.code.BaseErrorCode; +import com.bbteam.budgetbuddies.apiPayload.code.ErrorReasonDto; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum CommonErrorStatus implements BaseErrorCode { + + _INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "COMMON500", "서버에러"), + _BAD_REQUEST(HttpStatus.BAD_REQUEST, "COMMON400", "잘못된 요청입니다."), + _UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "COMMON401", "인증이 필요합니다"), + _FORBIDDEN(HttpStatus.FORBIDDEN, "COMMON403", "금지된 요청입니다."),; + + private final HttpStatus httpStatus; + private final String code; + private final String message; + + + @Override + public ErrorReasonDto getReason() { + return ErrorReasonDto.builder() + .message(message) + .code(code) + .isSuccess(false) + .build(); + } + + @Override + public ErrorReasonDto getReasonHttpStatus() { + return ErrorReasonDto.builder() + .message(message) + .code(code) + .isSuccess(false) + .httpStatus(httpStatus) + .build(); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/ErrorStatus.java b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/ErrorStatus.java new file mode 100644 index 00000000..a62e76f4 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/ErrorStatus.java @@ -0,0 +1,55 @@ +package com.bbteam.budgetbuddies.apiPayload.code.status; + +import com.bbteam.budgetbuddies.apiPayload.code.BaseErrorCode; +import com.bbteam.budgetbuddies.apiPayload.code.ErrorReasonDto; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum ErrorStatus implements BaseErrorCode { + + + _INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "COMMON500", "서버에러"), + _BAD_REQUEST(HttpStatus.BAD_REQUEST, "COMMON400", "잘못된 요청입니다."), + _UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "COMMON401", "인증이 필요합니다"), + _FORBIDDEN(HttpStatus.FORBIDDEN, "COMMON403", "금지된 요청입니다."), + MEMBER_NOT_FOUND(HttpStatus.BAD_REQUEST, "MEMBER4001", "사용자가 없습니다."), + NICKNAME_NOT_EXIST(HttpStatus.BAD_REQUEST, "MEMBER4002", "닉네임은 필수입니다."), + COMMENT_NOT_FOUND(HttpStatus.BAD_REQUEST, "COMMENT4001", "해당 댓글이 없습니다.") , + ARTICLE_NOT_FOUND(HttpStatus.NOT_FOUND, "ARTICLE4002", "게시글이 없습니다."), + TEMP_EXCEPTION(HttpStatus.BAD_REQUEST, "TEMP4001", "test"), + FOOD_CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, "FOOD_CATEGORY4004", "해당하는 음식 카테고리가 없습니다."), + STORE_NOT_FOUND(HttpStatus.NOT_FOUND, "STORE4004", "해당하는 가게는 존재하지 않습니다."), + MISSION_ALREADY_ACCEPT(HttpStatus.BAD_REQUEST, "MISSION4001", "해당 미션은 이미 수주되었습니다."), + REVIEW_ALREADY_EXIST(HttpStatus.BAD_REQUEST, "REVIEW4001","해당 가게에 리뷰를 이미 작성하셨습니다."), + PAGE_LOWER_ZERO(HttpStatus.BAD_REQUEST, "PAGE4001", "요청된 페이지가 0보다 작습니다."), + MISSION_NOT_FOUND(HttpStatus.NOT_FOUND, "MISSION4004", "해당 미션이 존재하지 않습니다."), + MISSION_ALREADY_COMPLETE(HttpStatus.BAD_REQUEST, "MISSION4001", "해당 미션은 이미 완료된 미션입니다."); + + + private HttpStatus httpStatus; + private String code; + private String message; + + + @Override + public ErrorReasonDto getReason() { + return ErrorReasonDto.builder() + .message(message) + .code(code) + .isSuccess(false) + .build(); + } + + @Override + public ErrorReasonDto getReasonHttpStatus() { + return ErrorReasonDto.builder() + .message(message) + .code(code) + .isSuccess(false) + .httpStatus(httpStatus) + .build(); + } +} 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 index 414fe213..1548603d 100644 --- a/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/SuccessStatus.java +++ b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/SuccessStatus.java @@ -1,14 +1,15 @@ package com.bbteam.budgetbuddies.apiPayload.code.status; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; @Getter -@RequiredArgsConstructor +@AllArgsConstructor public enum SuccessStatus { - OK("200", "OK"); + _OK(HttpStatus.OK, "200", "okay"); + private final HttpStatus httpStatus; private final String code; private final String message; } - diff --git a/src/main/java/com/bbteam/budgetbuddies/apiPayload/exception/ExceptionAdvice.java b/src/main/java/com/bbteam/budgetbuddies/apiPayload/exception/ExceptionAdvice.java new file mode 100644 index 00000000..6eac21e9 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/apiPayload/exception/ExceptionAdvice.java @@ -0,0 +1,125 @@ +package com.bbteam.budgetbuddies.apiPayload.exception; + + +import com.bbteam.budgetbuddies.apiPayload.ApiResponse; +import com.bbteam.budgetbuddies.apiPayload.code.ErrorReasonDto; +import com.bbteam.budgetbuddies.apiPayload.code.status.ErrorStatus; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.ConstraintViolationException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.context.request.ServletWebRequest; +import org.springframework.web.context.request.WebRequest; +import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Optional; + + +@Slf4j +@RestControllerAdvice(annotations = {RestController.class}) +public class ExceptionAdvice extends ResponseEntityExceptionHandler { + + + @org.springframework.web.bind.annotation.ExceptionHandler + public ResponseEntity validation(ConstraintViolationException e, WebRequest request) { + String errorMessage = e.getConstraintViolations().stream() + .map(constraintViolation -> constraintViolation.getMessage()) + .findFirst() + .orElseThrow(() -> new RuntimeException("ConstraintViolationException 추출 도중 에러 발생")); + + return handleExceptionInternalConstraint(e, ErrorStatus.valueOf(errorMessage), HttpHeaders.EMPTY,request); + } + + + @Override + protected ResponseEntity handleMethodArgumentNotValid( + MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { + Map errors = new LinkedHashMap<>(); + + ex.getBindingResult().getFieldErrors().stream() + .forEach(fieldError -> { + String fieldName = fieldError.getField(); + String errorMessage = Optional.ofNullable(fieldError.getDefaultMessage()).orElse(""); + errors.merge(fieldName, errorMessage, (existingErrorMessage, newErrorMessage) -> existingErrorMessage + ", " + newErrorMessage); + }); + + return handleExceptionInternalArgs(ex,HttpHeaders.EMPTY,ErrorStatus.valueOf("_BAD_REQUEST"),request,errors); + } + + + @org.springframework.web.bind.annotation.ExceptionHandler + public ResponseEntity exception(Exception e, WebRequest request) { + e.printStackTrace(); + + return handleExceptionInternalFalse(e, ErrorStatus._INTERNAL_SERVER_ERROR, HttpHeaders.EMPTY, ErrorStatus._INTERNAL_SERVER_ERROR.getHttpStatus(),request, e.getMessage()); + } + + @ExceptionHandler(value = GeneralException.class) + public ResponseEntity onThrowException(GeneralException generalException, HttpServletRequest request) { + ErrorReasonDto errorReasonHttpStatus = generalException.getErrorReasonHttpStatus(); + return handleExceptionInternal(generalException,errorReasonHttpStatus,null,request); + } + + private ResponseEntity handleExceptionInternal(Exception e, ErrorReasonDto reason, + HttpHeaders headers, HttpServletRequest request) { + + ApiResponse body = ApiResponse.onFailure(reason.getCode(),reason.getMessage(),null); +// e.printStackTrace(); + + WebRequest webRequest = new ServletWebRequest(request); + return super.handleExceptionInternal( + e, + body, + headers, + reason.getHttpStatus(), + webRequest + ); + } + + private ResponseEntity handleExceptionInternalFalse(Exception e, ErrorStatus errorCommonStatus, + HttpHeaders headers, HttpStatus status, WebRequest request, String errorPoint) { + ApiResponse body = ApiResponse.onFailure(errorCommonStatus.getCode(),errorCommonStatus.getMessage(),errorPoint); + return super.handleExceptionInternal( + e, + body, + headers, + status, + request + ); + } + + private ResponseEntity handleExceptionInternalArgs(Exception e, HttpHeaders headers, ErrorStatus errorCommonStatus, + WebRequest request, Map errorArgs) { + ApiResponse body = ApiResponse.onFailure(errorCommonStatus.getCode(),errorCommonStatus.getMessage(),errorArgs); + return super.handleExceptionInternal( + e, + body, + headers, + errorCommonStatus.getHttpStatus(), + request + ); + } + + private ResponseEntity handleExceptionInternalConstraint(Exception e, ErrorStatus errorCommonStatus, + HttpHeaders headers, WebRequest request) { + ApiResponse body = ApiResponse.onFailure(errorCommonStatus.getCode(), errorCommonStatus.getMessage(), null); + return super.handleExceptionInternal( + e, + body, + headers, + errorCommonStatus.getHttpStatus(), + request + ); + } +} + + diff --git a/src/main/java/com/bbteam/budgetbuddies/apiPayload/exception/GeneralException.java b/src/main/java/com/bbteam/budgetbuddies/apiPayload/exception/GeneralException.java new file mode 100644 index 00000000..79d2abbc --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/apiPayload/exception/GeneralException.java @@ -0,0 +1,21 @@ +package com.bbteam.budgetbuddies.apiPayload.exception; + +import com.bbteam.budgetbuddies.apiPayload.code.BaseErrorCode; +import com.bbteam.budgetbuddies.apiPayload.code.ErrorReasonDto; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class GeneralException extends RuntimeException{ + + private BaseErrorCode code; + + public ErrorReasonDto getErrorReason(){ + return this.code.getReason(); + } + + public ErrorReasonDto getErrorReasonHttpStatus(){ + return this.code.getReasonHttpStatus(); + } +} From 613dab94b060f0ec04501cb731b42dde74376490 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Mon, 5 Aug 2024 15:26:49 +0900 Subject: [PATCH 302/307] =?UTF-8?q?[feat]=20comment=20valid=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 | 41 +++++++++++-------- .../controller/CommentControllerApi.java | 24 +++++++---- .../validation/CommentExistValidation.java | 37 +++++++++++++++++ .../comment/validation/ExistComment.java | 17 ++++++++ 4 files changed, 92 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/validation/CommentExistValidation.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/comment/validation/ExistComment.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 18ba0126..7a415d8b 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,16 +1,21 @@ package com.bbteam.budgetbuddies.domain.comment.controller; +import com.bbteam.budgetbuddies.apiPayload.ApiResponse; 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 com.bbteam.budgetbuddies.domain.comment.validation.ExistComment; +import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Qualifier; 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.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @RestController +@Validated public class CommentController implements CommentControllerApi { @Qualifier("discountCommentService") @@ -30,70 +35,70 @@ public CommentController(CommentService saveDiscountInfoComment( + public ApiResponse saveDiscountInfoComment( @RequestParam("userId") Long userId, @RequestBody CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto){ CommentResponseDto.DiscountInfoCommentDto dto = discountCommentService.saveComment(userId, discountInfoCommentDto); - return ResponseEntity.ok(dto); + return ApiResponse.onSuccess(dto); } @GetMapping("/discounts/{discountInfoId}/comments") - public ResponseEntity> findAllByDiscountInfo( + public ApiResponse> findAllByDiscountInfo( @PathVariable("discountInfoId") Long discountInfoId, @PageableDefault(size = 20, page = 0) Pageable pageable){ Page result = discountCommentService.findByInfoWithPaging(discountInfoId, pageable); - return ResponseEntity.ok(result); + return ApiResponse.onSuccess(result); } @PostMapping("/supports/comments") - public ResponseEntity saveSupportInfoComment( + public ApiResponse saveSupportInfoComment( @RequestParam("userId") Long userId, @RequestBody CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto){ CommentResponseDto.SupportInfoCommentDto dto = supportCommentService.saveComment(userId, supportInfoCommentDto); - return ResponseEntity.ok(dto); + return ApiResponse.onSuccess(dto); } @GetMapping("/supports/{supportInfoId}/comments") - public ResponseEntity> findAllBySupportInfo( + public ApiResponse> findAllBySupportInfo( @PathVariable("supportInfoId") Long supportInfoId, @PageableDefault(size = 20, page = 0)Pageable pageable){ Page result = supportCommentService.findByInfoWithPaging(supportInfoId, pageable); - return ResponseEntity.ok(result); + return ApiResponse.onSuccess(result); } @PostMapping("/comments/delete/{commentId}") - public ResponseEntity deleteComment(@PathVariable("commentId") Long commentId) { + public ApiResponse deleteComment(@PathVariable("commentId") @ExistComment Long commentId) { discountCommentService.deleteComment(commentId); - return ResponseEntity.ok("ok"); + return ApiResponse.onSuccess("ok"); } @GetMapping("/supports/comments/getOne/{commentId}") - public ResponseEntity findSupportOne(@PathVariable("commentId")Long commentId) { + public ApiResponse findSupportOne(@PathVariable("commentId")Long commentId) { CommentResponseDto.SupportInfoCommentDto result = supportCommentService.findCommentOne(commentId); - return ResponseEntity.ok(result); + return ApiResponse.onSuccess(result); } @PostMapping("/supports/comments/modify") - public ResponseEntity modifySupportOne( + public ApiResponse modifySupportOne( @RequestBody CommentRequestDto.CommentModifyDto dto) { CommentResponseDto.SupportInfoCommentDto result = supportCommentService.modifyComment(dto); - return ResponseEntity.ok(result); + return ApiResponse.onSuccess(result); } @GetMapping("/discounts/comments/getOne/{commentId}") - public ResponseEntity findDiscountOne(@PathVariable("commentId")Long commentId) { + public ApiResponse findDiscountOne(@PathVariable("commentId")Long commentId) { CommentResponseDto.DiscountInfoCommentDto result = discountCommentService.findCommentOne(commentId); - return ResponseEntity.ok(result); + return ApiResponse.onSuccess(result); } @PostMapping("/discounts/comments/modify") - public ResponseEntity modifyDiscountOne( + public ApiResponse modifyDiscountOne( @RequestBody CommentRequestDto.CommentModifyDto dto) { CommentResponseDto.DiscountInfoCommentDto result = discountCommentService.modifyComment(dto); - return ResponseEntity.ok(result); + return ApiResponse.onSuccess(result); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java index 1a2a396b..49466062 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java @@ -1,18 +1,24 @@ package com.bbteam.budgetbuddies.domain.comment.controller; +import com.bbteam.budgetbuddies.apiPayload.ApiResponse; import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; +import com.bbteam.budgetbuddies.domain.comment.validation.ExistComment; 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 jakarta.validation.Valid; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +@RestController public interface CommentControllerApi { @Operation(summary = "[User] 특정 할인 정보 게시글에 댓글달기", description = "특정 할인 정보 게시글에 댓글을 다는 API입니다.") @ApiResponses({ @@ -23,7 +29,7 @@ public interface CommentControllerApi { @Parameter(name = "discountInfoId", description = "댓글을 다는 할인 정보 게시글 id입니다. requestBody"), @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), }) - ResponseEntity saveDiscountInfoComment( + ApiResponse saveDiscountInfoComment( Long userId, CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto); @@ -37,7 +43,7 @@ ResponseEntity saveDiscountInfoCommen @Parameter(name = "page", description = "페이징을 위한 페이지 번호입니다. 0부터 시작합니다. parameter"), @Parameter(name = "size", description = "페이징을 위한 페이지 사이즈입니다. default는 20입니다. parameter") }) - ResponseEntity> findAllByDiscountInfo( + ApiResponse> findAllByDiscountInfo( Long discountInfoId, Pageable pageable); @@ -50,7 +56,7 @@ ResponseEntity> findAllByDiscoun @Parameter(name = "supportInfoId", description = "댓글을 다는 지원 정보 게시글 id입니다. requestBody"), @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), }) - ResponseEntity saveSupportInfoComment( + ApiResponse saveSupportInfoComment( Long userId, CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto); @@ -65,7 +71,7 @@ ResponseEntity saveSupportInfoComment( }) - ResponseEntity> findAllBySupportInfo( + ApiResponse> findAllBySupportInfo( Long supportInfoId, Pageable pageable); @@ -76,7 +82,7 @@ ResponseEntity> findAllBySupportI @Parameters({ @Parameter(name = "commentId", description = "삭제할 댓글 id 입니다. pathVariable") }) - ResponseEntity deleteComment(Long commentId); + public ApiResponse deleteComment(@PathVariable("commentId") @ExistComment Long commentId); @Operation(summary = "[User] SupportInfo의 댓글 요청 API ", description = "특정 댓글을 요청하는 API입니다.") @ApiResponses({ @@ -85,7 +91,7 @@ ResponseEntity> findAllBySupportI @Parameters({ @Parameter(name = "commentId", description = "조회할 댓글 id 입니다. pathVariable") }) - ResponseEntity findSupportOne(@RequestParam("commentId")Long commentId); + ApiResponse findSupportOne(@RequestParam("commentId")Long commentId); @Operation(summary = "[User] SupportInfo의 댓글 변경 API", description = "특정 댓글을 변경하는 API입니다.") @ApiResponses({ @@ -96,7 +102,7 @@ ResponseEntity> findAllBySupportI @Parameter(name = "content", description = "변경할 댓글 내용입니다.. requestbody") }) - ResponseEntity modifySupportOne( + ApiResponse modifySupportOne( @RequestBody CommentRequestDto.CommentModifyDto dto); @@ -107,7 +113,7 @@ ResponseEntity modifySupportOne( @Parameters({ @Parameter(name = "commentId", description = "조회할 댓글 id 입니다. pathVariable") }) - ResponseEntity findDiscountOne(@RequestParam("commentId")Long commentId); + ApiResponse findDiscountOne(@RequestParam("commentId")Long commentId); @Operation(summary = "[User] DiscountInfo의 댓글 변경 API", description = "특정 댓글을 변경하는 API입니다.") @ApiResponses({ @@ -118,7 +124,7 @@ ResponseEntity modifySupportOne( @Parameter(name = "content", description = "변경할 댓글 내용입니다.. requestbody") }) - ResponseEntity modifyDiscountOne( + ApiResponse modifyDiscountOne( @RequestBody CommentRequestDto.CommentModifyDto dto); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/validation/CommentExistValidation.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/validation/CommentExistValidation.java new file mode 100644 index 00000000..f2395f3b --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/validation/CommentExistValidation.java @@ -0,0 +1,37 @@ +package com.bbteam.budgetbuddies.domain.comment.validation; + +import com.bbteam.budgetbuddies.apiPayload.code.status.ErrorStatus; +import com.bbteam.budgetbuddies.domain.comment.entity.Comment; +import com.bbteam.budgetbuddies.domain.comment.repository.CommentRepository; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +import java.lang.annotation.Annotation; +import java.util.Optional; + +@RequiredArgsConstructor +@Slf4j +public class CommentExistValidation implements ConstraintValidator { + private final CommentRepository commentRepository; + + @Override + public boolean isValid(Long aLong, ConstraintValidatorContext constraintValidatorContext) { + Optional comment = commentRepository.findById(aLong); + + log.info("comment.isEmpty={}", comment.isEmpty()); + if(comment.isEmpty()) { + constraintValidatorContext.disableDefaultConstraintViolation(); + constraintValidatorContext.buildConstraintViolationWithTemplate(ErrorStatus.COMMENT_NOT_FOUND.toString()).addConstraintViolation(); + return false; + } + log.info("test pass"); + return true; + } + + @Override + public void initialize(ExistComment constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + } +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/validation/ExistComment.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/validation/ExistComment.java new file mode 100644 index 00000000..aa721422 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/validation/ExistComment.java @@ -0,0 +1,17 @@ +package com.bbteam.budgetbuddies.domain.comment.validation; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; + +import java.lang.annotation.*; + +@Documented +@Constraint(validatedBy = CommentExistValidation.class) +@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +public @interface ExistComment { + + String message() default "해당 comment가 존재하지 않습니다."; + Class[] groups() default {}; + Class[] payload() default {}; +} From 30d8254b63471539c775d6bae4bb374923d502bd Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Mon, 5 Aug 2024 15:49:16 +0900 Subject: [PATCH 303/307] =?UTF-8?q?[feat]=20CommentController=20User=20val?= =?UTF-8?q?idation=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/comment/controller/CommentController.java | 5 +++-- .../domain/comment/controller/CommentControllerApi.java | 5 +++-- .../domain/comment/validation/CommentExistValidation.java | 2 -- 3 files changed, 6 insertions(+), 6 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 7a415d8b..9fad3bb4 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 @@ -5,6 +5,7 @@ import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; import com.bbteam.budgetbuddies.domain.comment.service.CommentService; import com.bbteam.budgetbuddies.domain.comment.validation.ExistComment; +import com.bbteam.budgetbuddies.domain.user.validation.ExistUser; import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.domain.Page; @@ -36,7 +37,7 @@ public CommentController(CommentService saveDiscountInfoComment( - @RequestParam("userId") Long userId, + @RequestParam("userId") @ExistUser Long userId, @RequestBody CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto){ CommentResponseDto.DiscountInfoCommentDto dto = discountCommentService.saveComment(userId, discountInfoCommentDto); return ApiResponse.onSuccess(dto); @@ -54,7 +55,7 @@ public ApiResponse> findAllByDis @PostMapping("/supports/comments") public ApiResponse saveSupportInfoComment( - @RequestParam("userId") Long userId, + @RequestParam("userId") @ExistUser Long userId, @RequestBody CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto){ CommentResponseDto.SupportInfoCommentDto dto = supportCommentService.saveComment(userId, supportInfoCommentDto); return ApiResponse.onSuccess(dto); diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java index 49466062..bd26e8d2 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java @@ -5,6 +5,7 @@ import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; import com.bbteam.budgetbuddies.domain.comment.validation.ExistComment; +import com.bbteam.budgetbuddies.domain.user.validation.ExistUser; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; @@ -30,7 +31,7 @@ public interface CommentControllerApi { @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), }) ApiResponse saveDiscountInfoComment( - Long userId, + @ExistUser Long userId, CommentRequestDto.DiscountInfoCommentDto discountInfoCommentDto); @@ -57,7 +58,7 @@ ApiResponse> findAllByDiscountIn @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), }) ApiResponse saveSupportInfoComment( - Long userId, + @ExistUser Long userId, CommentRequestDto.SupportInfoCommentDto supportInfoCommentDto); @Operation(summary = "[User] 특정 지원 정보 게시글의 댓글 조회하기", description = "특정 지원 정보 게시글의 댓글을 가져오는 API입니다.") diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/validation/CommentExistValidation.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/validation/CommentExistValidation.java index f2395f3b..fb63bf58 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/validation/CommentExistValidation.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/validation/CommentExistValidation.java @@ -20,13 +20,11 @@ public class CommentExistValidation implements ConstraintValidator comment = commentRepository.findById(aLong); - log.info("comment.isEmpty={}", comment.isEmpty()); if(comment.isEmpty()) { constraintValidatorContext.disableDefaultConstraintViolation(); constraintValidatorContext.buildConstraintViolationWithTemplate(ErrorStatus.COMMENT_NOT_FOUND.toString()).addConstraintViolation(); return false; } - log.info("test pass"); return true; } From eb5144e4d144663cd5c30e26f7edac2d674f27c4 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Mon, 5 Aug 2024 15:49:28 +0900 Subject: [PATCH 304/307] =?UTF-8?q?[feat]=20ErrorStatus=20user=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20status=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../budgetbuddies/apiPayload/code/status/ErrorStatus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/ErrorStatus.java b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/ErrorStatus.java index a62e76f4..94ca9de9 100644 --- a/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/ErrorStatus.java +++ b/src/main/java/com/bbteam/budgetbuddies/apiPayload/code/status/ErrorStatus.java @@ -15,7 +15,7 @@ public enum ErrorStatus implements BaseErrorCode { _BAD_REQUEST(HttpStatus.BAD_REQUEST, "COMMON400", "잘못된 요청입니다."), _UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "COMMON401", "인증이 필요합니다"), _FORBIDDEN(HttpStatus.FORBIDDEN, "COMMON403", "금지된 요청입니다."), - MEMBER_NOT_FOUND(HttpStatus.BAD_REQUEST, "MEMBER4001", "사용자가 없습니다."), + USER_NOT_FOUND(HttpStatus.BAD_REQUEST, "USER4001", "사용자가 없습니다."), NICKNAME_NOT_EXIST(HttpStatus.BAD_REQUEST, "MEMBER4002", "닉네임은 필수입니다."), COMMENT_NOT_FOUND(HttpStatus.BAD_REQUEST, "COMMENT4001", "해당 댓글이 없습니다.") , ARTICLE_NOT_FOUND(HttpStatus.NOT_FOUND, "ARTICLE4002", "게시글이 없습니다."), From 1eadd62871646a5eb0a2789ec8e2eecb47056852 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Mon, 5 Aug 2024 15:49:55 +0900 Subject: [PATCH 305/307] =?UTF-8?q?[feat]=20ExistUser=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=20=EA=B2=80=EC=A6=9D=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/validation/ExistUser.java | 18 ++++++++++ .../user/validation/UserExistValidation.java | 34 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/validation/ExistUser.java create mode 100644 src/main/java/com/bbteam/budgetbuddies/domain/user/validation/UserExistValidation.java diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/validation/ExistUser.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/validation/ExistUser.java new file mode 100644 index 00000000..6765c58c --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/user/validation/ExistUser.java @@ -0,0 +1,18 @@ +package com.bbteam.budgetbuddies.domain.user.validation; + +import com.bbteam.budgetbuddies.domain.comment.validation.CommentExistValidation; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; + +import java.lang.annotation.*; + +@Documented +@Constraint(validatedBy = UserExistValidation.class) +@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +public @interface ExistUser { + + String message() default "해당 user가 존재하지 않습니다."; + Class[] groups() default {}; + Class[] payload() default {}; +} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/validation/UserExistValidation.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/validation/UserExistValidation.java new file mode 100644 index 00000000..3c636ba7 --- /dev/null +++ b/src/main/java/com/bbteam/budgetbuddies/domain/user/validation/UserExistValidation.java @@ -0,0 +1,34 @@ +package com.bbteam.budgetbuddies.domain.user.validation; + +import com.bbteam.budgetbuddies.apiPayload.code.status.ErrorStatus; +import com.bbteam.budgetbuddies.domain.comment.entity.Comment; +import com.bbteam.budgetbuddies.domain.user.entity.User; +import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; +import lombok.RequiredArgsConstructor; + +import java.util.Optional; + +@RequiredArgsConstructor +public class UserExistValidation implements ConstraintValidator { + + private final UserRepository userRepository; + + @Override + public boolean isValid(Long aLong, ConstraintValidatorContext constraintValidatorContext) { + Optional foundUser = userRepository.findById(aLong); + + if(foundUser.isEmpty()) { + constraintValidatorContext.disableDefaultConstraintViolation(); + constraintValidatorContext.buildConstraintViolationWithTemplate(ErrorStatus.USER_NOT_FOUND.toString()).addConstraintViolation(); + return false; + } + return true; + } + + @Override + public void initialize(ExistUser constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + } +} From d6fb5b21c964228985be46d6a3361059377d98fd Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Wed, 7 Aug 2024 14:49:29 +0900 Subject: [PATCH 306/307] =?UTF-8?q?[refactor]=20CommentController=20Http?= =?UTF-8?q?=20method=20=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 | 8 +++----- .../domain/comment/controller/CommentControllerApi.java | 4 ++-- 2 files changed, 5 insertions(+), 7 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 9fad3bb4..8254f21e 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 @@ -70,7 +70,7 @@ public ApiResponse> findAllBySupp return ApiResponse.onSuccess(result); } - @PostMapping("/comments/delete/{commentId}") + @DeleteMapping("/comments/delete/{commentId}") public ApiResponse deleteComment(@PathVariable("commentId") @ExistComment Long commentId) { discountCommentService.deleteComment(commentId); return ApiResponse.onSuccess("ok"); @@ -82,7 +82,7 @@ public ApiResponse findSupportOne(@Pat return ApiResponse.onSuccess(result); } - @PostMapping("/supports/comments/modify") + @PutMapping("/supports/comments/modify") public ApiResponse modifySupportOne( @RequestBody CommentRequestDto.CommentModifyDto dto) { CommentResponseDto.SupportInfoCommentDto result = supportCommentService.modifyComment(dto); @@ -95,13 +95,11 @@ public ApiResponse findDiscountOne(@P return ApiResponse.onSuccess(result); } - @PostMapping("/discounts/comments/modify") + @PutMapping("/discounts/comments/modify") public ApiResponse modifyDiscountOne( @RequestBody CommentRequestDto.CommentModifyDto dto) { CommentResponseDto.DiscountInfoCommentDto result = discountCommentService.modifyComment(dto); return ApiResponse.onSuccess(result); } - - } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java index bd26e8d2..9054b374 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java @@ -85,7 +85,7 @@ ApiResponse> findAllBySupportInfo }) public ApiResponse deleteComment(@PathVariable("commentId") @ExistComment Long commentId); - @Operation(summary = "[User] SupportInfo의 댓글 요청 API ", description = "특정 댓글을 요청하는 API입니다.") + @Operation(summary = "[User] SupportInfo의 특정 댓글 요청 API ", description = "특정 댓글을 요청하는 API입니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) @@ -107,7 +107,7 @@ ApiResponse modifySupportOne( @RequestBody CommentRequestDto.CommentModifyDto dto); - @Operation(summary = "[User] DiscountInfo의 댓글 요청 API ", description = "특정 댓글을 요청하는 API입니다.") + @Operation(summary = "[User] DiscountInfo의 특정 댓글 요청 API", description = "특정 댓글을 요청하는 API입니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) From c54456b02e9af596fc87c14f035c7f3bb9d31a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=9E=AC=ED=98=81?= Date: Thu, 8 Aug 2024 02:03:17 +0900 Subject: [PATCH 307/307] =?UTF-8?q?=EB=8F=99=EC=9E=91=20=EA=B8=B0=EC=A4=80?= =?UTF-8?q?=20=EB=B8=8C=EB=9E=9C=EC=B9=98=20dev=20->=20main=20=EB=B8=8C?= =?UTF-8?q?=EB=9E=9C=EC=B9=98=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 main 브랜치로 push할 때 동작 --- .github/workflows/gradle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index d6b47f1f..3df82ec4 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -4,7 +4,7 @@ name: server on: push: branches: - - dev + - main permissions: contents: read @@ -43,4 +43,4 @@ jobs: key: ${{ secrets.PRIVATE_KEY }} host: ${{ secrets.HOST_DEV }} username: ${{ secrets.USERNAME }} - script: ${{ secrets.SCRIPT }} \ No newline at end of file + script: ${{ secrets.SCRIPT }}