fix
This commit is contained in:
@@ -147,11 +147,12 @@ class ApiService {
|
||||
}
|
||||
|
||||
dynamic balanceRaw = profileData["balance"];
|
||||
int? balance;
|
||||
if (balanceRaw is int) {
|
||||
balance = balanceRaw;
|
||||
double? balance;
|
||||
|
||||
if (balanceRaw is num) {
|
||||
balance = balanceRaw.toDouble();
|
||||
} else if (balanceRaw is String) {
|
||||
balance = int.tryParse(balanceRaw);
|
||||
balance = double.tryParse(balanceRaw);
|
||||
}
|
||||
|
||||
return UserProfile(
|
||||
@@ -238,11 +239,11 @@ class ApiService {
|
||||
}
|
||||
|
||||
dynamic balanceRaw = data["balance"];
|
||||
int? balance;
|
||||
if (balanceRaw is int) {
|
||||
double? balance;
|
||||
if (balanceRaw is double) {
|
||||
balance = balanceRaw;
|
||||
} else if (balanceRaw is String) {
|
||||
balance = int.tryParse(balanceRaw);
|
||||
balance = double.tryParse(balanceRaw);
|
||||
}
|
||||
|
||||
return UserProfile(
|
||||
@@ -420,7 +421,7 @@ class ApiService {
|
||||
int page = 1,
|
||||
int pageSize = 500,
|
||||
}) async {
|
||||
const path = "$baseUrl/zone/available";
|
||||
const path = "$baseUrl/zone/available2";
|
||||
|
||||
final queryParams = {
|
||||
'readAll': 'true',
|
||||
@@ -708,17 +709,13 @@ class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<ScooterOrder?> cancelRide(int orderId) async {
|
||||
Future<void> cancelRide(int orderId) async {
|
||||
try {
|
||||
final response = await _dio.put(
|
||||
"$baseUrl/scooterorder/$orderId/cancel",
|
||||
options: await _getAuthOptions(),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
return ScooterOrder.fromJson(response.data);
|
||||
}
|
||||
return null;
|
||||
} on DioException catch (e) {
|
||||
_handleDioError(e);
|
||||
return null;
|
||||
@@ -759,7 +756,7 @@ class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<ScooterOrder?> finishRide({
|
||||
Future<void> finishRide({
|
||||
required int orderId,
|
||||
required List<int> filesId,
|
||||
}) async {
|
||||
@@ -770,10 +767,6 @@ class ApiService {
|
||||
options: await _getAuthOptions(),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
return ScooterOrder.fromJson(response.data);
|
||||
}
|
||||
return null;
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 400) {
|
||||
final data = e.response?.data;
|
||||
@@ -1013,10 +1006,10 @@ class ApiService {
|
||||
if (event.data != null && event.data!.isNotEmpty) {
|
||||
try {
|
||||
final Map<String, dynamic> jsonData = jsonDecode(event.data!);
|
||||
print("✅ [SSE] Parsed JSON: $jsonData");
|
||||
print("[SSE] Parsed JSON: $jsonData");
|
||||
controller.add(jsonData);
|
||||
} catch (e) {
|
||||
print("❌ [SSE] JSON Parse Error: $e | Raw: ${event.data}");
|
||||
print("[SSE] JSON Parse Error: $e | Raw: ${event.data}");
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1034,17 +1027,19 @@ class ApiService {
|
||||
return controller.stream;
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getNotifications() async {
|
||||
final url = Uri.parse('$baseUrl/notification/client');
|
||||
Future<Map<String, dynamic>> getNotifications({
|
||||
int page = 1,
|
||||
int pageSize = 10,
|
||||
}) async {
|
||||
final url = Uri.parse('$baseUrl/notification/client').replace(
|
||||
queryParameters: {
|
||||
'page': page.toString(),
|
||||
'pageSize': pageSize.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
final accessToken = await _securityService.getAccessToken();
|
||||
if (accessToken == null) {
|
||||
print("APISERVICE Error: Access token is null.");
|
||||
throw UnauthorizedException();
|
||||
}
|
||||
|
||||
print("GET NOTIFICATIONS REQUEST:");
|
||||
print("URL: $url");
|
||||
if (accessToken == null) throw UnauthorizedException();
|
||||
|
||||
final response = await http.get(
|
||||
url,
|
||||
@@ -1054,34 +1049,17 @@ class ApiService {
|
||||
},
|
||||
);
|
||||
|
||||
print("GET NOTIFICATIONS RESPONSE:");
|
||||
print("STATUS: ${response.statusCode}");
|
||||
print("BODY: ${response.body}");
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
|
||||
// ✅ Проверяем, является ли ответ массивом или объектом с data[]
|
||||
if (data is List) {
|
||||
return data.cast<Map<String, dynamic>>();
|
||||
} else if (data is Map<String, dynamic>) {
|
||||
final list = data['data'];
|
||||
if (list is List) {
|
||||
return list.cast<Map<String, dynamic>>();
|
||||
} else {
|
||||
throw Exception(
|
||||
'Expected a List under "data" but got ${list.runtimeType}',
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw Exception('Expected a List or Map but got ${data.runtimeType}');
|
||||
if (data is Map<String, dynamic>) {
|
||||
return data;
|
||||
}
|
||||
throw Exception('Expected Map with data and pagination');
|
||||
} else if (response.statusCode == 401) {
|
||||
throw UnauthorizedException();
|
||||
} else if (response.statusCode == 403) {
|
||||
throw AuthBlockException();
|
||||
}
|
||||
|
||||
throw Exception('Ошибка сервера: ${response.statusCode}');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user