fix functional bugs
This commit is contained in:
@@ -20,6 +20,7 @@ import 'package:path/path.dart';
|
||||
import 'package:flutter_client_sse/constants/sse_request_type_enum.dart';
|
||||
import 'package:flutter_client_sse/flutter_client_sse.dart';
|
||||
|
||||
import '../../domain/entities/client_subscription.dart';
|
||||
import '../../domain/entities/point.dart';
|
||||
import '../../domain/entities/user_profile.dart';
|
||||
import '../../domain/entities/payment_card.dart';
|
||||
@@ -137,7 +138,8 @@ class ApiService {
|
||||
if (avatarId != null && profileData["avatar"] != null) {
|
||||
final String? avatarPath = profileData["avatar"]["path"];
|
||||
if (avatarPath != null && avatarPath.isNotEmpty) {
|
||||
avatarUrl = Uri.parse(fileBaseUrl).resolve(avatarPath).toString(); }
|
||||
avatarUrl = Uri.parse(fileBaseUrl).resolve(avatarPath).toString();
|
||||
}
|
||||
}
|
||||
|
||||
dynamic balanceRaw = profileData["balance"];
|
||||
@@ -394,19 +396,16 @@ class ApiService {
|
||||
final url = "$baseUrl/scooter/$title/code";
|
||||
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
url,
|
||||
options: await _getAuthOptions(),
|
||||
);
|
||||
final response = await _dio.get(url, options: await _getAuthOptions());
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
return Scooter.fromJson(response.data);
|
||||
}
|
||||
|
||||
|
||||
if (response.statusCode == 404) {
|
||||
throw ScooterNotFoundException(message: "Самокат не найден");
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 401) throw UnauthorizedException();
|
||||
@@ -463,7 +462,7 @@ class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Subscription>> getClientSubscriptions() async {
|
||||
Future<List<ClientSubscription>> getClientSubscriptions() async {
|
||||
const url = "$baseUrl/scootersubscription/client";
|
||||
|
||||
try {
|
||||
@@ -474,14 +473,7 @@ class ApiService {
|
||||
final List<dynamic> items = responseData['data'] ?? [];
|
||||
|
||||
return items.map((item) {
|
||||
final Map<String, dynamic> subscriptionMap =
|
||||
Map<String, dynamic>.from(item['subscription'] ?? {});
|
||||
|
||||
if (item['expiredAt'] != null) {
|
||||
subscriptionMap['activeTo'] = item['expiredAt'];
|
||||
}
|
||||
|
||||
return Subscription.fromJson(subscriptionMap);
|
||||
return ClientSubscription.fromJson(item);
|
||||
}).toList();
|
||||
}
|
||||
return [];
|
||||
@@ -547,7 +539,7 @@ class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> addPaymentCard({
|
||||
Future<void> addPaymentCard({
|
||||
required String cardNumber,
|
||||
required String cardHolder,
|
||||
required int expirationMonth,
|
||||
@@ -571,8 +563,9 @@ class ApiService {
|
||||
);
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
return response.data['id'] as int;
|
||||
return;
|
||||
}
|
||||
|
||||
throw AuthException('Непредвиденный статус: ${response.statusCode}', 0);
|
||||
} on DioException catch (e) {
|
||||
final data = e.response?.data;
|
||||
@@ -674,7 +667,9 @@ class ApiService {
|
||||
final firstError = data['message'][0]['message'].toString();
|
||||
|
||||
if (firstError.contains("Wrong start zone")) {
|
||||
throw WrongZoneException(message: "Некорректная зона для начала поездки.");
|
||||
throw WrongZoneException(
|
||||
message: "Некорректная зона для начала поездки.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -705,7 +700,9 @@ class ApiService {
|
||||
final firstError = data['message'][0]['message'].toString();
|
||||
|
||||
if (firstError.contains("Wrong start zone")) {
|
||||
throw WrongZoneException(message: "Некорректная зона для начала поездки.");
|
||||
throw WrongZoneException(
|
||||
message: "Некорректная зона для начала поездки.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -791,7 +788,9 @@ class ApiService {
|
||||
final firstError = data['message'][0]['message'].toString();
|
||||
|
||||
if (firstError.contains("Wrong start zone")) {
|
||||
throw WrongZoneException(message: "Некорректная зона для завершения поездки.");
|
||||
throw WrongZoneException(
|
||||
message: "Некорректная зона для завершения поездки.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -803,7 +802,7 @@ class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<ScooterOrder?> payRide(int orderId) async {
|
||||
Future<void> payRide(int orderId) async {
|
||||
try {
|
||||
final response = await _dio.put(
|
||||
"$baseUrl/scooterorder/$orderId/pay",
|
||||
@@ -811,12 +810,12 @@ class ApiService {
|
||||
);
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
return ScooterOrder.fromJson(response.data);
|
||||
// return ScooterOrder.fromJson(response.data);
|
||||
return;
|
||||
}
|
||||
return null;
|
||||
} on DioException catch (e) {
|
||||
_handleDioError(e);
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -878,7 +877,7 @@ class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<ScooterOrder?> payScooterOrderWithPhotos({
|
||||
Future<void> payScooterOrderWithPhotos({
|
||||
required int orderId,
|
||||
required int? cardId,
|
||||
required bool isBalance,
|
||||
@@ -891,12 +890,10 @@ class ApiService {
|
||||
);
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
return ScooterOrder.fromJson(response.data);
|
||||
return;
|
||||
}
|
||||
return null;
|
||||
} on DioException catch (e) {
|
||||
_handleDioError(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -918,7 +915,6 @@ class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<List<Point>> getScooterOrderRouteHistory({required int id}) async {
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
@@ -930,13 +926,19 @@ class ApiService {
|
||||
final String routeString = response.data['route'] ?? '[]';
|
||||
final List<dynamic> routeList = json.decode(routeString);
|
||||
|
||||
return routeList.map((item) => Point(
|
||||
(item[1] as num).toDouble(),
|
||||
(item[0] as num).toDouble(),
|
||||
)).toList();
|
||||
return routeList
|
||||
.map(
|
||||
(item) => Point(
|
||||
(item[1] as num).toDouble(),
|
||||
(item[0] as num).toDouble(),
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
throw RouteHistoryNotFoundException(message: "История маршрута не найдена");
|
||||
throw RouteHistoryNotFoundException(
|
||||
message: "История маршрута не найдена",
|
||||
);
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 401) throw UnauthorizedException();
|
||||
if (e.response?.statusCode == 403) throw AuthBlockException();
|
||||
@@ -1073,7 +1075,9 @@ class ApiService {
|
||||
if (list is List) {
|
||||
return list.cast<Map<String, dynamic>>();
|
||||
} else {
|
||||
throw Exception('Expected a List under "data" but got ${list.runtimeType}');
|
||||
throw Exception(
|
||||
'Expected a List under "data" but got ${list.runtimeType}',
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw Exception('Expected a List or Map but got ${data.runtimeType}');
|
||||
|
||||
Reference in New Issue
Block a user