From db315dd5e28417e87907725d5cda9b03f5d3624f Mon Sep 17 00:00:00 2001 From: LeeJaeHyeok97 Date: Tue, 9 Jan 2024 23:47:12 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20financialProduct=20=EB=B6=81=EB=A7=88?= =?UTF-8?q?=ED=81=AC=20=EC=A1=B0=ED=9A=8C=20=EB=B0=A9=EC=8B=9D=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 --- .../PolicyInfoBookmarkServiceImpl.java | 6 +-- .../dto/FinancialProductBookmarkRes.java | 37 +++++++++++-------- .../product/domain/FinancialProduct.java | 4 ++ 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/finfellows/domain/bookmark/application/PolicyInfoBookmarkServiceImpl.java b/src/main/java/com/finfellows/domain/bookmark/application/PolicyInfoBookmarkServiceImpl.java index 67919d4..7e761b8 100644 --- a/src/main/java/com/finfellows/domain/bookmark/application/PolicyInfoBookmarkServiceImpl.java +++ b/src/main/java/com/finfellows/domain/bookmark/application/PolicyInfoBookmarkServiceImpl.java @@ -66,10 +66,10 @@ public Message delete(UserPrincipal userPrincipal, Long id) { .build(); } + @Transactional public ResponseCustom findBookmarks(UserPrincipal userPrincipal) { - Optional optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); - - User user = optionalUser.get(); + User user = userRepository.findByEmail(userPrincipal.getEmail()) + .orElseThrow(RuntimeException::new); List bookmarks = policyInfoBookmarkRepository.findAllByUser(user); diff --git a/src/main/java/com/finfellows/domain/bookmark/dto/FinancialProductBookmarkRes.java b/src/main/java/com/finfellows/domain/bookmark/dto/FinancialProductBookmarkRes.java index cedb229..552a62c 100644 --- a/src/main/java/com/finfellows/domain/bookmark/dto/FinancialProductBookmarkRes.java +++ b/src/main/java/com/finfellows/domain/bookmark/dto/FinancialProductBookmarkRes.java @@ -3,10 +3,12 @@ import com.finfellows.domain.bookmark.domain.CmaBookmark; import com.finfellows.domain.bookmark.domain.FinancialProductBookmark; import com.finfellows.domain.product.domain.FinancialProduct; +import com.finfellows.domain.product.domain.FinancialProductOption; import com.finfellows.domain.product.domain.FinancialProductType; import lombok.Builder; import lombok.Data; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -15,35 +17,40 @@ public class FinancialProductBookmarkRes { private FinancialProductType financialProductType; private String companyName; private String productName; - private Integer maxLimit; - private String maturityInterestRate; + private String interestRate; + private String maximumPreferredInterestRate; + @Builder - public FinancialProductBookmarkRes(FinancialProductType financialProductType, String companyName, String productName, Integer maxLimit, String maturityInterestRate) { + public FinancialProductBookmarkRes(FinancialProductType financialProductType, String companyName, String productName, String interestRate, String maximumPreferredInterestRate) { this.financialProductType = financialProductType; this.companyName = companyName; this.productName = productName; - this.maxLimit = maxLimit; - this.maturityInterestRate = maturityInterestRate; + this.interestRate = interestRate; + this.maximumPreferredInterestRate = maximumPreferredInterestRate; } + public static List toDto(List bookmarks) { + List results = new ArrayList<>(); + for (FinancialProductBookmark bookmark : bookmarks) { + FinancialProduct financialProduct = bookmark.getFinancialProduct(); + for (FinancialProductOption financialProductOption : financialProduct.getFinancialProductOption()) { + FinancialProductType financialProductType = financialProduct.getFinancialProductType(); + String companyName = financialProduct.getCompanyName(); + String productName = financialProduct.getProductName(); + String interestRate = financialProductOption.getInterestRate(); + String maximumPreferredInterestRate = financialProductOption.getMaximumPreferredInterestRate(); + results.add(new FinancialProductBookmarkRes(financialProductType, companyName, productName, interestRate, maximumPreferredInterestRate)); + } + } - public static List toDto(List bookmarks) { - return bookmarks.stream() - .map(bookmark -> FinancialProductBookmarkRes.builder() - .financialProductType(bookmark.getFinancialProduct().getFinancialProductType()) - .companyName(bookmark.getFinancialProduct().getCompanyName()) - .productName(bookmark.getFinancialProduct().getProductName()) - .maturityInterestRate(bookmark.getFinancialProduct().getMaturityInterestRate()) - .maxLimit(bookmark.getFinancialProduct().getMaxLimit()) - .build()) - .collect(Collectors.toList()); + return results; } diff --git a/src/main/java/com/finfellows/domain/product/domain/FinancialProduct.java b/src/main/java/com/finfellows/domain/product/domain/FinancialProduct.java index 39653fe..78d2778 100644 --- a/src/main/java/com/finfellows/domain/product/domain/FinancialProduct.java +++ b/src/main/java/com/finfellows/domain/product/domain/FinancialProduct.java @@ -10,6 +10,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.List; @Entity @Table(name = "Financial_Product") @@ -74,6 +75,9 @@ public class FinancialProduct extends BaseEntity { @Column(name = "financial_product_type") private FinancialProductType financialProductType; + @OneToMany(mappedBy = "financialProduct", fetch = FetchType.LAZY) + private List financialProductOption; + @Builder public FinancialProduct(String financialCompanyNo, String financialProductCode, String topFinancialGroupNo, String disclosureMonth, String companyName, String productName, String joinWay, String maturityInterestRate, String specialCondition, Integer joinDeny, String joinMember, String etcNote, Integer maxLimit, LocalDate disclosureStartDay, LocalDate disclosureEndDay, LocalDateTime financialCompanySubmissionDay, FinancialProductType financialProductType) { this.financialCompanyNo = financialCompanyNo;