verify repo
This commit is contained in:
@@ -7,3 +7,4 @@ part 'auth_dtos.g.dart';
|
||||
|
||||
part 'dto/check_phone_dto.dart';
|
||||
part 'dto/register_dto.dart';
|
||||
part 'dto/verify_dto.dart';
|
||||
|
||||
@@ -859,3 +859,392 @@ abstract class _RegisterDataDto implements RegisterDataDto {
|
||||
_$$RegisterDataDtoImplCopyWith<_$RegisterDataDtoImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
VerifyDto _$VerifyDtoFromJson(Map<String, dynamic> json) {
|
||||
return _VerifyDto.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$VerifyDto {
|
||||
@JsonKey(name: 'status')
|
||||
String? get status => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'message')
|
||||
String? get message => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'data')
|
||||
VerifyDataDto? get data => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this VerifyDto to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of VerifyDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$VerifyDtoCopyWith<VerifyDto> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $VerifyDtoCopyWith<$Res> {
|
||||
factory $VerifyDtoCopyWith(VerifyDto value, $Res Function(VerifyDto) then) =
|
||||
_$VerifyDtoCopyWithImpl<$Res, VerifyDto>;
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: 'status') String? status,
|
||||
@JsonKey(name: 'message') String? message,
|
||||
@JsonKey(name: 'data') VerifyDataDto? data,
|
||||
});
|
||||
|
||||
$VerifyDataDtoCopyWith<$Res>? get data;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$VerifyDtoCopyWithImpl<$Res, $Val extends VerifyDto>
|
||||
implements $VerifyDtoCopyWith<$Res> {
|
||||
_$VerifyDtoCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of VerifyDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? status = freezed,
|
||||
Object? message = freezed,
|
||||
Object? data = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
status: freezed == status
|
||||
? _value.status
|
||||
: status // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
message: freezed == message
|
||||
? _value.message
|
||||
: message // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
data: freezed == data
|
||||
? _value.data
|
||||
: data // ignore: cast_nullable_to_non_nullable
|
||||
as VerifyDataDto?,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
|
||||
/// Create a copy of VerifyDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$VerifyDataDtoCopyWith<$Res>? get data {
|
||||
if (_value.data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $VerifyDataDtoCopyWith<$Res>(_value.data!, (value) {
|
||||
return _then(_value.copyWith(data: value) as $Val);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$VerifyDtoImplCopyWith<$Res>
|
||||
implements $VerifyDtoCopyWith<$Res> {
|
||||
factory _$$VerifyDtoImplCopyWith(
|
||||
_$VerifyDtoImpl value,
|
||||
$Res Function(_$VerifyDtoImpl) then,
|
||||
) = __$$VerifyDtoImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: 'status') String? status,
|
||||
@JsonKey(name: 'message') String? message,
|
||||
@JsonKey(name: 'data') VerifyDataDto? data,
|
||||
});
|
||||
|
||||
@override
|
||||
$VerifyDataDtoCopyWith<$Res>? get data;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$VerifyDtoImplCopyWithImpl<$Res>
|
||||
extends _$VerifyDtoCopyWithImpl<$Res, _$VerifyDtoImpl>
|
||||
implements _$$VerifyDtoImplCopyWith<$Res> {
|
||||
__$$VerifyDtoImplCopyWithImpl(
|
||||
_$VerifyDtoImpl _value,
|
||||
$Res Function(_$VerifyDtoImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of VerifyDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? status = freezed,
|
||||
Object? message = freezed,
|
||||
Object? data = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_$VerifyDtoImpl(
|
||||
status: freezed == status
|
||||
? _value.status
|
||||
: status // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
message: freezed == message
|
||||
? _value.message
|
||||
: message // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
data: freezed == data
|
||||
? _value.data
|
||||
: data // ignore: cast_nullable_to_non_nullable
|
||||
as VerifyDataDto?,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$VerifyDtoImpl extends _VerifyDto {
|
||||
const _$VerifyDtoImpl({
|
||||
@JsonKey(name: 'status') this.status,
|
||||
@JsonKey(name: 'message') this.message,
|
||||
@JsonKey(name: 'data') this.data,
|
||||
}) : super._();
|
||||
|
||||
factory _$VerifyDtoImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$VerifyDtoImplFromJson(json);
|
||||
|
||||
@override
|
||||
@JsonKey(name: 'status')
|
||||
final String? status;
|
||||
@override
|
||||
@JsonKey(name: 'message')
|
||||
final String? message;
|
||||
@override
|
||||
@JsonKey(name: 'data')
|
||||
final VerifyDataDto? data;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'VerifyDto(status: $status, message: $message, data: $data)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$VerifyDtoImpl &&
|
||||
(identical(other.status, status) || other.status == status) &&
|
||||
(identical(other.message, message) || other.message == message) &&
|
||||
(identical(other.data, data) || other.data == data));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, status, message, data);
|
||||
|
||||
/// Create a copy of VerifyDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$VerifyDtoImplCopyWith<_$VerifyDtoImpl> get copyWith =>
|
||||
__$$VerifyDtoImplCopyWithImpl<_$VerifyDtoImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$VerifyDtoImplToJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _VerifyDto extends VerifyDto {
|
||||
const factory _VerifyDto({
|
||||
@JsonKey(name: 'status') final String? status,
|
||||
@JsonKey(name: 'message') final String? message,
|
||||
@JsonKey(name: 'data') final VerifyDataDto? data,
|
||||
}) = _$VerifyDtoImpl;
|
||||
const _VerifyDto._() : super._();
|
||||
|
||||
factory _VerifyDto.fromJson(Map<String, dynamic> json) =
|
||||
_$VerifyDtoImpl.fromJson;
|
||||
|
||||
@override
|
||||
@JsonKey(name: 'status')
|
||||
String? get status;
|
||||
@override
|
||||
@JsonKey(name: 'message')
|
||||
String? get message;
|
||||
@override
|
||||
@JsonKey(name: 'data')
|
||||
VerifyDataDto? get data;
|
||||
|
||||
/// Create a copy of VerifyDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$VerifyDtoImplCopyWith<_$VerifyDtoImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
VerifyDataDto _$VerifyDataDtoFromJson(Map<String, dynamic> json) {
|
||||
return _VerifyDataDto.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$VerifyDataDto {
|
||||
@JsonKey(name: 'registration_token')
|
||||
String? get registrationToken => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this VerifyDataDto to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of VerifyDataDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$VerifyDataDtoCopyWith<VerifyDataDto> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $VerifyDataDtoCopyWith<$Res> {
|
||||
factory $VerifyDataDtoCopyWith(
|
||||
VerifyDataDto value,
|
||||
$Res Function(VerifyDataDto) then,
|
||||
) = _$VerifyDataDtoCopyWithImpl<$Res, VerifyDataDto>;
|
||||
@useResult
|
||||
$Res call({@JsonKey(name: 'registration_token') String? registrationToken});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$VerifyDataDtoCopyWithImpl<$Res, $Val extends VerifyDataDto>
|
||||
implements $VerifyDataDtoCopyWith<$Res> {
|
||||
_$VerifyDataDtoCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of VerifyDataDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? registrationToken = freezed}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
registrationToken: freezed == registrationToken
|
||||
? _value.registrationToken
|
||||
: registrationToken // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$VerifyDataDtoImplCopyWith<$Res>
|
||||
implements $VerifyDataDtoCopyWith<$Res> {
|
||||
factory _$$VerifyDataDtoImplCopyWith(
|
||||
_$VerifyDataDtoImpl value,
|
||||
$Res Function(_$VerifyDataDtoImpl) then,
|
||||
) = __$$VerifyDataDtoImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({@JsonKey(name: 'registration_token') String? registrationToken});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$VerifyDataDtoImplCopyWithImpl<$Res>
|
||||
extends _$VerifyDataDtoCopyWithImpl<$Res, _$VerifyDataDtoImpl>
|
||||
implements _$$VerifyDataDtoImplCopyWith<$Res> {
|
||||
__$$VerifyDataDtoImplCopyWithImpl(
|
||||
_$VerifyDataDtoImpl _value,
|
||||
$Res Function(_$VerifyDataDtoImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of VerifyDataDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? registrationToken = freezed}) {
|
||||
return _then(
|
||||
_$VerifyDataDtoImpl(
|
||||
registrationToken: freezed == registrationToken
|
||||
? _value.registrationToken
|
||||
: registrationToken // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$VerifyDataDtoImpl implements _VerifyDataDto {
|
||||
const _$VerifyDataDtoImpl({
|
||||
@JsonKey(name: 'registration_token') this.registrationToken,
|
||||
});
|
||||
|
||||
factory _$VerifyDataDtoImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$VerifyDataDtoImplFromJson(json);
|
||||
|
||||
@override
|
||||
@JsonKey(name: 'registration_token')
|
||||
final String? registrationToken;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'VerifyDataDto(registrationToken: $registrationToken)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$VerifyDataDtoImpl &&
|
||||
(identical(other.registrationToken, registrationToken) ||
|
||||
other.registrationToken == registrationToken));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, registrationToken);
|
||||
|
||||
/// Create a copy of VerifyDataDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$VerifyDataDtoImplCopyWith<_$VerifyDataDtoImpl> get copyWith =>
|
||||
__$$VerifyDataDtoImplCopyWithImpl<_$VerifyDataDtoImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$VerifyDataDtoImplToJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _VerifyDataDto implements VerifyDataDto {
|
||||
const factory _VerifyDataDto({
|
||||
@JsonKey(name: 'registration_token') final String? registrationToken,
|
||||
}) = _$VerifyDataDtoImpl;
|
||||
|
||||
factory _VerifyDataDto.fromJson(Map<String, dynamic> json) =
|
||||
_$VerifyDataDtoImpl.fromJson;
|
||||
|
||||
@override
|
||||
@JsonKey(name: 'registration_token')
|
||||
String? get registrationToken;
|
||||
|
||||
/// Create a copy of VerifyDataDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$VerifyDataDtoImplCopyWith<_$VerifyDataDtoImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
@@ -61,3 +61,27 @@ Map<String, dynamic> _$$RegisterDataDtoImplToJson(
|
||||
'otp_token': instance.otpToken,
|
||||
'expires_in': instance.expiresIn,
|
||||
};
|
||||
|
||||
_$VerifyDtoImpl _$$VerifyDtoImplFromJson(Map<String, dynamic> json) =>
|
||||
_$VerifyDtoImpl(
|
||||
status: json['status'] as String?,
|
||||
message: json['message'] as String?,
|
||||
data: json['data'] == null
|
||||
? null
|
||||
: VerifyDataDto.fromJson(json['data'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$VerifyDtoImplToJson(_$VerifyDtoImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'status': instance.status,
|
||||
'message': instance.message,
|
||||
'data': instance.data,
|
||||
};
|
||||
|
||||
_$VerifyDataDtoImpl _$$VerifyDataDtoImplFromJson(Map<String, dynamic> json) =>
|
||||
_$VerifyDataDtoImpl(
|
||||
registrationToken: json['registration_token'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$VerifyDataDtoImplToJson(_$VerifyDataDtoImpl instance) =>
|
||||
<String, dynamic>{'registration_token': instance.registrationToken};
|
||||
|
||||
@@ -96,4 +96,44 @@ class AuthRemoteDataProvider {
|
||||
return DC.error(AuthFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
|
||||
Future<DC<AuthFailure, VerifyDto>> verify({
|
||||
required String registrationToken,
|
||||
required String otpCode,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _apiClient.post(
|
||||
ApiPath.verify,
|
||||
data: {'registration_token': registrationToken, 'otp_code': otpCode},
|
||||
);
|
||||
|
||||
if (response.data['success'] == false) {
|
||||
if ((response.data['errors'] as List).isNotEmpty) {
|
||||
if (response.data['errors'][0]['code'] == "900") {
|
||||
return DC.error(
|
||||
AuthFailure.dynamicErrorMessage('Kode OTP Tidak Sesuai'),
|
||||
);
|
||||
} else {
|
||||
return DC.error(
|
||||
AuthFailure.dynamicErrorMessage(
|
||||
'Terjadi kesalahan coba lagi nanti',
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return DC.error(
|
||||
AuthFailure.dynamicErrorMessage(
|
||||
'Terjadi kesalahan coba lagi nanti',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final dto = VerifyDto.fromJson(response.data['data']);
|
||||
return DC.data(dto);
|
||||
} on ApiFailure catch (e, s) {
|
||||
log('verify', name: _logName, error: e, stackTrace: s);
|
||||
return DC.error(AuthFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
part of '../auth_dtos.dart';
|
||||
|
||||
@freezed
|
||||
class VerifyDto with _$VerifyDto {
|
||||
const factory VerifyDto({
|
||||
@JsonKey(name: 'status') String? status,
|
||||
@JsonKey(name: 'message') String? message,
|
||||
@JsonKey(name: 'data') VerifyDataDto? data,
|
||||
}) = _VerifyDto;
|
||||
|
||||
factory VerifyDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$VerifyDtoFromJson(json);
|
||||
|
||||
const VerifyDto._(); // biar bisa bikin method
|
||||
|
||||
/// mapping ke domain
|
||||
Verify toDomain() => Verify(
|
||||
status: status ?? '',
|
||||
message: message ?? '',
|
||||
registrationToken: data?.registrationToken ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class VerifyDataDto with _$VerifyDataDto {
|
||||
const factory VerifyDataDto({
|
||||
@JsonKey(name: 'registration_token') String? registrationToken,
|
||||
}) = _VerifyDataDto;
|
||||
|
||||
factory VerifyDataDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$VerifyDataDtoFromJson(json);
|
||||
}
|
||||
@@ -57,7 +57,31 @@ class AuthRepository implements IAuthRepository {
|
||||
|
||||
return right(auth);
|
||||
} catch (e, s) {
|
||||
log('checkPhoneError', name: _logName, error: e, stackTrace: s);
|
||||
log('registerError', name: _logName, error: e, stackTrace: s);
|
||||
return left(const AuthFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<AuthFailure, Verify>> verify({
|
||||
required String registrationToken,
|
||||
required String otpCode,
|
||||
}) async {
|
||||
try {
|
||||
final result = await _remoteDataProvider.verify(
|
||||
registrationToken: registrationToken,
|
||||
otpCode: otpCode,
|
||||
);
|
||||
|
||||
if (result.hasError) {
|
||||
return left(result.error!);
|
||||
}
|
||||
|
||||
final auth = result.data!.toDomain();
|
||||
|
||||
return right(auth);
|
||||
} catch (e, s) {
|
||||
log('verifyError', name: _logName, error: e, stackTrace: s);
|
||||
return left(const AuthFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user