2026-03-29 20:26:30 +08:00
|
|
|
import 'package:social_app/data/network/i_api_client.dart';
|
2026-03-23 14:25:47 +08:00
|
|
|
import '../models/memory_models.dart';
|
2026-03-10 17:43:17 +08:00
|
|
|
|
2026-03-23 14:25:47 +08:00
|
|
|
class MemoryService {
|
|
|
|
|
final IApiClient _client;
|
|
|
|
|
static const _prefix = '/api/v1/memories';
|
2026-03-10 17:43:17 +08:00
|
|
|
|
2026-03-23 14:25:47 +08:00
|
|
|
MemoryService(this._client);
|
2026-03-10 17:43:17 +08:00
|
|
|
|
2026-03-23 14:25:47 +08:00
|
|
|
Future<MemoryListResponse> getAllMemories() async {
|
|
|
|
|
final response = await _client.get<Map<String, dynamic>>(_prefix);
|
|
|
|
|
return MemoryListResponse.fromJson(response.data!);
|
|
|
|
|
}
|
2026-03-10 17:43:17 +08:00
|
|
|
|
2026-03-23 14:25:47 +08:00
|
|
|
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);
|
|
|
|
|
}
|
2026-03-10 17:43:17 +08:00
|
|
|
|
2026-03-23 14:25:47 +08:00
|
|
|
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);
|
2026-03-10 17:43:17 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-23 14:25:47 +08:00
|
|
|
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);
|
|
|
|
|
}
|
2026-03-10 17:43:17 +08:00
|
|
|
|
2026-03-23 14:25:47 +08:00
|
|
|
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);
|
2026-03-10 17:43:17 +08:00
|
|
|
}
|
|
|
|
|
}
|