feat: 重构 memory 系统,支持 user memory 和 work memory 分离

This commit is contained in:
qzl
2026-03-23 14:25:47 +08:00
parent 3aacc756db
commit 6be616f108
70 changed files with 7031 additions and 431 deletions
@@ -1,38 +1,64 @@
import 'package:flutter/material.dart';
class MemoryItemModel {
final String id;
final IconData icon;
final String title;
final String subtitle;
MemoryItemModel({
required this.id,
required this.icon,
required this.title,
required this.subtitle,
});
}
class MockMemoryService {
static final MockMemoryService _instance = MockMemoryService._internal();
factory MockMemoryService() => _instance;
final List<MemoryItemModel> _items = [];
MockMemoryService._internal();
List<MemoryItemModel> get items => List.unmodifiable(_items);
List<MemoryItemModel> fetchMemoryItems() {
return items;
}
}
import 'package:social_app/core/api/i_api_client.dart';
import '../models/memory_models.dart';
class MemoryService {
final MockMemoryService _mock = MockMemoryService();
final IApiClient _client;
static const _prefix = '/api/v1/memories';
List<MemoryItemModel> getMemoryItems() {
return _mock.fetchMemoryItems();
MemoryService(this._client);
Future<MemoryListResponse> getAllMemories() async {
final response = await _client.get<Map<String, dynamic>>(_prefix);
return MemoryListResponse.fromJson(response.data!);
}
Future<UserMemoryContent?> getUserMemory() async {
final response = await _client.get<Map<String, dynamic>>('$_prefix/user');
if (response.data == null) return null;
return UserMemoryContent.fromJson(response.data);
}
Future<WorkProfileContent?> getWorkMemory() async {
final response = await _client.get<Map<String, dynamic>>('$_prefix/work');
if (response.data == null) return null;
return WorkProfileContent.fromJson(response.data);
}
Future<UserMemoryContent> updateUserMemory(UserMemoryContent content) async {
final response = await _client.put<Map<String, dynamic>>(
'$_prefix/user',
data: {'content': content.toJson()},
);
return UserMemoryContent.fromJson(response.data);
}
Future<WorkProfileContent> updateWorkMemory(
WorkProfileContent content,
) async {
final response = await _client.put<Map<String, dynamic>>(
'$_prefix/work',
data: {'content': content.toJson()},
);
return WorkProfileContent.fromJson(response.data);
}
Future<UserMemoryContent> patchUserMemory(
Map<String, dynamic> content,
) async {
final response = await _client.patch<Map<String, dynamic>>(
'$_prefix/user',
data: {'content': content},
);
return UserMemoryContent.fromJson(response.data);
}
Future<WorkProfileContent> patchWorkMemory(
Map<String, dynamic> content,
) async {
final response = await _client.patch<Map<String, dynamic>>(
'$_prefix/work',
data: {'content': content},
);
return WorkProfileContent.fromJson(response.data);
}
}