add auth, format
This commit is contained in:
@@ -40,7 +40,9 @@ class FavoritesLocalDataSource {
|
||||
Future<void> addFavorite(FavoriteModel favorite) async {
|
||||
try {
|
||||
await _box.put(favorite.favoriteId, favorite);
|
||||
debugPrint('[FavoritesLocalDataSource] Added favorite: ${favorite.favoriteId} for user: ${favorite.userId}');
|
||||
debugPrint(
|
||||
'[FavoritesLocalDataSource] Added favorite: ${favorite.favoriteId} for user: ${favorite.userId}',
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('[FavoritesLocalDataSource] Error adding favorite: $e');
|
||||
rethrow;
|
||||
@@ -60,13 +62,17 @@ class FavoritesLocalDataSource {
|
||||
.toList();
|
||||
|
||||
if (favorites.isEmpty) {
|
||||
debugPrint('[FavoritesLocalDataSource] Favorite not found: productId=$productId, userId=$userId');
|
||||
debugPrint(
|
||||
'[FavoritesLocalDataSource] Favorite not found: productId=$productId, userId=$userId',
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
final favorite = favorites.first;
|
||||
await _box.delete(favorite.favoriteId);
|
||||
debugPrint('[FavoritesLocalDataSource] Removed favorite: ${favorite.favoriteId} for user: $userId');
|
||||
debugPrint(
|
||||
'[FavoritesLocalDataSource] Removed favorite: ${favorite.favoriteId} for user: $userId',
|
||||
);
|
||||
return true;
|
||||
} catch (e) {
|
||||
debugPrint('[FavoritesLocalDataSource] Error removing favorite: $e');
|
||||
@@ -79,9 +85,9 @@ class FavoritesLocalDataSource {
|
||||
/// Returns true if the product is in the user's favorites, false otherwise.
|
||||
bool isFavorite(String productId, String userId) {
|
||||
try {
|
||||
return _box.values
|
||||
.whereType<FavoriteModel>()
|
||||
.any((fav) => fav.productId == productId && fav.userId == userId);
|
||||
return _box.values.whereType<FavoriteModel>().any(
|
||||
(fav) => fav.productId == productId && fav.userId == userId,
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('[FavoritesLocalDataSource] Error checking favorite: $e');
|
||||
return false;
|
||||
@@ -101,7 +107,9 @@ class FavoritesLocalDataSource {
|
||||
.toList();
|
||||
|
||||
await _box.deleteAll(favoriteIds);
|
||||
debugPrint('[FavoritesLocalDataSource] Cleared ${favoriteIds.length} favorites for user: $userId');
|
||||
debugPrint(
|
||||
'[FavoritesLocalDataSource] Cleared ${favoriteIds.length} favorites for user: $userId',
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('[FavoritesLocalDataSource] Error clearing favorites: $e');
|
||||
rethrow;
|
||||
@@ -140,7 +148,9 @@ class FavoritesLocalDataSource {
|
||||
debugPrint('[FavoritesLocalDataSource] Favorites box compacted');
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('[FavoritesLocalDataSource] Error compacting favorites box: $e');
|
||||
debugPrint(
|
||||
'[FavoritesLocalDataSource] Error compacting favorites box: $e',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user