new project stable version
This commit is contained in:
42
lib/data/repositories/app_settings_repository_impl.dart
Normal file
42
lib/data/repositories/app_settings_repository_impl.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'package:be_happy/data/service/app_setting_service.dart';
|
||||
import 'package:be_happy/domain/entities/map_settings.dart';
|
||||
import 'package:be_happy/domain/repositories/app_settings_repository.dart';
|
||||
|
||||
class AppSettingsRepositoryImpl extends AppSettingsRepository {
|
||||
static const String SHOW_ALL_PLACEMARKS = "all_placemarks";
|
||||
static const String SHOW_ALL_ZONES = "all_zones";
|
||||
static const String SHOW_PARKING_ZONES = "parking_zones";
|
||||
static const String SHOW_RESTRICTED_PARKING_ZONES = "restricted_parking_zones";
|
||||
static const String SHOW_RESTRICTED_DRIVING_ZONES = "restricted_driving_zones";
|
||||
|
||||
final AppSettingsService appSettingsService;
|
||||
|
||||
AppSettingsRepositoryImpl(this.appSettingsService);
|
||||
|
||||
@override
|
||||
Future<MapSettings> getMapSettings() async {
|
||||
MapSettings settings = MapSettings(
|
||||
all_placemarks: appSettingsService.getMapSettingsFlag(
|
||||
SHOW_ALL_PLACEMARKS),
|
||||
all_zones: appSettingsService.getMapSettingsFlag(
|
||||
SHOW_ALL_ZONES),
|
||||
parking_zones: appSettingsService.getMapSettingsFlag(
|
||||
SHOW_PARKING_ZONES),
|
||||
restricted_parking_zones: appSettingsService.getMapSettingsFlag(
|
||||
SHOW_RESTRICTED_PARKING_ZONES),
|
||||
restricted_driving_zones: appSettingsService.getMapSettingsFlag(
|
||||
SHOW_RESTRICTED_DRIVING_ZONES)
|
||||
);
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> saveMapSettings(MapSettings settings) async {
|
||||
appSettingsService.saveMapSettingsFlag(SHOW_ALL_PLACEMARKS, settings.all_placemarks);
|
||||
appSettingsService.saveMapSettingsFlag(SHOW_ALL_ZONES, settings.all_zones);
|
||||
appSettingsService.saveMapSettingsFlag(SHOW_PARKING_ZONES, settings.parking_zones);
|
||||
appSettingsService.saveMapSettingsFlag(SHOW_RESTRICTED_PARKING_ZONES, settings.restricted_parking_zones);
|
||||
appSettingsService.saveMapSettingsFlag(SHOW_RESTRICTED_DRIVING_ZONES, settings.restricted_driving_zones);
|
||||
}
|
||||
}
|
||||
85
lib/data/repositories/auth_repository_impl.dart
Normal file
85
lib/data/repositories/auth_repository_impl.dart
Normal file
@@ -0,0 +1,85 @@
|
||||
import 'package:be_happy/core/failures.dart';
|
||||
import 'package:be_happy/core/result.dart';
|
||||
import 'package:be_happy/data/exceptions/auth_block_exception.dart';
|
||||
import 'package:be_happy/data/exceptions/auth_exception.dart';
|
||||
import 'package:be_happy/data/repositories/pin_repository_impl.dart';
|
||||
import 'package:be_happy/domain/service/device_info_service.dart';
|
||||
import 'package:be_happy/domain/service/security_service.dart';
|
||||
|
||||
import '../../domain/repositories/auth_repository.dart';
|
||||
import '../../domain/entities/user_auth_data.dart';
|
||||
|
||||
import '../network/api_service.dart';
|
||||
|
||||
class AuthRepositoryImpl implements AuthRepository {
|
||||
final ApiService _apiService;
|
||||
final DeviceInfoService _deviceInfoService;
|
||||
final SecurityService _securityService;
|
||||
|
||||
String tempToken = "";
|
||||
|
||||
AuthRepositoryImpl(
|
||||
this._apiService,
|
||||
this._deviceInfoService,
|
||||
this._securityService,
|
||||
);
|
||||
|
||||
@override
|
||||
Future<String> login(String phone) async {
|
||||
final systemId = await _deviceInfoService.getSystemId() ?? "UnknownId";
|
||||
final deviceModel = await _deviceInfoService.getDeviceModel();
|
||||
|
||||
final response = await _apiService.sendPhone(phone, deviceModel, systemId);
|
||||
if (response != null) {
|
||||
tempToken = response;
|
||||
print("TEMP TOKEN IS $tempToken");
|
||||
return response;
|
||||
} else {
|
||||
throw Exception("Login failed");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<void>> verifyCode(String code, String token) async {
|
||||
late final Result<UserAuthData> result;
|
||||
try {
|
||||
final response = await _apiService.verifyCode(code, tempToken);
|
||||
if (response != null) {
|
||||
final authData = UserAuthData(
|
||||
accessToken: response["accessToken"]!,
|
||||
refreshToken: response["refreshToken"]!,
|
||||
);
|
||||
await _securityService.saveTokens(authData);
|
||||
result = Success(null);
|
||||
}
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} on AuthBlockException {
|
||||
result = Failure(AuthBlockFailure("Ошибка. Вы заблокированы."));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<UserAuthData> refreshToken() async {
|
||||
final response = await _apiService.refresh();
|
||||
print("REFRESH: $response");
|
||||
if (response != null) {
|
||||
final authData = UserAuthData(
|
||||
accessToken: response["accessToken"]!,
|
||||
refreshToken: response["refreshToken"]!,
|
||||
);
|
||||
await _securityService.saveTokens(authData);
|
||||
return authData;
|
||||
} else {
|
||||
throw Exception("Refresh token failed");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> logout() async {
|
||||
await _securityService.removeTokens();
|
||||
}
|
||||
}
|
||||
59
lib/data/repositories/certificate_repository_impl.dart
Normal file
59
lib/data/repositories/certificate_repository_impl.dart
Normal file
@@ -0,0 +1,59 @@
|
||||
import '../../core/failures.dart';
|
||||
import '../../core/result.dart';
|
||||
import '../../domain/entities/certificate.dart';
|
||||
import '../../domain/repositories/certificate_repository.dart';
|
||||
import '../../domain/service/security_service.dart';
|
||||
import '../network/api_service.dart';
|
||||
import '../exceptions/auth_exception.dart';
|
||||
import '../exceptions/auth_block_exception.dart';
|
||||
import '../exceptions/unauthorized_exception.dart';
|
||||
|
||||
class CertificateRepositoryImpl implements CertificateRepository {
|
||||
final ApiService apiService;
|
||||
final SecurityService securityService;
|
||||
|
||||
CertificateRepositoryImpl(this.apiService, this.securityService);
|
||||
|
||||
@override
|
||||
Future<Result<List<Certificate>>> getCertificates() async {
|
||||
try {
|
||||
final certificates = await apiService.getCertificates();
|
||||
return Success(certificates);
|
||||
} on AuthException catch (e) {
|
||||
return Failure(AuthFailure(e.attemptsLeft));
|
||||
} on AuthBlockException catch (_) {
|
||||
return Failure(AuthBlockFailure("Ошибка. Вы заблокированы."));
|
||||
} on UnauthorizedException catch (_) {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
} catch (e) {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<Map<String, dynamic>>> purchaseCertificate({
|
||||
required int certificateId,
|
||||
required int cardId,
|
||||
}) async {
|
||||
try {
|
||||
final result = await apiService.purchaseCertificate(
|
||||
certificateId: certificateId,
|
||||
cardId: cardId,
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
return Success(result);
|
||||
} else {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
} on AuthException catch (e) {
|
||||
return Failure(AuthFailure(e.attemptsLeft));
|
||||
} on AuthBlockException catch (_) {
|
||||
return Failure(AuthBlockFailure("Ошибка. Вы заблокированы."));
|
||||
} on UnauthorizedException catch (_) {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
} catch (e) {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
}
|
||||
}
|
||||
46
lib/data/repositories/news_repository_impl.dart
Normal file
46
lib/data/repositories/news_repository_impl.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import '../../domain/entities/news.dart';
|
||||
import '../../domain/repositories/news_repository.dart';
|
||||
import '../service/news_api_service.dart';
|
||||
import 'dart:developer' as dev;
|
||||
|
||||
class NewsRepositoryImpl implements NewsRepository {
|
||||
final NewsApiService _apiService;
|
||||
|
||||
NewsRepositoryImpl(this._apiService);
|
||||
|
||||
@override
|
||||
Future<List<NewsEntity>> getNews() async {
|
||||
try {
|
||||
dev.log('NewsRepository: Загрузка новостей...');
|
||||
|
||||
final response = await _apiService.getNews();
|
||||
final List<dynamic> data = response['data'] ?? [];
|
||||
|
||||
final newsList = data.map((json) => NewsEntity.fromJson(json)).toList();
|
||||
|
||||
dev.log('NewsRepository: Загружено ${newsList.length} новостей');
|
||||
|
||||
return newsList;
|
||||
} catch (e, stackTrace) {
|
||||
dev.log('NewsRepository: Ошибка: $e', stackTrace: stackTrace);
|
||||
throw Exception('Не удалось загрузить новости: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<NewsEntity> getNewsById(int id) async {
|
||||
try {
|
||||
dev.log('NewsRepository: Загрузка новости с ID: $id');
|
||||
|
||||
final response = await _apiService.getNewsById(id);
|
||||
|
||||
final news = NewsEntity.fromJson(response);
|
||||
|
||||
dev.log('NewsRepository: Успешно загружена новость с ID: $id');
|
||||
return news;
|
||||
} catch (e, stackTrace) {
|
||||
dev.log('NewsRepository: Ошибка: $e', stackTrace: stackTrace);
|
||||
throw Exception('Не удалось загрузить новость: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
36
lib/data/repositories/notification_repository_impl.dart
Normal file
36
lib/data/repositories/notification_repository_impl.dart
Normal file
@@ -0,0 +1,36 @@
|
||||
import 'package:be_happy/domain/entities/client_notification.dart';
|
||||
|
||||
import '../../data/network/api_service.dart';
|
||||
import '../../domain/repositories/notification_repository.dart';
|
||||
import '../models/client_notification_dto.dart';
|
||||
|
||||
class NotificationRepositoryImpl implements NotificationRepository {
|
||||
final ApiService _apiService;
|
||||
|
||||
NotificationRepositoryImpl(this._apiService);
|
||||
|
||||
@override
|
||||
Stream<ClientNotification> getNotificationsStream() {
|
||||
return _apiService.getNotificationsStream().map((data) {
|
||||
// Создаем DTO из данных API
|
||||
final dto = ClientNotificationDto.fromJson(data);
|
||||
// Преобразуем в entity
|
||||
return dto.toEntity();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ClientNotification> cancelNotification(int id) async {
|
||||
final data = await _apiService.cancelNotification(id);
|
||||
if (data == null) {
|
||||
throw Exception("Failed to cancel notification");
|
||||
}
|
||||
final dto = ClientNotificationDto.fromJson(data);
|
||||
return dto.toEntity();
|
||||
}
|
||||
|
||||
@override
|
||||
void closeStream() {
|
||||
// соединение закрывается автоматически при отписке от stream
|
||||
}
|
||||
}
|
||||
116
lib/data/repositories/payment_repository_impl.dart
Normal file
116
lib/data/repositories/payment_repository_impl.dart
Normal file
@@ -0,0 +1,116 @@
|
||||
import '../../core/failures.dart';
|
||||
import '../../core/result.dart';
|
||||
import '../../domain/entities/payment_card.dart';
|
||||
import '../../domain/repositories/payment_repository.dart';
|
||||
import '../../domain/service/security_service.dart';
|
||||
import '../network/api_service.dart';
|
||||
import '../exceptions/auth_exception.dart';
|
||||
import '../exceptions/auth_block_exception.dart';
|
||||
import '../exceptions/unauthorized_exception.dart';
|
||||
import '../service/security_service_impl.dart';
|
||||
|
||||
class PaymentRepositoryImpl implements PaymentRepository {
|
||||
final ApiService apiService;
|
||||
final SecurityService securityService;
|
||||
|
||||
PaymentRepositoryImpl(this.apiService, this.securityService);
|
||||
|
||||
@override
|
||||
Future<Result<List<PaymentCard>>> getPaymentCards() async {
|
||||
try {
|
||||
final cards = await apiService.getPaymentCards();
|
||||
return Success(cards);
|
||||
} on AuthException catch (e) {
|
||||
return Failure(AuthFailure(e.attemptsLeft));
|
||||
} on AuthBlockException catch (_) {
|
||||
return Failure(AuthBlockFailure("Ошибка. Вы заблокированы."));
|
||||
} on UnauthorizedException catch (_) {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
} catch (e) {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<void>> addPaymentCard({
|
||||
required String cardNumber,
|
||||
required String cardHolder,
|
||||
required String expiryMonth,
|
||||
required String expiryYear,
|
||||
required String cvv,
|
||||
}) async {
|
||||
try {
|
||||
final cardId = await apiService.addPaymentCard(
|
||||
cardNumber: cardNumber,
|
||||
cardHolder: cardHolder,
|
||||
expirationMonth: int.parse(expiryMonth),
|
||||
expirationYear: int.parse(expiryYear),
|
||||
cvv: cvv,
|
||||
);
|
||||
|
||||
// Сохраняем полный номер карты локально
|
||||
await securityService.saveCardFullNumber(cardId, cardNumber);
|
||||
|
||||
return Success(null);
|
||||
} on AuthException catch (e) {
|
||||
return Failure(AuthFailure(e.attemptsLeft));
|
||||
} on AuthBlockException catch (_) {
|
||||
return Failure(AuthBlockFailure("Ошибка. Вы заблокированы."));
|
||||
} on UnauthorizedException catch (_) {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
} on FormatException catch (_) {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
} catch (e) {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<void>> setMainPaymentCard(int cardId) async {
|
||||
try {
|
||||
await apiService.setMainPaymentCard(cardId);
|
||||
return Success(null);
|
||||
} on AuthException catch (e) {
|
||||
return Failure(AuthFailure(e.attemptsLeft));
|
||||
} on AuthBlockException catch (_) {
|
||||
return Failure(AuthBlockFailure("Ошибка. Вы заблокированы."));
|
||||
} on UnauthorizedException catch (_) {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
} catch (e) {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<void>> removePaymentCard(int cardId) async {
|
||||
try {
|
||||
await apiService.removePaymentCard(cardId);
|
||||
await securityService.removeCardFullNumber(cardId);
|
||||
return Success(null);
|
||||
} on AuthException catch (e) {
|
||||
return Failure(AuthFailure(e.attemptsLeft));
|
||||
} on AuthBlockException catch (_) {
|
||||
return Failure(AuthBlockFailure("Ошибка. Вы заблокированы."));
|
||||
} on UnauthorizedException catch (_) {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
} catch (e) {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<bool>> activateSubscription(int optionId) async {
|
||||
try {
|
||||
final success = await apiService.activateSubscription(optionId: optionId);
|
||||
return Success(success);
|
||||
} on AuthException catch (e) {
|
||||
return Failure(AuthFailure(e.attemptsLeft));
|
||||
} on AuthBlockException catch (_) {
|
||||
return Failure(AuthBlockFailure("Ошибка. Вы заблокированы."));
|
||||
} on UnauthorizedException catch (_) {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
} catch (e) {
|
||||
return Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
}
|
||||
}
|
||||
24
lib/data/repositories/pin_repository_impl.dart
Normal file
24
lib/data/repositories/pin_repository_impl.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:be_happy/domain/repositories/pin_repository.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
class PinRepositoryImpl implements PinRepository {
|
||||
final FlutterSecureStorage _storage;
|
||||
|
||||
PinRepositoryImpl(this._storage);
|
||||
|
||||
@override
|
||||
Future<String?> getSavedPin() {
|
||||
return _storage.read(key: "user_pin");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> savePin(String? pin) async {
|
||||
await _storage.write(key: "user_pin", value: pin);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removePin() async {
|
||||
await _storage.delete(key: "user_pin");
|
||||
}
|
||||
}
|
||||
|
||||
48
lib/data/repositories/profile_repository_impl.dart
Normal file
48
lib/data/repositories/profile_repository_impl.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:be_happy/data/network/api_service.dart';
|
||||
|
||||
import '../../domain/entities/user_profile.dart';
|
||||
import '../../domain/entities/user_check_flags.dart';
|
||||
import '../../domain/repositories/profile_repository.dart';
|
||||
|
||||
class UserProfileRepositoryImpl implements UserProfileRepository {
|
||||
final ApiService _apiService;
|
||||
|
||||
static const String kAccessToken = "access_token";
|
||||
static const String kRefreshToken = "refresh_token";
|
||||
|
||||
final UserProfile _cachedProfile = UserProfile(
|
||||
name: 'Иванов Антон',
|
||||
birthDate: '12-03-2005',
|
||||
phone: '+375 00 000-00-00',
|
||||
balance: null,
|
||||
email: 'почта@gmail.com',
|
||||
);
|
||||
|
||||
UserProfileRepositoryImpl(this._apiService);
|
||||
|
||||
@override
|
||||
Future<UserProfile> getProfile() async {
|
||||
return await _apiService.getProfile() ?? _cachedProfile;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<UserProfile?> updateProfile(UserProfile profile) async {
|
||||
//await Future.delayed(const Duration(milliseconds: 300));
|
||||
print("UPDATE PROFILE DATA: $profile");
|
||||
return await _apiService.updateProfile(profile);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int?> uploadProfilePhoto(File imageFile) async {
|
||||
return await _apiService.uploadPhoto(imageFile);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<UserCheckFlags?> checkUser() async {
|
||||
return await _apiService.checkUser();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
444
lib/data/repositories/scooter_repository_impl.dart
Normal file
444
lib/data/repositories/scooter_repository_impl.dart
Normal file
@@ -0,0 +1,444 @@
|
||||
import 'dart:io';
|
||||
import 'package:be_happy/data/exceptions/auth_block_exception.dart';
|
||||
import 'package:be_happy/data/exceptions/route_history_not_found_exception.dart';
|
||||
import 'package:be_happy/data/exceptions/scooter_not_found_exception.dart';
|
||||
import 'package:be_happy/data/exceptions/unauthorized_exception.dart';
|
||||
import 'package:be_happy/data/exceptions/wrong_zone_exception.dart';
|
||||
import 'package:be_happy/domain/entities/point.dart';
|
||||
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/scooter.dart';
|
||||
import '../../domain/entities/tariff.dart';
|
||||
import '../../domain/entities/subscription.dart';
|
||||
import '../../domain/entities/scooter_order.dart';
|
||||
import '../exceptions/auth_exception.dart';
|
||||
import '../network/api_service.dart';
|
||||
|
||||
class ScooterRepositoryImpl extends ScooterRepository {
|
||||
final ApiService _apiService;
|
||||
|
||||
final scooter = Scooter(
|
||||
id: 123,
|
||||
title: "Unnamed",
|
||||
status: "Available",
|
||||
latitude: 55.178960,
|
||||
longitude: 30.222316,
|
||||
batteryLevel: 89,
|
||||
isOnline: true,
|
||||
maxSpeed: 25,
|
||||
number: "Unnamed",
|
||||
);
|
||||
|
||||
ScooterRepositoryImpl(this._apiService);
|
||||
|
||||
@override
|
||||
Future<List<Scooter>> getScooters(
|
||||
List<double> area,
|
||||
int page,
|
||||
int pageSize,
|
||||
) async {
|
||||
final responce = await _apiService.getScooters(
|
||||
area: area,
|
||||
page: page,
|
||||
pageSize: pageSize,
|
||||
);
|
||||
|
||||
final List<Scooter>? list = responce?.scooters;
|
||||
// list?.add(scooter);
|
||||
|
||||
// print("Scooters: ${list?.first.status}");
|
||||
|
||||
if (responce != null) {
|
||||
return list ?? List.empty();
|
||||
}
|
||||
|
||||
return List.empty();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<Scooter?>> getScooter(int id) async {
|
||||
late final Result<Scooter> result;
|
||||
try {
|
||||
final scooter = await _apiService.getScooterById(id: id);
|
||||
if (scooter != null) {
|
||||
result = Success(scooter);
|
||||
}
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<List<Tariff>>> getAvailableTariffs(int scooterId) async {
|
||||
late final Result<List<Tariff>> result;
|
||||
try {
|
||||
final response = await _apiService.getAvailableTariffs(
|
||||
scooterId: scooterId,
|
||||
);
|
||||
if (response != null) {
|
||||
result = Success(response.tariffs);
|
||||
} else {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<List<Subscription>>> getAvailableSubscriptions() async {
|
||||
late final Result<List<Subscription>> result;
|
||||
try {
|
||||
final response = await _apiService.getAvailableSubscriptions();
|
||||
if (response != null) {
|
||||
result = Success(response.subscriptions);
|
||||
} else {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<Subscription>> getSubscriptionById(int id) async {
|
||||
late final Result<Subscription> result;
|
||||
try {
|
||||
final subscription = await _apiService.getSubscriptionById(id: id);
|
||||
if (subscription != null) {
|
||||
result = Success(subscription);
|
||||
} else {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<List<Subscription>>> getClientSubscriptions() async {
|
||||
late final Result<List<Subscription>> result;
|
||||
try {
|
||||
final subscriptions = await _apiService.getClientSubscriptions();
|
||||
result = Success(subscriptions);
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<ScooterOrder>> bookScooter({
|
||||
required int scooterId,
|
||||
required int planId,
|
||||
int? subscriptionId,
|
||||
int? cardId,
|
||||
required bool isBalance,
|
||||
required bool isInsurance,
|
||||
}) async {
|
||||
late final Result<ScooterOrder> result;
|
||||
try {
|
||||
final order = await _apiService.bookScooter(
|
||||
scooterId: scooterId,
|
||||
planId: planId,
|
||||
subscriptionId: subscriptionId,
|
||||
cardId: cardId,
|
||||
isBalance: isBalance,
|
||||
isInsurance: isInsurance,
|
||||
);
|
||||
if (order != null) {
|
||||
result = Success(order);
|
||||
} else {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<ScooterOrder>> startRide(int orderId) async {
|
||||
late final Result<ScooterOrder> result;
|
||||
try {
|
||||
final order = await _apiService.startRide(orderId);
|
||||
if (order != null) {
|
||||
result = Success(order);
|
||||
} else {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<ScooterOrder>> cancelRide(int orderId) async {
|
||||
late final Result<ScooterOrder> result;
|
||||
try {
|
||||
final order = await _apiService.cancelRide(orderId);
|
||||
if (order != null) {
|
||||
result = Success(order);
|
||||
} else {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<ScooterOrder>> pauseRide(int orderId) async {
|
||||
late final Result<ScooterOrder> result;
|
||||
try {
|
||||
final order = await _apiService.pauseRide(orderId);
|
||||
if (order != null) {
|
||||
result = Success(order);
|
||||
} else {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<ScooterOrder>> resumeRide(int orderId) async {
|
||||
late final Result<ScooterOrder> result;
|
||||
try {
|
||||
final order = await _apiService.resumeRide(orderId);
|
||||
if (order != null) {
|
||||
result = Success(order);
|
||||
} else {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<ScooterOrder>> finishRide(int orderId, List<int> files) async {
|
||||
late final Result<ScooterOrder> result;
|
||||
try {
|
||||
final order = await _apiService.finishRide(
|
||||
orderId: orderId,
|
||||
filesId: files,
|
||||
);
|
||||
if (order != null) {
|
||||
result = Success(order);
|
||||
} else {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} on WrongZoneException catch (e) {
|
||||
result = Failure(WrongZoneFailure(e.message));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<ScooterOrder>> payRide(int orderId) async {
|
||||
late final Result<ScooterOrder> result;
|
||||
try {
|
||||
final order = await _apiService.payRide(orderId);
|
||||
if (order != null) {
|
||||
result = Success(order);
|
||||
} else {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<List<ScooterOrder>>> getClientOrders() async {
|
||||
late final Result<List<ScooterOrder>> result;
|
||||
try {
|
||||
final orders = await _apiService.getClientOrders();
|
||||
result = Success(orders);
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<List<int>>> uploadScooterPhotos(List<File> images) async {
|
||||
late final Result<List<int>> result;
|
||||
try {
|
||||
final filesId = await _apiService.uploadScooterPhotos(images);
|
||||
result = Success(filesId);
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<ActiveScooterOrder>> updateScooterOrderData({
|
||||
required int orderId,
|
||||
}) async {
|
||||
late final Result<ActiveScooterOrder> result;
|
||||
try {
|
||||
final order = await _apiService.updateScooterOrderData(orderId: orderId);
|
||||
if (order != null) {
|
||||
print("ORDER DATA FROM REPOSITORY: $order");
|
||||
result = Success(order);
|
||||
} else {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<ScooterOrder>> payScooterOrderWithPhotos({
|
||||
required int orderId,
|
||||
required int? cardId,
|
||||
required bool isBalance,
|
||||
}) async {
|
||||
late final Result<ScooterOrder> result;
|
||||
try {
|
||||
final order = await _apiService.payScooterOrderWithPhotos(
|
||||
orderId: orderId,
|
||||
cardId: cardId,
|
||||
isBalance: isBalance,
|
||||
);
|
||||
if (order != null) {
|
||||
result = Success(order);
|
||||
} else {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<ScooterOrder>> getScooterOrderById(int id) async {
|
||||
late final Result<ScooterOrder> result;
|
||||
try {
|
||||
final order = await _apiService.getScooterOrderById(id: id);
|
||||
if (order != null) {
|
||||
result = Success(order);
|
||||
} else {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<List<ScooterOrder>>> getScooterOrderHistory({
|
||||
int page = 1,
|
||||
int pageSize = 20,
|
||||
}) async {
|
||||
late final Result<List<ScooterOrder>> result;
|
||||
try {
|
||||
final response = await _apiService.getScooterOrderHistory(
|
||||
page: page,
|
||||
pageSize: pageSize,
|
||||
);
|
||||
final List<dynamic> data = response['data'] ?? [];
|
||||
final orders = data.map((json) => ScooterOrder.fromJson(json)).toList();
|
||||
result = Success(orders);
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<Scooter?>> getScooterByTitle(String title) async {
|
||||
late final Result<Scooter?> result;
|
||||
try {
|
||||
final scooter = await _apiService.getScooterByTitle(title: title);
|
||||
if (scooter != null) {
|
||||
result = Success(scooter);
|
||||
} else {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
} on ScooterNotFoundException catch (e) {
|
||||
result = Failure(ScooterNotFoundFailure(e.message));
|
||||
} on UnauthorizedException catch (e) {
|
||||
result = Failure(AuthFailure(0, message: e.toString()));
|
||||
} on AuthBlockException catch (e) {
|
||||
result = Failure(AuthBlockFailure(e.toString()));
|
||||
} catch (e, stacktrace) {
|
||||
print("REPOSITORY ERROR: $e");
|
||||
print("STACKTRACE: $stacktrace");
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<List<Point>>> getScooterOrderRouteHistory(int id) async {
|
||||
late final Result<List<Point>> result;
|
||||
try {
|
||||
final route = await _apiService.getScooterOrderRouteHistory(id: id);
|
||||
result = Success(route);
|
||||
} on RouteHistoryNotFoundException catch (e) {
|
||||
result = Failure(RouteHistoryNotFoundFailure(e.message));
|
||||
} on UnauthorizedException catch (e) {
|
||||
result = Failure(AuthFailure(0, message: e.toString()));
|
||||
} on AuthBlockException catch (e) {
|
||||
result = Failure(AuthBlockFailure(e.toString()));
|
||||
} catch (e, stacktrace) {
|
||||
print("REPOSITORY ERROR: $e");
|
||||
print("STACKTRACE: $stacktrace");
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
69
lib/data/repositories/zone_repository_impl.dart
Normal file
69
lib/data/repositories/zone_repository_impl.dart
Normal file
@@ -0,0 +1,69 @@
|
||||
import 'package:be_happy/domain/entities/zone.dart';
|
||||
import 'package:be_happy/domain/repositories/zone_repository.dart';
|
||||
|
||||
import '../../domain/entities/point.dart';
|
||||
import '../network/api_service.dart';
|
||||
|
||||
class ZoneRepositoryImpl extends ZoneRepository {
|
||||
final ApiService _apiService;
|
||||
|
||||
ZoneRepositoryImpl(this._apiService);
|
||||
|
||||
@override
|
||||
Future<List<Zone>> getZones(List<double> area,
|
||||
int page,
|
||||
int pageSize,) async {
|
||||
|
||||
final List<Point> list = [];
|
||||
final List<Point> list2 = [];
|
||||
|
||||
/*list.add(Point(55.182372,30.203347));
|
||||
list.add(Point(55.173746,30.200257));
|
||||
list.add(Point(55.172153,30.212531));
|
||||
list.add(Point(55.179946,30.215964));
|
||||
|
||||
list2.add(Point(55.178304,30.227380));
|
||||
list2.add(Point(55.178059,30.229654));
|
||||
list2.add(Point(55.191339,30.234718));
|
||||
list2.add(Point(55.194352,30.234890));
|
||||
list2.add(Point(55.194377,30.231972));
|
||||
list2.add(Point(55.192123,30.232744));
|
||||
|
||||
final zone = Zone(id: 123,
|
||||
title: "Zone 01",
|
||||
description: "description",
|
||||
type: "Finish",
|
||||
isActive: true,
|
||||
shapeType: "polygon",
|
||||
points: list,
|
||||
speedLimit: "speedLimit");
|
||||
|
||||
final zone2 = Zone(id: 124,
|
||||
title: "Zone 02",
|
||||
description: "description",
|
||||
type: "NotDrive",
|
||||
isActive: true,
|
||||
shapeType: "polygon",
|
||||
points: list2,
|
||||
speedLimit: "speedLimit");
|
||||
*/
|
||||
|
||||
final responce = await _apiService.getZones(
|
||||
area: area,
|
||||
page: page,
|
||||
pageSize: pageSize,
|
||||
);
|
||||
|
||||
final List<Zone>? zones = responce?.zones;
|
||||
// zones?.add(zone);
|
||||
// zones?.add(zone2);
|
||||
|
||||
print("Scooters: ${zones?.first.title}");
|
||||
|
||||
if (responce != null) {
|
||||
return zones ?? List.empty();
|
||||
}
|
||||
|
||||
return List.empty();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user