feat: add pantry management features including repository, providers, and UI integration

This commit is contained in:
Nils-Johan Gynther
2026-04-22 10:45:37 +02:00
parent f11364b73e
commit dd05fed279
9 changed files with 615 additions and 7 deletions
@@ -0,0 +1,39 @@
import '../../../core/api/api_client.dart';
import '../../../core/api/api_paths.dart';
import '../domain/pantry_item.dart';
import '../domain/pantry_product.dart';
class PantryRepository {
final ApiClient _api;
const PantryRepository(this._api);
Future<List<PantryItem>> fetchPantry({String? token}) async {
final data = await _api.getJson(PantryApiPaths.list, token: token);
final list = data as List<dynamic>;
return list
.map((e) => PantryItem.fromJson(e as Map<String, dynamic>))
.toList();
}
Future<List<PantryProduct>> fetchProducts({String? token}) async {
final data = await _api.getJson(ProductApiPaths.list, token: token);
final list = data as List<dynamic>;
return list
.map((e) => PantryProduct.fromJson(e as Map<String, dynamic>))
.toList();
}
Future<PantryItem> createPantryItem(int productId, {String? token}) async {
final data = await _api.postJson(
PantryApiPaths.list,
body: {'productId': productId},
token: token,
);
return PantryItem.fromJson(data as Map<String, dynamic>);
}
Future<void> deletePantryItem(int id, {String? token}) async {
await _api.deleteJson(PantryApiPaths.remove(id), token: token);
}
}