fix product page

This commit is contained in:
Phuoc Nguyen
2025-11-17 11:03:51 +07:00
parent 49082026f5
commit 0828ff1355
17 changed files with 482 additions and 76 deletions

View File

@@ -14,9 +14,14 @@ import 'package:worker/features/products/domain/entities/product.dart';
abstract class ProductsRepository {
/// Get all products
///
/// Returns a list of all available products.
/// Returns a list of all available products with pagination support.
/// [limitStart] - Starting index for pagination (default: 0)
/// [limitPageLength] - Number of items per page (default: 12)
/// Throws an exception if the operation fails.
Future<List<Product>> getAllProducts();
Future<List<Product>> getAllProducts({
int limitStart = 0,
int limitPageLength = 12,
});
/// Search products by query
///
@@ -27,8 +32,14 @@ abstract class ProductsRepository {
/// Get products by category
///
/// [categoryId] - Category ID to filter by
/// [limitStart] - Starting index for pagination (default: 0)
/// [limitPageLength] - Number of items per page (default: 12)
/// Returns list of products in the specified category.
Future<List<Product>> getProductsByCategory(String categoryId);
Future<List<Product>> getProductsByCategory(
String categoryId, {
int limitStart = 0,
int limitPageLength = 12,
});
/// Get product by ID
///

View File

@@ -17,12 +17,25 @@ class GetProducts {
/// Execute the use case
///
/// [categoryId] - Optional category ID to filter products
/// [limitStart] - Starting index for pagination (default: 0)
/// [limitPageLength] - Number of items per page (default: 12)
/// Returns list of products (all or filtered by category)
Future<List<Product>> call({String? categoryId}) async {
Future<List<Product>> call({
String? categoryId,
int limitStart = 0,
int limitPageLength = 12,
}) async {
if (categoryId == null || categoryId == 'all') {
return await repository.getAllProducts();
return await repository.getAllProducts(
limitStart: limitStart,
limitPageLength: limitPageLength,
);
} else {
return await repository.getProductsByCategory(categoryId);
return await repository.getProductsByCategory(
categoryId,
limitStart: limitStart,
limitPageLength: limitPageLength,
);
}
}
}