import '../../../core/api/api_client.dart'; import '../../../core/api/api_exception.dart'; import '../domain/recipe.dart'; class RecipeRepository { final ApiClient _api; RecipeRepository(this._api); Future> fetchRecipes({String? token}) async { try { final data = await _api.getJson('/recipes', token: token); if (data is! List) { throw const ApiException( type: ApiErrorType.unknown, message: 'Ogiltigt svar fran servern.', ); } return data .map((e) => Recipe.fromJson(e as Map)) .toList(); } on ApiException { rethrow; } catch (_) { throw const ApiException( type: ApiErrorType.network, message: 'Kunde inte hamta recept.', ); } } }