Backend: - Migrations 007 (menu_plans, menu_items, shopping_lists) and 008 (meal_diary) - gemini/menu.go: GenerateMenu — 7-day × 3-meal plan via one Groq call - internal/menu: model, repository (GetByWeek, SaveMenuInTx, shopping list CRUD), handler (GET/PUT/DELETE /menu, POST /ai/generate-menu, shopping list endpoints) - internal/diary: model, repository, handler (GET/POST/DELETE /diary) - Increase server WriteTimeout to 120s for long AI calls - api_client.go: add patch() and postList() helpers Flutter: - shared/models: menu.dart, shopping_item.dart, diary_entry.dart - features/menu: menu_service.dart, menu_provider.dart (MenuNotifier, ShoppingListNotifier, DiaryNotifier with family) - MenuScreen: 7-day view, week nav, skeleton on generation, generate FAB with confirmation dialog - ShoppingListScreen: items by category, optimistic checkbox toggle - DiaryScreen: daily entries with swipe-to-delete, add-entry sheet - Router: /menu/shopping-list and /menu/diary routes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
69 lines
2.1 KiB
Dart
69 lines
2.1 KiB
Dart
import 'package:dio/dio.dart';
|
|
import '../auth/secure_storage.dart';
|
|
import 'auth_interceptor.dart';
|
|
|
|
class ApiClient {
|
|
late final Dio _dio;
|
|
|
|
ApiClient({required String baseUrl, required SecureStorageService storage}) {
|
|
_dio = Dio(BaseOptions(
|
|
baseUrl: baseUrl,
|
|
connectTimeout: const Duration(seconds: 10),
|
|
receiveTimeout: const Duration(seconds: 120),
|
|
headers: {'Content-Type': 'application/json'},
|
|
));
|
|
|
|
_dio.interceptors.addAll([
|
|
AuthInterceptor(storage: storage, dio: _dio),
|
|
LogInterceptor(requestBody: true, responseBody: true),
|
|
]);
|
|
}
|
|
|
|
/// Exposed for testing only.
|
|
ApiClient.withDio(this._dio);
|
|
|
|
Future<Map<String, dynamic>> get(String path,
|
|
{Map<String, dynamic>? params}) async {
|
|
final response = await _dio.get(path, queryParameters: params);
|
|
return response.data;
|
|
}
|
|
|
|
Future<Map<String, dynamic>> post(String path, {dynamic data}) async {
|
|
final response = await _dio.post(path, data: data);
|
|
return response.data;
|
|
}
|
|
|
|
Future<Map<String, dynamic>> put(String path, {dynamic data}) async {
|
|
final response = await _dio.put(path, data: data);
|
|
return response.data;
|
|
}
|
|
|
|
Future<void> patch(String path,
|
|
{dynamic data, Map<String, dynamic>? params}) async {
|
|
await _dio.patch(path, data: data, queryParameters: params);
|
|
}
|
|
|
|
/// Posts data and expects a JSON array response.
|
|
Future<List<dynamic>> postList(String path, {dynamic data}) async {
|
|
final response = await _dio.post(path, data: data);
|
|
return response.data as List<dynamic>;
|
|
}
|
|
|
|
Future<Map<String, dynamic>> delete(String path) async {
|
|
final response = await _dio.delete(path);
|
|
return response.data;
|
|
}
|
|
|
|
/// Returns a list for endpoints that respond with a JSON array.
|
|
Future<List<dynamic>> getList(String path,
|
|
{Map<String, dynamic>? params}) async {
|
|
final response = await _dio.get(path, queryParameters: params);
|
|
return response.data as List<dynamic>;
|
|
}
|
|
|
|
/// Deletes a resource and expects no response body (204 No Content).
|
|
Future<void> deleteVoid(String path) async {
|
|
await _dio.delete(path);
|
|
}
|
|
}
|