From 2a0a743657a66815a219b33703657094459f82cb Mon Sep 17 00:00:00 2001 From: LeeJaeHyeok97 Date: Thu, 18 Jan 2024 04:36:02 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20financialProduct=20=EC=A4=91=EB=B3=B5?= =?UTF-8?q?=20=EC=B6=9C=EB=A0=A5=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/FinancialProductBookmarkRes.java | 19 +++++++++++++----- .../presentation/BookmarkController.java | 20 +++++++++---------- 2 files changed, 24 insertions(+), 15 deletions(-) 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 d37d776..0956bce 100644 --- a/src/main/java/com/finfellows/domain/bookmark/dto/FinancialProductBookmarkRes.java +++ b/src/main/java/com/finfellows/domain/bookmark/dto/FinancialProductBookmarkRes.java @@ -10,7 +10,9 @@ import lombok.Data; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; @Data @@ -44,29 +46,36 @@ public FinancialProductBookmarkRes(Boolean isLiked, Long financialProductId, Fin public static List toDto(List bookmarks, BankRepository bankRepository) { List results = new ArrayList<>(); + Set includedFinancialProductIds = new HashSet<>(); for (FinancialProductBookmark bookmark : bookmarks) { FinancialProduct financialProduct = bookmark.getFinancialProduct(); + Long financialProductId = financialProduct.getId(); - for (FinancialProductOption financialProductOption : financialProduct.getFinancialProductOption()) { + // financialProductId가 이미 포함되어 있으면 건너뛴다 + if (!includedFinancialProductIds.contains(financialProductId)) { String bankName = financialProduct.getBankName(); String bankLogoUrl = bankRepository.findByBankName(bankName) != null ? bankRepository.findByBankName(bankName).getBankLogoUrl() : null; + // 대표 옵션 선택 또는 모든 옵션 정보 집계 + FinancialProductOption representativeOption = financialProduct.getFinancialProductOption().get(0); // 예시: 첫 번째 옵션 사용 + results.add(FinancialProductBookmarkRes.builder() .isLiked(Boolean.TRUE) - .financialProductId(financialProduct.getId()) + .financialProductId(financialProductId) .financialProductType(financialProduct.getFinancialProductType()) .companyName(bankName) .productName(financialProduct.getProductName()) - .interestRate(financialProductOption.getInterestRate()) - .maximumPreferredInterestRate(financialProductOption.getMaximumPreferredInterestRate()) + .interestRate(representativeOption.getInterestRate()) + .maximumPreferredInterestRate(representativeOption.getMaximumPreferredInterestRate()) .bankLogoUrl(bankLogoUrl) .build()); + // financialProductId를 포함된 목록에 추가한다 + includedFinancialProductIds.add(financialProductId); } } - return results; } diff --git a/src/main/java/com/finfellows/domain/bookmark/presentation/BookmarkController.java b/src/main/java/com/finfellows/domain/bookmark/presentation/BookmarkController.java index 5cf8ca0..f3f9792 100644 --- a/src/main/java/com/finfellows/domain/bookmark/presentation/BookmarkController.java +++ b/src/main/java/com/finfellows/domain/bookmark/presentation/BookmarkController.java @@ -143,16 +143,16 @@ public ResponseCustom deleteBookmarkCma( } -// @Operation(summary = "모든 금융, 뭐하지 북마크 삭제", description = "Deletes all financial product and CMA bookmarks.") -// @ApiResponses(value = { -// @ApiResponse(responseCode = "200", description = "All bookmarks deleted successfully", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}), -// @ApiResponse(responseCode = "500", description = "Internal server error", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}) -// }) -// @DeleteMapping("/all") -// public ResponseCustom deleteAllBookmarks() { -// bookmarkCleanupService.deleteAllBookmarks(); -// return ResponseCustom.OK(new Message("All bookmarks deleted successfully.")); -// } + @Operation(summary = "모든 금융, 뭐하지 북마크 삭제", description = "Deletes all financial product and CMA bookmarks.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "All bookmarks deleted successfully", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}), + @ApiResponse(responseCode = "500", description = "Internal server error", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}) + }) + @DeleteMapping("/all") + public ResponseCustom deleteAllBookmarks() { + bookmarkCleanupService.deleteAllBookmarks(); + return ResponseCustom.OK(new Message("All bookmarks deleted successfully.")); + } // @Operation(summary = "금융, 고마워 북마크 삭제", description = "Deletes all policyInfos.") // @ApiResponses(value = {