-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductRepository.java
More file actions
47 lines (34 loc) · 2.2 KB
/
ProductRepository.java
File metadata and controls
47 lines (34 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.ecommerce.product.repository;
import com.ecommerce.product.entity.Product;
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;
import java.math.BigDecimal;
import java.util.List;
@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {
Page<Product> findByCategory(String category, Pageable pageable);
Page<Product> findByBrand(String brand, Pageable pageable);
Page<Product> findByStatus(Product.ProductStatus status, Pageable pageable);
Page<Product> findByFeatured(Boolean featured, Pageable pageable);
@Query("SELECT p FROM Product p WHERE p.price BETWEEN :minPrice AND :maxPrice")
Page<Product> findByPriceRange(@Param("minPrice") BigDecimal minPrice,
@Param("maxPrice") BigDecimal maxPrice,
Pageable pageable);
@Query("SELECT p FROM Product p WHERE p.category = :category AND p.price BETWEEN :minPrice AND :maxPrice")
Page<Product> findByCategoryAndPriceRange(@Param("category") String category,
@Param("minPrice") BigDecimal minPrice,
@Param("maxPrice") BigDecimal maxPrice,
Pageable pageable);
@Query("SELECT p FROM Product p WHERE p.name LIKE %:keyword% OR p.description LIKE %:keyword% OR p.brand LIKE %:keyword%")
Page<Product> searchProducts(@Param("keyword") String keyword, Pageable pageable);
@Query("SELECT DISTINCT p.category FROM Product p WHERE p.status = 'ACTIVE'")
List<String> findAllActiveCategories();
@Query("SELECT DISTINCT p.brand FROM Product p WHERE p.status = 'ACTIVE'")
List<String> findAllActiveBrands();
@Query("SELECT p FROM Product p WHERE p.stockQuantity < :threshold")
List<Product> findLowStockProducts(@Param("threshold") Integer threshold);
}