runable
This commit is contained in:
42
lib/features/products/domain/entities/product.dart
Normal file
42
lib/features/products/domain/entities/product.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// Product domain entity
|
||||
class Product extends Equatable {
|
||||
final String id;
|
||||
final String name;
|
||||
final String description;
|
||||
final double price;
|
||||
final String? imageUrl;
|
||||
final String categoryId;
|
||||
final int stockQuantity;
|
||||
final bool isAvailable;
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
|
||||
const Product({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.description,
|
||||
required this.price,
|
||||
this.imageUrl,
|
||||
required this.categoryId,
|
||||
required this.stockQuantity,
|
||||
required this.isAvailable,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
name,
|
||||
description,
|
||||
price,
|
||||
imageUrl,
|
||||
categoryId,
|
||||
stockQuantity,
|
||||
isAvailable,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../../../core/errors/failures.dart';
|
||||
import '../entities/product.dart';
|
||||
|
||||
/// Product repository interface
|
||||
abstract class ProductRepository {
|
||||
/// Get all products from cache
|
||||
Future<Either<Failure, List<Product>>> getAllProducts();
|
||||
|
||||
/// Get products by category
|
||||
Future<Either<Failure, List<Product>>> getProductsByCategory(String categoryId);
|
||||
|
||||
/// Search products
|
||||
Future<Either<Failure, List<Product>>> searchProducts(String query);
|
||||
|
||||
/// Get product by ID
|
||||
Future<Either<Failure, Product>> getProductById(String id);
|
||||
|
||||
/// Sync products from remote
|
||||
Future<Either<Failure, List<Product>>> syncProducts();
|
||||
}
|
||||
15
lib/features/products/domain/usecases/get_all_products.dart
Normal file
15
lib/features/products/domain/usecases/get_all_products.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../../../core/errors/failures.dart';
|
||||
import '../entities/product.dart';
|
||||
import '../repositories/product_repository.dart';
|
||||
|
||||
/// Use case to get all products
|
||||
class GetAllProducts {
|
||||
final ProductRepository repository;
|
||||
|
||||
GetAllProducts(this.repository);
|
||||
|
||||
Future<Either<Failure, List<Product>>> call() async {
|
||||
return await repository.getAllProducts();
|
||||
}
|
||||
}
|
||||
15
lib/features/products/domain/usecases/search_products.dart
Normal file
15
lib/features/products/domain/usecases/search_products.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../../../core/errors/failures.dart';
|
||||
import '../entities/product.dart';
|
||||
import '../repositories/product_repository.dart';
|
||||
|
||||
/// Use case to search products
|
||||
class SearchProducts {
|
||||
final ProductRepository repository;
|
||||
|
||||
SearchProducts(this.repository);
|
||||
|
||||
Future<Either<Failure, List<Product>>> call(String query) async {
|
||||
return await repository.searchProducts(query);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user