fix functional bugs

This commit is contained in:
2026-05-29 11:40:55 +03:00
parent 591265a7fc
commit 134ffdde60
50 changed files with 1086 additions and 771 deletions

View File

@@ -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}');

View File

@@ -40,7 +40,7 @@ class PaymentRepositoryImpl implements PaymentRepository {
required String cvv,
}) async {
try {
final cardId = await apiService.addPaymentCard(
await apiService.addPaymentCard(
cardNumber: cardNumber,
cardHolder: cardHolder,
expirationMonth: int.parse(expiryMonth),
@@ -48,8 +48,7 @@ class PaymentRepositoryImpl implements PaymentRepository {
cvv: cvv,
);
// Сохраняем полный номер карты локально
await securityService.saveCardFullNumber(cardId, cardNumber);
// await securityService.saveCardFullNumber(cardId, cardNumber);
return Success(null);
} on AuthException catch (e) {

View File

@@ -10,6 +10,7 @@ import 'package:be_happy/domain/repositories/scooter_repository.dart';
import '../../core/failures.dart';
import '../../core/result.dart';
import '../../domain/entities/active_scooter_order.dart';
import '../../domain/entities/client_subscription.dart';
import '../../domain/entities/scooter.dart';
import '../../domain/entities/tariff.dart';
import '../../domain/entities/subscription.dart';
@@ -127,8 +128,8 @@ class ScooterRepositoryImpl extends ScooterRepository {
}
@override
Future<Result<List<Subscription>>> getClientSubscriptions() async {
late final Result<List<Subscription>> result;
Future<Result<List<ClientSubscription>>> getClientSubscriptions() async {
late final Result<List<ClientSubscription>> result;
try {
final subscriptions = await _apiService.getClientSubscriptions();
result = Success(subscriptions);
@@ -268,15 +269,12 @@ class ScooterRepositoryImpl extends ScooterRepository {
}
@override
Future<Result<ScooterOrder>> payRide(int orderId) async {
late final Result<ScooterOrder> result;
Future<Result<void>> payRide(int orderId) async {
late final Result<void> result;
try {
final order = await _apiService.payRide(orderId);
if (order != null) {
result = Success(order);
} else {
result = Failure(UnknownFailure("Неизвестная ошибка"));
}
await _apiService.payRide(orderId);
result = Success(null);
} on AuthException catch (e) {
result = Failure(AuthFailure(e.attemptsLeft));
} catch (e) {
@@ -335,23 +333,19 @@ class ScooterRepositoryImpl extends ScooterRepository {
}
@override
Future<Result<ScooterOrder>> payScooterOrderWithPhotos({
Future<Result<void>> payScooterOrderWithPhotos({
required int orderId,
required int? cardId,
required bool isBalance,
}) async {
late final Result<ScooterOrder> result;
late final Result<void> result;
try {
final order = await _apiService.payScooterOrderWithPhotos(
orderId: orderId,
cardId: cardId,
isBalance: isBalance,
);
if (order != null) {
result = Success(order);
} else {
result = Failure(UnknownFailure("Неизвестная ошибка"));
}
result = Success(null);
} on AuthException catch (e) {
result = Failure(AuthFailure(e.attemptsLeft));
} catch (e) {