refactor(apps): 主题系统迁移至 ColorScheme + 扩展架构并支持 Dark Mode
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../../../core/network/i_api_client.dart';
|
||||
import '../../../../data/models/user_profile.dart';
|
||||
|
||||
class UserProfileService {
|
||||
static const _prefix = '/api/v1/users';
|
||||
|
||||
final IApiClient _client;
|
||||
|
||||
UserProfileService(this._client);
|
||||
|
||||
Future<UserProfile> getMe() async {
|
||||
final response = await _client.get<Map<String, dynamic>>('$_prefix/me');
|
||||
final data = response.data;
|
||||
if (data == null) {
|
||||
throw StateError('Invalid getMe response: empty payload');
|
||||
}
|
||||
return UserProfile.fromJson(data);
|
||||
}
|
||||
|
||||
Future<UserProfile> updateMe(UserUpdateRequest request) async {
|
||||
final response = await _client.patch<Map<String, dynamic>>(
|
||||
'$_prefix/me',
|
||||
data: request.toJson(),
|
||||
);
|
||||
final data = response.data;
|
||||
if (data == null) {
|
||||
throw StateError('Invalid updateMe response: empty payload');
|
||||
}
|
||||
return UserProfile.fromJson(data);
|
||||
}
|
||||
|
||||
Future<String> uploadAvatar(File file) async {
|
||||
final formData = FormData.fromMap({
|
||||
'file': await MultipartFile.fromFile(
|
||||
file.path,
|
||||
filename: file.path.split('/').last,
|
||||
),
|
||||
});
|
||||
final response = await _client.post<Map<String, dynamic>>(
|
||||
'$_prefix/me/avatar',
|
||||
data: formData,
|
||||
);
|
||||
final data = response.data;
|
||||
if (data == null || data['url'] is! String) {
|
||||
throw StateError('Invalid uploadAvatar response: missing url');
|
||||
}
|
||||
return data['url'] as String;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user