refactor: Remove PantryProduct class and simplify category resolution in PantryScreen
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
This commit is contained in:
@@ -4,7 +4,6 @@ import '../../../core/api/api_providers.dart';
|
||||
import '../../../core/api/guarded_api_call.dart';
|
||||
import '../../auth/data/auth_providers.dart';
|
||||
import '../domain/pantry_item.dart';
|
||||
import '../domain/pantry_product.dart';
|
||||
import 'pantry_repository.dart';
|
||||
|
||||
final pantryRepositoryProvider = Provider<PantryRepository>((ref) {
|
||||
@@ -18,11 +17,3 @@ final pantryProvider = FutureProvider<List<PantryItem>>((ref) async {
|
||||
() => ref.read(pantryRepositoryProvider).fetchPantry(token: token),
|
||||
);
|
||||
});
|
||||
|
||||
final pantryProductsProvider = FutureProvider<List<PantryProduct>>((ref) async {
|
||||
final token = await ref.watch(authStateProvider.future);
|
||||
return guardedApiCall(
|
||||
ref,
|
||||
() => ref.read(pantryRepositoryProvider).fetchProducts(token: token),
|
||||
);
|
||||
});
|
||||
@@ -2,7 +2,6 @@ import 'package:logging/logging.dart';
|
||||
import '../../../core/api/api_client.dart';
|
||||
import '../../../core/api/api_paths.dart';
|
||||
import '../domain/pantry_item.dart';
|
||||
import '../domain/pantry_product.dart';
|
||||
|
||||
final _logger = Logger('PantryRepository');
|
||||
|
||||
@@ -25,20 +24,6 @@ class PantryRepository {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<PantryProduct>> fetchProducts({String? token}) async {
|
||||
try {
|
||||
final data = await _api.getJson(ProductApiPaths.mine, token: token);
|
||||
final list = data as List<dynamic>;
|
||||
_logger.info('Fetched ${list.length} products');
|
||||
return list
|
||||
.map((e) => PantryProduct.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
} catch (error) {
|
||||
_logger.severe('Failed to fetch products: $error');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<PantryItem> createPantryItem(
|
||||
int productId, {
|
||||
String? token,
|
||||
|
||||
Reference in New Issue
Block a user