feat(account): 接入个人中心接口模型
This commit is contained in:
1 parent
7d68699523
commit
44f6feb249
6 files changed
+501
No files matched your search
@@ -0,0 +1,52 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import '../models/account_device.dart';
|
||||
import '../models/account_export.dart';
|
||||
import '../models/account_profile.dart';
|
||||
import 'api_client.dart';
|
||||
|
||||
/// 个人中心接口:`/app/me*`。
|
||||
class AccountApi {
|
||||
const AccountApi(this._client);
|
||||
|
||||
final ApiClient _client;
|
||||
|
||||
Future<AccountProfile> profile() async {
|
||||
final data = await _client.get('/app/me');
|
||||
return AccountProfile.fromJson(_map(data));
|
||||
}
|
||||
|
||||
Future<AccountProfile> updateProfile(AccountProfileUpdate update) async {
|
||||
final data = await _client.put('/app/me', body: update.toJson());
|
||||
return AccountProfile.fromJson(_map(data));
|
||||
}
|
||||
|
||||
Future<List<AccountDevice>> devices() async {
|
||||
final data = await _client.get('/app/me/devices');
|
||||
if (data is! List) return const [];
|
||||
return [
|
||||
for (final item in data)
|
||||
if (item is Map) AccountDevice.fromJson(item.cast<String, dynamic>()),
|
||||
];
|
||||
}
|
||||
|
||||
Future<AccountExport> export() async {
|
||||
final data = await _client.get('/app/me/export');
|
||||
return AccountExport.fromJson(_map(data));
|
||||
}
|
||||
|
||||
Future<DateTime?> deactivate({String reason = ''}) async {
|
||||
final data = await _client.post(
|
||||
'/app/me/deactivate',
|
||||
body: {'reason': reason.trim()},
|
||||
);
|
||||
return DateTime.tryParse(data?.toString() ?? '');
|
||||
}
|
||||
|
||||
Future<void> cancelDeactivation() async {
|
||||
await _client.post('/app/me/deactivate/cancel');
|
||||
}
|
||||
|
||||
Map<String, dynamic> _map(Object? data) =>
|
||||
data is Map ? data.cast<String, dynamic>() : const {};
|
||||
}
|
||||
Reference in new issue
Block a user