21 lines
627 B
Dart
21 lines
627 B
Dart
import 'dart:convert';
|
|
import '../../../core/api/api_client.dart';
|
|
import '../domain/recipe.dart';
|
|
|
|
class RecipeRepository {
|
|
final ApiClient _api;
|
|
|
|
RecipeRepository(this._api);
|
|
|
|
Future<List<Recipe>> fetchRecipes({String? token}) async {
|
|
final response = await _api.get('/api/recipes', token: token);
|
|
if (response.statusCode != 200) {
|
|
throw Exception('Failed to load recipes: ${response.statusCode}');
|
|
}
|
|
final List<dynamic> data = jsonDecode(response.body) as List<dynamic>;
|
|
return data
|
|
.map((e) => Recipe.fromJson(e as Map<String, dynamic>))
|
|
.toList();
|
|
}
|
|
}
|