add favorite
This commit is contained in:
@@ -145,6 +145,25 @@ class ApiConstants {
|
||||
/// Body: { "method": "whatsapp|telegram|sms" }
|
||||
static const String shareReferral = '/loyalty/referral/share';
|
||||
|
||||
// ============================================================================
|
||||
// Favorites/Wishlist Endpoints (Frappe ERPNext)
|
||||
// ============================================================================
|
||||
|
||||
/// Get favorite/wishlist items for current user
|
||||
/// POST /api/method/building_material.building_material.api.item_wishlist.get_list
|
||||
/// Body: { "limit_start": 0, "limit_page_length": 0 }
|
||||
static const String getFavorites = '/building_material.building_material.api.item_wishlist.get_list';
|
||||
|
||||
/// Add item to wishlist
|
||||
/// POST /api/method/building_material.building_material.api.item_wishlist.add_to_wishlist
|
||||
/// Body: { "item_id": "GIB20 G04" }
|
||||
static const String addToFavorites = '/building_material.building_material.api.item_wishlist.add_to_wishlist';
|
||||
|
||||
/// Remove item from wishlist
|
||||
/// POST /api/method/building_material.building_material.api.item_wishlist.remove_from_wishlist
|
||||
/// Body: { "item_id": "GIB20 G04" }
|
||||
static const String removeFromFavorites = '/building_material.building_material.api.item_wishlist.remove_from_wishlist';
|
||||
|
||||
// ============================================================================
|
||||
// Product Endpoints
|
||||
// ============================================================================
|
||||
|
||||
@@ -51,8 +51,8 @@ class HiveBoxNames {
|
||||
/// Address book
|
||||
static const String addressBox = 'address_box';
|
||||
|
||||
/// Favorite products
|
||||
static const String favoriteBox = 'favorite_box';
|
||||
/// Favorite products data (cached from wishlist API)
|
||||
static const String favoriteProductsBox = 'favorite_products_box';
|
||||
|
||||
/// Offline request queue for failed API calls
|
||||
static const String offlineQueueBox = 'offline_queue_box';
|
||||
@@ -72,7 +72,7 @@ class HiveBoxNames {
|
||||
syncStateBox,
|
||||
notificationBox,
|
||||
addressBox,
|
||||
favoriteBox,
|
||||
favoriteProductsBox,
|
||||
offlineQueueBox,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hive_ce_flutter/hive_flutter.dart';
|
||||
|
||||
import 'package:worker/core/database/database_manager.dart';
|
||||
import 'package:worker/core/database/hive_service.dart';
|
||||
@@ -53,6 +54,9 @@ class HiveInitializer {
|
||||
|
||||
final dbManager = DatabaseManager();
|
||||
|
||||
// Migration: Delete old favoriteBox (deprecated, replaced with favoriteProductsBox)
|
||||
await _deleteLegacyFavoriteBox(verbose);
|
||||
|
||||
// Clear expired cache on app start
|
||||
await dbManager.clearExpiredCache();
|
||||
|
||||
@@ -97,6 +101,33 @@ class HiveInitializer {
|
||||
await hiveService.clearUserData();
|
||||
}
|
||||
|
||||
/// Delete legacy favoriteBox (migration helper)
|
||||
///
|
||||
/// The old favoriteBox stored FavoriteModel which has been removed.
|
||||
/// This method deletes the old box to prevent typeId errors.
|
||||
static Future<void> _deleteLegacyFavoriteBox(bool verbose) async {
|
||||
try {
|
||||
const legacyBoxName = 'favorite_box';
|
||||
|
||||
// Check if the old box exists
|
||||
if (await Hive.boxExists(legacyBoxName)) {
|
||||
if (verbose) {
|
||||
debugPrint('HiveInitializer: Deleting legacy favoriteBox...');
|
||||
}
|
||||
|
||||
// Delete the box from disk
|
||||
await Hive.deleteBoxFromDisk(legacyBoxName);
|
||||
|
||||
if (verbose) {
|
||||
debugPrint('HiveInitializer: Legacy favoriteBox deleted successfully');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('HiveInitializer: Error deleting legacy favoriteBox: $e');
|
||||
// Don't rethrow - this is just a cleanup operation
|
||||
}
|
||||
}
|
||||
|
||||
/// Get database statistics
|
||||
///
|
||||
/// Returns statistics about all Hive boxes.
|
||||
|
||||
@@ -156,8 +156,8 @@ class HiveService {
|
||||
// Notification box (non-sensitive)
|
||||
Hive.openBox<dynamic>(HiveBoxNames.notificationBox),
|
||||
|
||||
// Favorites box (non-sensitive)
|
||||
Hive.openBox<dynamic>(HiveBoxNames.favoriteBox),
|
||||
// Favorite products box (non-sensitive) - caches Product entities from wishlist API
|
||||
Hive.openBox<dynamic>(HiveBoxNames.favoriteProductsBox),
|
||||
]);
|
||||
|
||||
// Open potentially encrypted boxes (sensitive data)
|
||||
|
||||
Reference in New Issue
Block a user