|
|
|
|
|
|
|
|
|
import 'package:dartz/dartz.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/api/api_client.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/exceptions/api_exception.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/exceptions/api_failure.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/logger_service.dart';
|
|
|
|
|
|
|
|
|
|
abstract class AuthenticationRepo {
|
|
|
|
|
Future<Either<Failure, dynamic>> signIn({required String phone, required String password});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AuthenticationRepoImp implements AuthenticationRepo {
|
|
|
|
|
final ApiClient apiClient;
|
|
|
|
|
final LoggerService loggerService;
|
|
|
|
|
|
|
|
|
|
AuthenticationRepoImp({required this.loggerService, required this.apiClient});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<Either<Failure, dynamic>> signIn({required String phone, required String password}) async {
|
|
|
|
|
try {
|
|
|
|
|
// Mock API call with delayed response
|
|
|
|
|
final result = await Future.delayed(
|
|
|
|
|
const Duration(seconds: 2),
|
|
|
|
|
() => {
|
|
|
|
|
'success': true,
|
|
|
|
|
'data': [
|
|
|
|
|
{
|
|
|
|
|
'id': '1',
|
|
|
|
|
'name': 'Dr. Ahmed Hassan',
|
|
|
|
|
'specialty': 'Cardiology',
|
|
|
|
|
'experience': '10 years',
|
|
|
|
|
'rating': 4.8,
|
|
|
|
|
'image': 'https://example.com/doctor1.jpg'
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (result != null && result is Map && result['success'] != null && result['success'] != null && result['success'] != false) {
|
|
|
|
|
return Right(result);
|
|
|
|
|
} else {
|
|
|
|
|
loggerService.errorLogs(result.toString());
|
|
|
|
|
return Left(ServerFailure(result.toString()));
|
|
|
|
|
}
|
|
|
|
|
} on APIException catch (e) {
|
|
|
|
|
APIError? apiError;
|
|
|
|
|
if (e.error is APIError) {
|
|
|
|
|
apiError = e.error as APIError;
|
|
|
|
|
}
|
|
|
|
|
loggerService.errorLogs(e.toString());
|
|
|
|
|
return Left(ServerFailure(apiError?.errorMessage ?? e.message));
|
|
|
|
|
} catch (e) {
|
|
|
|
|
loggerService.errorLogs(e.toString());
|
|
|
|
|
return Left(ServerFailure(e.toString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|