Skip to content

Commit

Permalink
[feat] 스크랩 횟수 카운트 함수 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
CYJhub committed Jul 27, 2023
1 parent b25df49 commit f2e670d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/main/java/shop/hooking/hooking/service/BrandService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,14 +65,8 @@ public BrandRes.BrandDetailDto getOneBrand(Long id) {

List<Card> cards = cardRepository.findCardsByBrandId(brand.getId());

for(Card card : cards){
Long cardId = card.getId();

List<Scrap> scraps = scrapRepository.findByCardId(cardId);
int length = scraps.size();
card.setScrapCnt(length);
cards.forEach(card -> card.setScrapCnt((int) scrapRepository.findByCardId(card.getId()).stream().count()));

}

List<String> cardTexts = new ArrayList<>();
int maxCardCount = Math.min(cards.size(), 3);
Expand Down Expand Up @@ -100,6 +95,14 @@ public BrandRes.BrandDetailDto getOneBrand(Long id) {
return brandDetailDto;
}

public int countScrapCnt(Card card){
Long cardId = card.getId();

List<Scrap> scraps = scrapRepository.findByCardId(cardId);
int length = scraps.size();
return length;
}

// public boolean followBrand(Long brandId, User user){
//
// Brand brand = brandRepository.findBrandById(brandId);
Expand Down

0 comments on commit f2e670d

Please sign in to comment.