feat(app): offline-кэш на остальных экранах — фаза 5
accounts, cashflow, categories, goals, income, portfolio (+instrument), rebalance, tax, rules переведены на Cached<T> по контракту docs/ai/offline-cache.md. Общие/второстепенные селекторы (scopesProvider, categoriesListProvider и т.п.) оставлены как есть — не основной контент экрана. sync_page.dart и settings_page.dart не тронуты (первый — заменён health-page отдельно, второй — чистые действия без списка для баннера).
This commit is contained in:
@@ -11,6 +11,7 @@ library;
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../../core/cache/cached.dart';
|
||||
import '../../../core/utils/json.dart';
|
||||
|
||||
class Goal {
|
||||
@@ -125,11 +126,14 @@ class GoalsApi {
|
||||
|
||||
static const _base = '/api/v1/goals';
|
||||
|
||||
Future<List<Goal>> list() async {
|
||||
/// See `docs/ai/offline-cache.md`: this hand-written client returns `Cached<T>` directly
|
||||
/// (there is no generated `Response<T>` for `GoalsPage` to unwrap `r.cached` from).
|
||||
Future<Cached<List<Goal>>> list() async {
|
||||
final r = await _dio.get<List<dynamic>>(_base);
|
||||
return (r.data ?? const [])
|
||||
final goals = (r.data ?? const [])
|
||||
.map((e) => Goal.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.toList();
|
||||
return Cached(goals, fetchedAt: r.extra['fetchedAt'] as DateTime?);
|
||||
}
|
||||
|
||||
Future<Goal> create(Goal goal) async {
|
||||
@@ -144,8 +148,11 @@ class GoalsApi {
|
||||
|
||||
Future<void> delete(int id) => _dio.delete<void>('$_base/$id');
|
||||
|
||||
Future<GoalProgress> progress(int id) async {
|
||||
Future<Cached<GoalProgress>> progress(int id) async {
|
||||
final r = await _dio.get<Map<String, dynamic>>('$_base/$id/progress');
|
||||
return GoalProgress.fromJson(r.data ?? const {});
|
||||
return Cached(
|
||||
GoalProgress.fromJson(r.data ?? const {}),
|
||||
fetchedAt: r.extra['fetchedAt'] as DateTime?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user