From 1a671fc06b9137b88ccca1aa4fd48547d59a1001 Mon Sep 17 00:00:00 2001 From: CYJhub Date: Tue, 25 Jul 2023 14:42:33 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EA=B2=80=EC=83=89=EC=84=B1=EB=8A=A5?= =?UTF-8?q?=20=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hooking/config/SecurityConfig.java | 2 +- .../hooking/controller/CopyController.java | 8 +-- .../hooking/repository/CardJpaRepository.java | 54 ++++++++++++++++++- .../hooking/repository/CardRepository.java | 2 +- .../hooking/hooking/service/CopyService.java | 2 +- 5 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/main/java/shop/hooking/hooking/config/SecurityConfig.java b/src/main/java/shop/hooking/hooking/config/SecurityConfig.java index 45f8573..c6f7aab 100644 --- a/src/main/java/shop/hooking/hooking/config/SecurityConfig.java +++ b/src/main/java/shop/hooking/hooking/config/SecurityConfig.java @@ -58,7 +58,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .requestMatchers(CorsUtils::isPreFlightRequest).permitAll() - .antMatchers("**/oath-processor/**","/kakaologin","/copy", "/copy/search","/copy/filter","/copy/crawling", "/brand", "/brand/{brand_id}" + .antMatchers("**/oath-processor/**","/kakaologin","/copy/{index}", "/copy/search","/copy/filter","/copy/crawling", "/brand", "/brand/{brand_id}" ).permitAll() diff --git a/src/main/java/shop/hooking/hooking/controller/CopyController.java b/src/main/java/shop/hooking/hooking/controller/CopyController.java index 65d7b77..5276210 100644 --- a/src/main/java/shop/hooking/hooking/controller/CopyController.java +++ b/src/main/java/shop/hooking/hooking/controller/CopyController.java @@ -93,10 +93,10 @@ public CopySearchResponse copySearchList(HttpServletRequest httpRequest,@Request List textCopyRes = new ArrayList<>(); List brandCopyRes = new ArrayList<>(); - textCopyRes = copyService.selectCopyByQuery(q); + textCopyRes = cardJpaRepository.searchCopy(q); if (moodType != null) { - moodCopyRes = copyService.selectMoodByQuery(q); + moodCopyRes = cardJpaRepository.searchMood(q); setScrapCntWhenTokenNotProvided(httpRequest, moodCopyRes); Collections.shuffle(moodCopyRes); CopySearchResult moodResult = createCopySearchResult(moodCopyRes); @@ -114,7 +114,7 @@ public CopySearchResponse copySearchList(HttpServletRequest httpRequest,@Request results.add(copyResult); } } else if (BrandType.containsKeyword(q)) { - brandCopyRes = copyService.selectBrandByQuery(q); + brandCopyRes = cardJpaRepository.searchBrand(q); setScrapCntWhenTokenNotProvided(httpRequest, brandCopyRes); Collections.shuffle(brandCopyRes); CopySearchResult brandResult = createCopySearchResult(brandCopyRes); @@ -210,7 +210,7 @@ public HttpRes saveCrawling(@RequestBody CrawlingReq crawlingReq) { @GetMapping("/filter") public HttpRes> searchFilterCard(HttpServletRequest httpRequest,CardSearchCondition condition) { - List results = cardJpaRepository.search(condition); + List results = cardJpaRepository.filter(condition); List limitedResults = getLimitedCopyRes(results,30); setScrapCntWhenTokenNotProvided(httpRequest, limitedResults); return new HttpRes<>(limitedResults); diff --git a/src/main/java/shop/hooking/hooking/repository/CardJpaRepository.java b/src/main/java/shop/hooking/hooking/repository/CardJpaRepository.java index 65707f8..85cb4ee 100644 --- a/src/main/java/shop/hooking/hooking/repository/CardJpaRepository.java +++ b/src/main/java/shop/hooking/hooking/repository/CardJpaRepository.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Repository; import shop.hooking.hooking.dto.CardSearchCondition; import shop.hooking.hooking.dto.response.CopyRes; +import shop.hooking.hooking.dto.response.CopySearchResponse; import shop.hooking.hooking.dto.response.QCopyRes; import shop.hooking.hooking.entity.*; @@ -26,7 +27,7 @@ public CardJpaRepository(EntityManager em) { this.queryFactory = new JPAQueryFactory(em); } - public List search(CardSearchCondition condition){ + public List filter(CardSearchCondition condition){ String moodString = condition.getMood(); String[] moods = null; @@ -127,4 +128,55 @@ private BooleanExpression priceEq(String[] prices) { return priceExpression; } + + public List searchMood(String q){ + BooleanExpression moodNameEqualsQ = mood.moodName.eq(q); + + return queryFactory + .selectDistinct(new QCopyRes( + card.id, + card.brand, + card.text, + card.scrapCnt, + card.createdAt)) + .from(card) + .leftJoin(card.brand, brand) + .leftJoin(have) + .on(have.brand.eq(brand)) + .join(have.mood, mood) + .where(moodNameEqualsQ) + .fetch(); + } + + public List searchCopy(String q){ + BooleanExpression textContainsQ = card.text.contains(q); + + return queryFactory + .selectDistinct(new QCopyRes( + card.id, + card.brand, + card.text, + card.scrapCnt, + card.createdAt)) + .from(card) + .where(textContainsQ) + .fetch(); + } + + public List searchBrand(String q){ + BooleanExpression brandContainsQ = brand.brandName.contains(q); + + return queryFactory + .selectDistinct(new QCopyRes( + card.id, + card.brand, + card.text, + card.scrapCnt, + card.createdAt)) + .from(card) + .leftJoin(card.brand, brand) + .where(brandContainsQ) + .fetch(); + } + } \ No newline at end of file diff --git a/src/main/java/shop/hooking/hooking/repository/CardRepository.java b/src/main/java/shop/hooking/hooking/repository/CardRepository.java index 5f0e515..f7c18f7 100644 --- a/src/main/java/shop/hooking/hooking/repository/CardRepository.java +++ b/src/main/java/shop/hooking/hooking/repository/CardRepository.java @@ -12,7 +12,7 @@ @Repository public interface CardRepository extends JpaRepository{ - List findTop5ByBrandIdOrderByCreatedAtDesc(Long brandId); + List findTop10ByBrandIdOrderByCreatedAtDesc(Long brandId); Card findCardByBrandId(Long brandId); // 브랜드 아이디로 카피라이팅 카드 찾기 diff --git a/src/main/java/shop/hooking/hooking/service/CopyService.java b/src/main/java/shop/hooking/hooking/service/CopyService.java index a6ff667..586d5d3 100644 --- a/src/main/java/shop/hooking/hooking/service/CopyService.java +++ b/src/main/java/shop/hooking/hooking/service/CopyService.java @@ -31,7 +31,7 @@ public class CopyService { @Transactional public List getCopyList(Long brandId) { - List cards = cardRepository.findTop5ByBrandIdOrderByCreatedAtDesc(brandId); + List cards = cardRepository.findTop10ByBrandIdOrderByCreatedAtDesc(brandId); List copyResList = new ArrayList<>(); for (Card card : cards) {