54 lines
1.5 KiB
Dart
54 lines
1.5 KiB
Dart
|
|
import 'dart:developer';
|
||
|
|
|
||
|
|
import 'package:injectable/injectable.dart';
|
||
|
|
import 'package:data_channel/data_channel.dart';
|
||
|
|
|
||
|
|
import '../../../common/api/api_client.dart';
|
||
|
|
import '../../../common/api/api_failure.dart';
|
||
|
|
import '../../../common/url/api_path.dart';
|
||
|
|
import '../../../domain/auth/auth.dart';
|
||
|
|
import '../auth_dtos.dart';
|
||
|
|
|
||
|
|
@injectable
|
||
|
|
class AuthRemoteDataProvider {
|
||
|
|
final ApiClient _apiClient;
|
||
|
|
final String _logName = "AuthRemoteDataProvider";
|
||
|
|
|
||
|
|
AuthRemoteDataProvider(this._apiClient);
|
||
|
|
|
||
|
|
Future<DC<AuthFailure, CheckPhoneDto>> checkPhone({
|
||
|
|
required String phoneNumber,
|
||
|
|
}) async {
|
||
|
|
try {
|
||
|
|
final response = await _apiClient.post(
|
||
|
|
ApiPath.checkPhone,
|
||
|
|
data: {'phone_number': phoneNumber},
|
||
|
|
);
|
||
|
|
|
||
|
|
if (response.data['code'] == 401) {
|
||
|
|
return DC.error(
|
||
|
|
AuthFailure.serverError(
|
||
|
|
ApiFailure.unauthorized('Incorrect email or password'),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (response.data['success'] == false) {
|
||
|
|
if ((response.data['errors'] as List).isNotEmpty) {
|
||
|
|
if (response.data['errors'][0]['code'] == 303) {
|
||
|
|
return DC.error(
|
||
|
|
AuthFailure.dynamicErrorMessage('No. Telepon Tidak Boleh Kosong'),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
final dto = CheckPhoneDto.fromJson(response.data['data']);
|
||
|
|
return DC.data(dto);
|
||
|
|
} on ApiFailure catch (e, s) {
|
||
|
|
log('checkPhone', name: _logName, error: e, stackTrace: s);
|
||
|
|
return DC.error(AuthFailure.serverError(e));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|