58 lines
1.5 KiB
Dart
58 lines
1.5 KiB
Dart
import 'package:dio/dio.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:quiz_app/core/endpoint/api_endpoint.dart';
|
|
import 'package:quiz_app/core/utils/logger.dart';
|
|
import 'package:quiz_app/data/models/base/base_model.dart';
|
|
import 'package:quiz_app/data/models/user/user_full_model.dart';
|
|
import 'package:quiz_app/data/providers/dio_client.dart';
|
|
|
|
class UserService extends GetxService {
|
|
late final Dio _dio;
|
|
|
|
@override
|
|
void onInit() {
|
|
_dio = Get.find<ApiClient>().dio;
|
|
super.onInit();
|
|
}
|
|
|
|
Future<bool> updateProfileData(String id, String name, {String? birthDate, String? locale, String? phone}) async {
|
|
try {
|
|
final response = await _dio.post(APIEndpoint.userUpdate, data: {
|
|
"id": id,
|
|
"name": name,
|
|
"birth_date": birthDate,
|
|
"locale": locale,
|
|
"phone": phone,
|
|
});
|
|
|
|
if (response.statusCode == 200) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
} catch (e) {
|
|
logC.e("update profile error: $e");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
Future<BaseResponseModel<UserFullModel>?> getUserData(String id) async {
|
|
try {
|
|
final response = await _dio.get("${APIEndpoint.userData}/$id");
|
|
|
|
if (response.statusCode == 200) {
|
|
final parsedResponse = BaseResponseModel<UserFullModel>.fromJson(
|
|
response.data,
|
|
(data) => UserFullModel.fromJson(data),
|
|
);
|
|
return parsedResponse;
|
|
} else {
|
|
return null;
|
|
}
|
|
} catch (e) {
|
|
logC.e("get user data error: $e");
|
|
return null;
|
|
}
|
|
}
|
|
}
|