feat: add Flutter web frontend with authentication and recipe management features
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/api/api_providers.dart';
|
||||
import '../../../features/auth/data/auth_providers.dart';
|
||||
import 'recipe_repository.dart';
|
||||
import '../domain/recipe.dart';
|
||||
|
||||
final recipeRepositoryProvider = Provider<RecipeRepository>((ref) {
|
||||
return RecipeRepository(ref.watch(apiClientProvider));
|
||||
});
|
||||
|
||||
final recipesProvider = FutureProvider<List<Recipe>>((ref) async {
|
||||
final token = await ref.watch(authStateProvider.future);
|
||||
return ref.watch(recipeRepositoryProvider).fetchRecipes(token: token);
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user