68 lines
1.7 KiB
Dart
68 lines
1.7 KiB
Dart
/// 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);
|
|
}
|
|
}
|