fix product search/filter
This commit is contained in:
@@ -26,8 +26,14 @@ abstract class ProductsRepository {
|
||||
/// Search products by query
|
||||
///
|
||||
/// [query] - Search term to filter products
|
||||
/// [limitStart] - Starting index for pagination (default: 0)
|
||||
/// [limitPageLength] - Number of items per page (default: 12)
|
||||
/// Returns filtered list of products matching the query.
|
||||
Future<List<Product>> searchProducts(String query);
|
||||
Future<List<Product>> searchProducts(
|
||||
String query, {
|
||||
int limitStart = 0,
|
||||
int limitPageLength = 12,
|
||||
});
|
||||
|
||||
/// Get products by category
|
||||
///
|
||||
@@ -52,4 +58,23 @@ abstract class ProductsRepository {
|
||||
///
|
||||
/// Returns a list of all product categories.
|
||||
Future<List<Category>> getCategories();
|
||||
|
||||
/// Get products with filters
|
||||
///
|
||||
/// Fetches products with comprehensive filtering support:
|
||||
/// - [itemGroups] - List of product group names to filter by
|
||||
/// - [brands] - List of brand names to filter by
|
||||
/// - [itemAttributes] - List of attribute filters (attribute + value pairs)
|
||||
/// - [searchKeyword] - Search query string
|
||||
/// - [limitStart] - Starting index for pagination (default: 0)
|
||||
/// - [limitPageLength] - Number of items per page (default: 12)
|
||||
/// Returns filtered list of products matching all criteria.
|
||||
Future<List<Product>> getProductsWithFilters({
|
||||
int limitStart = 0,
|
||||
int limitPageLength = 12,
|
||||
List<String>? itemGroups,
|
||||
List<String>? brands,
|
||||
List<Map<String, String>>? itemAttributes,
|
||||
String? searchKeyword,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// Use Case: Search Products
|
||||
///
|
||||
/// Business logic for searching products by query string.
|
||||
/// Business logic for searching products by query string with pagination support.
|
||||
library;
|
||||
|
||||
import 'package:worker/features/products/domain/entities/product.dart';
|
||||
@@ -8,7 +8,7 @@ import 'package:worker/features/products/domain/repositories/products_repository
|
||||
|
||||
/// Search Products Use Case
|
||||
///
|
||||
/// Searches for products matching the given query string.
|
||||
/// Searches for products matching the given query string with pagination.
|
||||
class SearchProducts {
|
||||
final ProductsRepository repository;
|
||||
|
||||
@@ -17,13 +17,26 @@ class SearchProducts {
|
||||
/// Execute the use case
|
||||
///
|
||||
/// [query] - Search query string
|
||||
/// [limitStart] - Starting index for pagination (default: 0)
|
||||
/// [limitPageLength] - Number of items per page (default: 12)
|
||||
/// Returns list of products matching the query
|
||||
Future<List<Product>> call(String query) async {
|
||||
Future<List<Product>> call(
|
||||
String query, {
|
||||
int limitStart = 0,
|
||||
int limitPageLength = 12,
|
||||
}) async {
|
||||
// Return all products if query is empty
|
||||
if (query.trim().isEmpty) {
|
||||
return await repository.getAllProducts();
|
||||
return await repository.getAllProducts(
|
||||
limitStart: limitStart,
|
||||
limitPageLength: limitPageLength,
|
||||
);
|
||||
}
|
||||
|
||||
return await repository.searchProducts(query);
|
||||
return await repository.searchProducts(
|
||||
query,
|
||||
limitStart: limitStart,
|
||||
limitPageLength: limitPageLength,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user