add favorite
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
/// Domain Entity: Favorite
|
||||
///
|
||||
/// Pure business entity representing a user's favorite product.
|
||||
/// This entity is framework-independent and contains only business logic.
|
||||
library;
|
||||
|
||||
/// Favorite Entity
|
||||
///
|
||||
/// Represents a product that a user has marked as favorite.
|
||||
/// Used across all layers but originates in the domain layer.
|
||||
class Favorite {
|
||||
/// Unique identifier for the favorite entry
|
||||
final String favoriteId;
|
||||
|
||||
/// Reference to the product that was favorited
|
||||
final String productId;
|
||||
|
||||
/// Reference to the user who favorited the product
|
||||
final String userId;
|
||||
|
||||
/// Timestamp when the product was favorited
|
||||
final DateTime createdAt;
|
||||
|
||||
const Favorite({
|
||||
required this.favoriteId,
|
||||
required this.productId,
|
||||
required this.userId,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
/// Copy with method for creating modified copies
|
||||
Favorite copyWith({
|
||||
String? favoriteId,
|
||||
String? productId,
|
||||
String? userId,
|
||||
DateTime? createdAt,
|
||||
}) {
|
||||
return Favorite(
|
||||
favoriteId: favoriteId ?? this.favoriteId,
|
||||
productId: productId ?? this.productId,
|
||||
userId: userId ?? this.userId,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Favorite(favoriteId: $favoriteId, productId: $productId, '
|
||||
'userId: $userId, createdAt: $createdAt)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is Favorite &&
|
||||
other.favoriteId == favoriteId &&
|
||||
other.productId == productId &&
|
||||
other.userId == userId &&
|
||||
other.createdAt == createdAt;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(favoriteId, productId, userId, createdAt);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:worker/features/products/domain/entities/product.dart';
|
||||
|
||||
/// Favorites Repository Interface
|
||||
///
|
||||
/// Defines the contract for favorites data operations.
|
||||
/// Implementations should follow the online-first approach:
|
||||
/// 1. Try to fetch/update data from API
|
||||
/// 2. Update local cache with API response
|
||||
/// 3. On network failure, fall back to local cache
|
||||
abstract class FavoritesRepository {
|
||||
/// Get favorite products with full product data
|
||||
///
|
||||
/// Online-first: Fetches from wishlist API, caches locally.
|
||||
/// Falls back to local cache on network failure.
|
||||
/// Returns `List<Product>` with complete product information.
|
||||
Future<List<Product>> getFavoriteProducts();
|
||||
|
||||
/// Add a product to favorites
|
||||
///
|
||||
/// Online-first: Adds to API, then caches locally.
|
||||
/// On network failure, queues for later sync.
|
||||
Future<void> addFavorite(String productId);
|
||||
|
||||
/// Remove a product from favorites
|
||||
///
|
||||
/// Online-first: Removes from API, then updates local cache.
|
||||
/// On network failure, queues for later sync.
|
||||
Future<bool> removeFavorite(String productId);
|
||||
}
|
||||
Reference in New Issue
Block a user