Refactor code structure for improved readability and maintainability
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/api/api_client.dart';
|
||||
import '../../../core/api/api_paths.dart';
|
||||
import '../../../core/api/guarded_api_call.dart';
|
||||
import '../../../core/api/api_exception.dart';
|
||||
import '../../auth/data/auth_providers.dart';
|
||||
import '../domain/user_profile.dart';
|
||||
|
||||
final profileRepositoryProvider = Provider<ProfileRepository>((ref) {
|
||||
final apiClient = ref.read(apiClientProvider);
|
||||
return ProfileRepository(apiClient, ref);
|
||||
return ProfileRepository(ref.watch(apiClientProvider), ref);
|
||||
});
|
||||
|
||||
class ProfileRepository {
|
||||
@@ -15,17 +15,28 @@ class ProfileRepository {
|
||||
|
||||
ProfileRepository(this._apiClient, this._ref);
|
||||
|
||||
Future<Map<String, dynamic>> getProfile() async {
|
||||
return guardedApiCall(
|
||||
Future<UserProfile> getMe() async {
|
||||
final data = await guardedApiCall(
|
||||
_ref,
|
||||
() => _apiClient.getJson('/api/profile'),
|
||||
() => _apiClient.getJson(UserApiPaths.me),
|
||||
);
|
||||
return UserProfile.fromJson(data);
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> updateProfile(Map<String, dynamic> profileData) async {
|
||||
return guardedApiCall(
|
||||
Future<UserProfile> updateMe({
|
||||
String? email,
|
||||
String? firstName,
|
||||
String? lastName,
|
||||
}) async {
|
||||
final body = <String, dynamic>{
|
||||
if (email != null) 'email': email,
|
||||
if (firstName != null) 'firstName': firstName,
|
||||
if (lastName != null) 'lastName': lastName,
|
||||
};
|
||||
final data = await guardedApiCall(
|
||||
_ref,
|
||||
() => _apiClient.patchJson('/api/profile', profileData),
|
||||
() => _apiClient.patchJson(UserApiPaths.me, body: body),
|
||||
);
|
||||
return UserProfile.fromJson(data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user