feat: add pantry management features including repository, providers, and UI integration
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user