refactor(apps): 重构数据层目录结构并新增启动预热编排器
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
import 'package:social_app/core/network/i_api_client.dart';
|
||||
import '../models/automation_job_model.dart';
|
||||
|
||||
class AutomationJobsApi {
|
||||
final IApiClient _client;
|
||||
static const _prefix = '/api/v1/automation-jobs';
|
||||
|
||||
AutomationJobsApi(this._client);
|
||||
|
||||
Future<List<AutomationJobModel>> list() async {
|
||||
final response = await _client.get(_prefix);
|
||||
final parsed = AutomationJobListResponse.fromJson(response.data);
|
||||
return parsed.items;
|
||||
}
|
||||
|
||||
Future<AutomationJobModel> get(String id) async {
|
||||
final response = await _client.get('$_prefix/$id');
|
||||
return AutomationJobModel.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<AutomationJobModel> create(AutomationJobCreateRequest request) async {
|
||||
final response = await _client.post(_prefix, data: request.toJson());
|
||||
return AutomationJobModel.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<AutomationJobModel> update(
|
||||
String id,
|
||||
AutomationJobUpdateRequest request,
|
||||
) async {
|
||||
final data = request.toJson();
|
||||
final response = await _client.patch('$_prefix/$id', data: data);
|
||||
return AutomationJobModel.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<void> delete(String id) async {
|
||||
await _client.delete('$_prefix/$id');
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'package:social_app/core/network/i_api_client.dart';
|
||||
import 'package:social_app/data/network/i_api_client.dart';
|
||||
import '../models/memory_models.dart';
|
||||
|
||||
class MemoryService {
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
import '../../../../data/cache/cache_policy.dart';
|
||||
import '../../../../data/cache/cached_repository.dart';
|
||||
import '../../../../data/models/user_profile.dart';
|
||||
|
||||
class UserProfileCacheRepository extends CachedRepository<UserProfile> {
|
||||
static const String cacheKey = 'settings:user_profile';
|
||||
|
||||
final Future<UserProfile> Function() remoteLoader;
|
||||
UserProfile? _cachedUser;
|
||||
int _generation = 0;
|
||||
|
||||
UserProfileCacheRepository({
|
||||
required super.store,
|
||||
required this.remoteLoader,
|
||||
CachePolicy? policy,
|
||||
super.now,
|
||||
}) : super(
|
||||
policy:
|
||||
policy ??
|
||||
const CachePolicy(
|
||||
softTtl: Duration(minutes: 2),
|
||||
hardTtl: Duration(minutes: 30),
|
||||
minRefreshInterval: Duration(minutes: 1),
|
||||
),
|
||||
);
|
||||
|
||||
UserProfile? get cachedUser => _cachedUser;
|
||||
|
||||
Future<UserProfile> getProfile({bool forceRefresh = false}) async {
|
||||
final generation = _generation;
|
||||
final user = await getOrLoad(
|
||||
key: cacheKey,
|
||||
forceRefresh: forceRefresh,
|
||||
loadFromRemote: _loadAndRemember,
|
||||
shouldWriteLoaded: (_) => generation == _generation,
|
||||
);
|
||||
if (generation == _generation) {
|
||||
_cachedUser = user;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
Future<void> setCached(UserProfile user) async {
|
||||
final generation = _generation;
|
||||
_cachedUser = user;
|
||||
await writeCacheEntry(cacheKey, user);
|
||||
if (generation != _generation) {
|
||||
_cachedUser = null;
|
||||
await removeCacheKey(cacheKey);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> invalidate() async {
|
||||
_generation += 1;
|
||||
_cachedUser = null;
|
||||
await removeCacheKey(cacheKey);
|
||||
}
|
||||
|
||||
Future<UserProfile> _loadAndRemember() async {
|
||||
final generation = _generation;
|
||||
final remote = await remoteLoader();
|
||||
if (generation == _generation) {
|
||||
_cachedUser = remote;
|
||||
}
|
||||
return remote;
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@ import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../../../core/network/i_api_client.dart';
|
||||
import '../../../../data/models/user_profile.dart';
|
||||
import '../../../../data/network/i_api_client.dart';
|
||||
import '../../../contacts/data/models/user_profile.dart';
|
||||
|
||||
class UserProfileService {
|
||||
static const _prefix = '/api/v1/users';
|
||||
|
||||
Reference in New Issue
Block a user