From 9871091dedf2999b458cf6074488ce625ca1932d Mon Sep 17 00:00:00 2001 From: LeeJaeHyeok97 Date: Thu, 18 Jan 2024 01:37:02 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]:=20=EA=B8=88=EC=9C=B5,=20=EB=AD=90?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=9D=91=EB=8B=B5=EC=97=90=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FinancialProductBookmarkServiceImpl.java | 6 ++- .../domain/bookmark/dto/CmaBookmarkRes.java | 38 +++++++++++++------ .../dto/FinancialProductBookmarkRes.java | 29 ++++++++------ 3 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java b/src/main/java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java index 96ff22a..05491e9 100644 --- a/src/main/java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java +++ b/src/main/java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java @@ -9,6 +9,7 @@ import com.finfellows.domain.bookmark.dto.FinancialProductBookmarkRes; import com.finfellows.domain.product.domain.CMA; import com.finfellows.domain.product.domain.FinancialProduct; +import com.finfellows.domain.product.domain.repository.BankRepository; import com.finfellows.domain.product.domain.repository.CmaRepository; import com.finfellows.domain.product.domain.repository.FinancialProductRepository; import com.finfellows.domain.user.domain.User; @@ -36,6 +37,7 @@ public class FinancialProductBookmarkServiceImpl implements BookmarkService{ private final FinancialProductRepository financialProductRepository; private final CmaRepository cmaRepository; private final CmaBookmarkRepository cmaBookmarkRepository; + private final BankRepository bankRepository; @Transactional @@ -96,8 +98,8 @@ public ResponseCustom findBookmarks(UserPrincipa List cmaBookmarks = cmaBookmarkRepository.findAllByUser(user); - List financialProductBookmarkResList = FinancialProductBookmarkRes.toDto(bookmarks); - List cmaBookmarkResList = CmaBookmarkRes.toDto(cmaBookmarks); + List financialProductBookmarkResList = FinancialProductBookmarkRes.toDto(bookmarks, bankRepository); + List cmaBookmarkResList = CmaBookmarkRes.toDto(cmaBookmarks, bankRepository); CmaFinancialProductBookmarkRes cmaFinancialProductBookmarkRes = new CmaFinancialProductBookmarkRes(financialProductBookmarkResList, cmaBookmarkResList); diff --git a/src/main/java/com/finfellows/domain/bookmark/dto/CmaBookmarkRes.java b/src/main/java/com/finfellows/domain/bookmark/dto/CmaBookmarkRes.java index a2d5024..a1afc30 100644 --- a/src/main/java/com/finfellows/domain/bookmark/dto/CmaBookmarkRes.java +++ b/src/main/java/com/finfellows/domain/bookmark/dto/CmaBookmarkRes.java @@ -1,8 +1,13 @@ package com.finfellows.domain.bookmark.dto; import com.finfellows.domain.bookmark.domain.CmaBookmark; +import com.finfellows.domain.product.domain.Bank; +import com.finfellows.domain.product.domain.repository.BankRepository; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; import java.util.List; import java.util.stream.Collectors; @@ -16,10 +21,13 @@ public class CmaBookmarkRes { private String cmaType; private String maturityInterestRate; private String specialCondition; + private String bankLogoUrl; + + @Builder - public CmaBookmarkRes(Boolean isLiked, Long cmaId, String companyName, String productName, String cmaType, String maturityInterestRate, String specialCondition) { + public CmaBookmarkRes(Boolean isLiked, Long cmaId, String companyName, String productName, String cmaType, String maturityInterestRate, String specialCondition, String bankLogoUrl) { this.isLiked = isLiked; this.cmaId = cmaId; this.companyName = companyName; @@ -27,23 +35,31 @@ public CmaBookmarkRes(Boolean isLiked, Long cmaId, String companyName, String pr this.cmaType = cmaType; this.maturityInterestRate = maturityInterestRate; this.specialCondition = specialCondition; + this.bankLogoUrl = bankLogoUrl; } - public static List toDto(List cmaBookmarks) { + public static List toDto(List cmaBookmarks, BankRepository bankRepository) { + return cmaBookmarks.stream() - .map(bookmark -> CmaBookmarkRes.builder() - .isLiked(Boolean.TRUE) - .cmaId(bookmark.getCma().getId()) - .cmaType(bookmark.getCma().getCmaType()) - .productName(bookmark.getCma().getProductName()) - .companyName(bookmark.getCma().getBankName()) - .maturityInterestRate(bookmark.getCma().getMaturityInterestRate()) - .specialCondition(bookmark.getCma().getSpecialCondition()) - .build()) + .map(bookmark -> { + Bank bank = bankRepository.findByBankName(bookmark.getCma().getBankName()); + String bankLogoUrl = bank != null ? bank.getBankLogoUrl() : null; + + return CmaBookmarkRes.builder() + .isLiked(Boolean.TRUE) + .cmaId(bookmark.getCma().getId()) + .cmaType(bookmark.getCma().getCmaType()) + .productName(bookmark.getCma().getProductName()) + .companyName(bookmark.getCma().getBankName()) + .maturityInterestRate(bookmark.getCma().getMaturityInterestRate()) + .specialCondition(bookmark.getCma().getSpecialCondition()) + .bankLogoUrl(bankLogoUrl) + .build(); + }) .collect(Collectors.toList()); } } 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 892d4a8..d37d776 100644 --- a/src/main/java/com/finfellows/domain/bookmark/dto/FinancialProductBookmarkRes.java +++ b/src/main/java/com/finfellows/domain/bookmark/dto/FinancialProductBookmarkRes.java @@ -5,6 +5,7 @@ import com.finfellows.domain.product.domain.FinancialProduct; import com.finfellows.domain.product.domain.FinancialProductOption; import com.finfellows.domain.product.domain.FinancialProductType; +import com.finfellows.domain.product.domain.repository.BankRepository; import lombok.Builder; import lombok.Data; @@ -21,11 +22,12 @@ public class FinancialProductBookmarkRes { private String productName; private String interestRate; private String maximumPreferredInterestRate; + private String bankLogoUrl; @Builder - public FinancialProductBookmarkRes(Boolean isLiked, Long financialProductId, FinancialProductType financialProductType, String companyName, String productName, String interestRate, String maximumPreferredInterestRate) { + public FinancialProductBookmarkRes(Boolean isLiked, Long financialProductId, FinancialProductType financialProductType, String companyName, String productName, String interestRate, String maximumPreferredInterestRate, String bankLogoUrl) { this.isLiked = isLiked; this.financialProductId = financialProductId; this.financialProductType = financialProductType; @@ -33,28 +35,33 @@ public FinancialProductBookmarkRes(Boolean isLiked, Long financialProductId, Fin this.productName = productName; this.interestRate = interestRate; this.maximumPreferredInterestRate = maximumPreferredInterestRate; + this.bankLogoUrl = bankLogoUrl; } - public static List toDto(List bookmarks) { + public static List toDto(List bookmarks, BankRepository bankRepository) { List results = new ArrayList<>(); for (FinancialProductBookmark bookmark : bookmarks) { FinancialProduct financialProduct = bookmark.getFinancialProduct(); for (FinancialProductOption financialProductOption : financialProduct.getFinancialProductOption()) { - Boolean isLiked = Boolean.TRUE; - Long financialProductId = financialProduct.getId(); - FinancialProductType financialProductType = financialProduct.getFinancialProductType(); - String companyName = financialProduct.getBankName(); - String productName = financialProduct.getProductName(); - String interestRate = financialProductOption.getInterestRate(); - String maximumPreferredInterestRate = financialProductOption.getMaximumPreferredInterestRate(); - - results.add(new FinancialProductBookmarkRes(isLiked ,financialProductId ,financialProductType, companyName, productName, interestRate, maximumPreferredInterestRate)); + String bankName = financialProduct.getBankName(); + String bankLogoUrl = bankRepository.findByBankName(bankName) != null ? bankRepository.findByBankName(bankName).getBankLogoUrl() : null; + + results.add(FinancialProductBookmarkRes.builder() + .isLiked(Boolean.TRUE) + .financialProductId(financialProduct.getId()) + .financialProductType(financialProduct.getFinancialProductType()) + .companyName(bankName) + .productName(financialProduct.getProductName()) + .interestRate(financialProductOption.getInterestRate()) + .maximumPreferredInterestRate(financialProductOption.getMaximumPreferredInterestRate()) + .bankLogoUrl(bankLogoUrl) + .build()); } }