diff --git a/src/main/java/shop/hooking/hooking/service/BrandService.java b/src/main/java/shop/hooking/hooking/service/BrandService.java index 57e4769..afd4e06 100644 --- a/src/main/java/shop/hooking/hooking/service/BrandService.java +++ b/src/main/java/shop/hooking/hooking/service/BrandService.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import shop.hooking.hooking.dto.CardSearchCondition; import shop.hooking.hooking.dto.response.BrandRes; import shop.hooking.hooking.dto.response.CopyRes; import shop.hooking.hooking.dto.response.ReviewRes; @@ -64,14 +65,8 @@ public BrandRes.BrandDetailDto getOneBrand(Long id) { List cards = cardRepository.findCardsByBrandId(brand.getId()); - for(Card card : cards){ - Long cardId = card.getId(); - - List scraps = scrapRepository.findByCardId(cardId); - int length = scraps.size(); - card.setScrapCnt(length); + cards.forEach(card -> card.setScrapCnt((int) scrapRepository.findByCardId(card.getId()).stream().count())); - } List cardTexts = new ArrayList<>(); int maxCardCount = Math.min(cards.size(), 3); @@ -100,6 +95,14 @@ public BrandRes.BrandDetailDto getOneBrand(Long id) { return brandDetailDto; } + public int countScrapCnt(Card card){ + Long cardId = card.getId(); + + List scraps = scrapRepository.findByCardId(cardId); + int length = scraps.size(); + return length; + } + // public boolean followBrand(Long brandId, User user){ // // Brand brand = brandRepository.findBrandById(brandId);