From 2c29a01bbb1c5cc5e5ea143623aa929549f5e3c4 Mon Sep 17 00:00:00 2001 From: sim-mer Date: Thu, 3 Oct 2024 04:26:55 +0900 Subject: [PATCH] =?UTF-8?q?#27=20feat(persistence):=20=EC=83=81=ED=92=88?= =?UTF-8?q?=20=EA=B2=80=EC=83=89=20=EA=B8=B0=EB=8A=A5=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?(imageUrl=20=EC=B6=94=EA=B0=80=20=EC=98=88=EC=A0=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/repository/ProductRepository.java | 19 +++++++++++++++++++ .../product/repository/dto/ProductSearch.java | 9 +++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/main/java/com/helpmeCookies/product/repository/dto/ProductSearch.java diff --git a/src/main/java/com/helpmeCookies/product/repository/ProductRepository.java b/src/main/java/com/helpmeCookies/product/repository/ProductRepository.java index d8b05f3..aca10a1 100644 --- a/src/main/java/com/helpmeCookies/product/repository/ProductRepository.java +++ b/src/main/java/com/helpmeCookies/product/repository/ProductRepository.java @@ -1,9 +1,28 @@ package com.helpmeCookies.product.repository; import com.helpmeCookies.product.entity.Product; +import com.helpmeCookies.product.repository.dto.ProductSearch; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @Repository public interface ProductRepository extends JpaRepository { + + @Query("SELECT p.id AS id, p.name AS name, a.name AS artist, p.price AS price " + + "FROM Product p JOIN p.artistInfo a " + + "WHERE p.name LIKE %:query%") // Index 미사용 + Page findByName(@Param("query") String query, Pageable pageable); + + @Query(value = "SELECT p.id, p.name, a.name AS artist, p.price " + + "FROM product p JOIN artist_info a ON p.artist_info_id = a.id " + + "WHERE MATCH(p.name) AGAINST (:query IN BOOLEAN MODE)", + countQuery = "SELECT COUNT(*) " + + "FROM product p JOIN artist_info a ON p.artist_info_id = a.id " + + "WHERE MATCH(p.name) AGAINST (:query IN BOOLEAN MODE)", + nativeQuery = true) // Index 사용 + Page findByNameWithIdx(@Param("query") String query, Pageable pageable); } diff --git a/src/main/java/com/helpmeCookies/product/repository/dto/ProductSearch.java b/src/main/java/com/helpmeCookies/product/repository/dto/ProductSearch.java new file mode 100644 index 0000000..3c5fcee --- /dev/null +++ b/src/main/java/com/helpmeCookies/product/repository/dto/ProductSearch.java @@ -0,0 +1,9 @@ +package com.helpmeCookies.product.repository.dto; + + +public interface ProductSearch { + Long getId(); + String getName(); + String getArtist(); + Long getPrice(); +}