This commit is contained in:
efrilm
2025-09-18 07:16:56 +07:00
parent b20854f329
commit 3b26b19b25
17 changed files with 1672 additions and 0 deletions
+1
View File
@@ -9,3 +9,4 @@ part 'dto/check_phone_dto.dart';
part 'dto/register_dto.dart';
part 'dto/verify_dto.dart';
part 'dto/login_dto.dart';
part 'dto/resend_dto.dart';
@@ -1945,3 +1945,449 @@ abstract class _UserDto extends UserDto {
_$$UserDtoImplCopyWith<_$UserDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
ResendDto _$ResendDtoFromJson(Map<String, dynamic> json) {
return _ResendDto.fromJson(json);
}
/// @nodoc
mixin _$ResendDto {
@JsonKey(name: 'status')
String? get status => throw _privateConstructorUsedError;
@JsonKey(name: 'message')
String? get message => throw _privateConstructorUsedError;
@JsonKey(name: 'data')
ResendDataDto? get data => throw _privateConstructorUsedError;
/// Serializes this ResendDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of ResendDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ResendDtoCopyWith<ResendDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ResendDtoCopyWith<$Res> {
factory $ResendDtoCopyWith(ResendDto value, $Res Function(ResendDto) then) =
_$ResendDtoCopyWithImpl<$Res, ResendDto>;
@useResult
$Res call({
@JsonKey(name: 'status') String? status,
@JsonKey(name: 'message') String? message,
@JsonKey(name: 'data') ResendDataDto? data,
});
$ResendDataDtoCopyWith<$Res>? get data;
}
/// @nodoc
class _$ResendDtoCopyWithImpl<$Res, $Val extends ResendDto>
implements $ResendDtoCopyWith<$Res> {
_$ResendDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ResendDto
/// 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 ResendDataDto?,
)
as $Val,
);
}
/// Create a copy of ResendDto
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ResendDataDtoCopyWith<$Res>? get data {
if (_value.data == null) {
return null;
}
return $ResendDataDtoCopyWith<$Res>(_value.data!, (value) {
return _then(_value.copyWith(data: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$ResendDtoImplCopyWith<$Res>
implements $ResendDtoCopyWith<$Res> {
factory _$$ResendDtoImplCopyWith(
_$ResendDtoImpl value,
$Res Function(_$ResendDtoImpl) then,
) = __$$ResendDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
@JsonKey(name: 'status') String? status,
@JsonKey(name: 'message') String? message,
@JsonKey(name: 'data') ResendDataDto? data,
});
@override
$ResendDataDtoCopyWith<$Res>? get data;
}
/// @nodoc
class __$$ResendDtoImplCopyWithImpl<$Res>
extends _$ResendDtoCopyWithImpl<$Res, _$ResendDtoImpl>
implements _$$ResendDtoImplCopyWith<$Res> {
__$$ResendDtoImplCopyWithImpl(
_$ResendDtoImpl _value,
$Res Function(_$ResendDtoImpl) _then,
) : super(_value, _then);
/// Create a copy of ResendDto
/// 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(
_$ResendDtoImpl(
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 ResendDataDto?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$ResendDtoImpl extends _ResendDto {
const _$ResendDtoImpl({
@JsonKey(name: 'status') this.status,
@JsonKey(name: 'message') this.message,
@JsonKey(name: 'data') this.data,
}) : super._();
factory _$ResendDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$ResendDtoImplFromJson(json);
@override
@JsonKey(name: 'status')
final String? status;
@override
@JsonKey(name: 'message')
final String? message;
@override
@JsonKey(name: 'data')
final ResendDataDto? data;
@override
String toString() {
return 'ResendDto(status: $status, message: $message, data: $data)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ResendDtoImpl &&
(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 ResendDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ResendDtoImplCopyWith<_$ResendDtoImpl> get copyWith =>
__$$ResendDtoImplCopyWithImpl<_$ResendDtoImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$ResendDtoImplToJson(this);
}
}
abstract class _ResendDto extends ResendDto {
const factory _ResendDto({
@JsonKey(name: 'status') final String? status,
@JsonKey(name: 'message') final String? message,
@JsonKey(name: 'data') final ResendDataDto? data,
}) = _$ResendDtoImpl;
const _ResendDto._() : super._();
factory _ResendDto.fromJson(Map<String, dynamic> json) =
_$ResendDtoImpl.fromJson;
@override
@JsonKey(name: 'status')
String? get status;
@override
@JsonKey(name: 'message')
String? get message;
@override
@JsonKey(name: 'data')
ResendDataDto? get data;
/// Create a copy of ResendDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ResendDtoImplCopyWith<_$ResendDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
ResendDataDto _$ResendDataDtoFromJson(Map<String, dynamic> json) {
return _ResendDataDto.fromJson(json);
}
/// @nodoc
mixin _$ResendDataDto {
@JsonKey(name: 'otp_token')
String? get otpToken => throw _privateConstructorUsedError;
@JsonKey(name: 'expires_in')
int? get expiresIn => throw _privateConstructorUsedError;
@JsonKey(name: 'next_resend_in')
int? get nextResendIn => throw _privateConstructorUsedError;
/// Serializes this ResendDataDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of ResendDataDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ResendDataDtoCopyWith<ResendDataDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ResendDataDtoCopyWith<$Res> {
factory $ResendDataDtoCopyWith(
ResendDataDto value,
$Res Function(ResendDataDto) then,
) = _$ResendDataDtoCopyWithImpl<$Res, ResendDataDto>;
@useResult
$Res call({
@JsonKey(name: 'otp_token') String? otpToken,
@JsonKey(name: 'expires_in') int? expiresIn,
@JsonKey(name: 'next_resend_in') int? nextResendIn,
});
}
/// @nodoc
class _$ResendDataDtoCopyWithImpl<$Res, $Val extends ResendDataDto>
implements $ResendDataDtoCopyWith<$Res> {
_$ResendDataDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ResendDataDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? otpToken = freezed,
Object? expiresIn = freezed,
Object? nextResendIn = freezed,
}) {
return _then(
_value.copyWith(
otpToken: freezed == otpToken
? _value.otpToken
: otpToken // ignore: cast_nullable_to_non_nullable
as String?,
expiresIn: freezed == expiresIn
? _value.expiresIn
: expiresIn // ignore: cast_nullable_to_non_nullable
as int?,
nextResendIn: freezed == nextResendIn
? _value.nextResendIn
: nextResendIn // ignore: cast_nullable_to_non_nullable
as int?,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$ResendDataDtoImplCopyWith<$Res>
implements $ResendDataDtoCopyWith<$Res> {
factory _$$ResendDataDtoImplCopyWith(
_$ResendDataDtoImpl value,
$Res Function(_$ResendDataDtoImpl) then,
) = __$$ResendDataDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
@JsonKey(name: 'otp_token') String? otpToken,
@JsonKey(name: 'expires_in') int? expiresIn,
@JsonKey(name: 'next_resend_in') int? nextResendIn,
});
}
/// @nodoc
class __$$ResendDataDtoImplCopyWithImpl<$Res>
extends _$ResendDataDtoCopyWithImpl<$Res, _$ResendDataDtoImpl>
implements _$$ResendDataDtoImplCopyWith<$Res> {
__$$ResendDataDtoImplCopyWithImpl(
_$ResendDataDtoImpl _value,
$Res Function(_$ResendDataDtoImpl) _then,
) : super(_value, _then);
/// Create a copy of ResendDataDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? otpToken = freezed,
Object? expiresIn = freezed,
Object? nextResendIn = freezed,
}) {
return _then(
_$ResendDataDtoImpl(
otpToken: freezed == otpToken
? _value.otpToken
: otpToken // ignore: cast_nullable_to_non_nullable
as String?,
expiresIn: freezed == expiresIn
? _value.expiresIn
: expiresIn // ignore: cast_nullable_to_non_nullable
as int?,
nextResendIn: freezed == nextResendIn
? _value.nextResendIn
: nextResendIn // ignore: cast_nullable_to_non_nullable
as int?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$ResendDataDtoImpl implements _ResendDataDto {
const _$ResendDataDtoImpl({
@JsonKey(name: 'otp_token') this.otpToken,
@JsonKey(name: 'expires_in') this.expiresIn,
@JsonKey(name: 'next_resend_in') this.nextResendIn,
});
factory _$ResendDataDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$ResendDataDtoImplFromJson(json);
@override
@JsonKey(name: 'otp_token')
final String? otpToken;
@override
@JsonKey(name: 'expires_in')
final int? expiresIn;
@override
@JsonKey(name: 'next_resend_in')
final int? nextResendIn;
@override
String toString() {
return 'ResendDataDto(otpToken: $otpToken, expiresIn: $expiresIn, nextResendIn: $nextResendIn)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ResendDataDtoImpl &&
(identical(other.otpToken, otpToken) ||
other.otpToken == otpToken) &&
(identical(other.expiresIn, expiresIn) ||
other.expiresIn == expiresIn) &&
(identical(other.nextResendIn, nextResendIn) ||
other.nextResendIn == nextResendIn));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode =>
Object.hash(runtimeType, otpToken, expiresIn, nextResendIn);
/// Create a copy of ResendDataDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ResendDataDtoImplCopyWith<_$ResendDataDtoImpl> get copyWith =>
__$$ResendDataDtoImplCopyWithImpl<_$ResendDataDtoImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$ResendDataDtoImplToJson(this);
}
}
abstract class _ResendDataDto implements ResendDataDto {
const factory _ResendDataDto({
@JsonKey(name: 'otp_token') final String? otpToken,
@JsonKey(name: 'expires_in') final int? expiresIn,
@JsonKey(name: 'next_resend_in') final int? nextResendIn,
}) = _$ResendDataDtoImpl;
factory _ResendDataDto.fromJson(Map<String, dynamic> json) =
_$ResendDataDtoImpl.fromJson;
@override
@JsonKey(name: 'otp_token')
String? get otpToken;
@override
@JsonKey(name: 'expires_in')
int? get expiresIn;
@override
@JsonKey(name: 'next_resend_in')
int? get nextResendIn;
/// Create a copy of ResendDataDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ResendDataDtoImplCopyWith<_$ResendDataDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
+30
View File
@@ -133,3 +133,33 @@ Map<String, dynamic> _$$UserDtoImplToJson(_$UserDtoImpl instance) =>
'phone_number': instance.phoneNumber,
'birth_date': instance.birthDate,
};
_$ResendDtoImpl _$$ResendDtoImplFromJson(Map<String, dynamic> json) =>
_$ResendDtoImpl(
status: json['status'] as String?,
message: json['message'] as String?,
data: json['data'] == null
? null
: ResendDataDto.fromJson(json['data'] as Map<String, dynamic>),
);
Map<String, dynamic> _$$ResendDtoImplToJson(_$ResendDtoImpl instance) =>
<String, dynamic>{
'status': instance.status,
'message': instance.message,
'data': instance.data,
};
_$ResendDataDtoImpl _$$ResendDataDtoImplFromJson(Map<String, dynamic> json) =>
_$ResendDataDtoImpl(
otpToken: json['otp_token'] as String?,
expiresIn: (json['expires_in'] as num?)?.toInt(),
nextResendIn: (json['next_resend_in'] as num?)?.toInt(),
);
Map<String, dynamic> _$$ResendDataDtoImplToJson(_$ResendDataDtoImpl instance) =>
<String, dynamic>{
'otp_token': instance.otpToken,
'expires_in': instance.expiresIn,
'next_resend_in': instance.nextResendIn,
};
@@ -223,4 +223,28 @@ class AuthRemoteDataProvider {
return DC.error(AuthFailure.serverError(e));
}
}
Future<DC<AuthFailure, ResendDto>> resend({
required String phoneNumber,
required String purpose, //login or registration
}) async {
try {
final response = await _apiClient.post(
ApiPath.resend,
data: {'phone_number': phoneNumber, 'purpose': purpose},
);
if (response.data['success'] == false) {
return DC.error(
AuthFailure.dynamicErrorMessage('Terjadi kesalahan coba lagi nanti'),
);
}
final dto = ResendDto.fromJson(response.data['data']);
return DC.data(dto);
} on ApiFailure catch (e, s) {
log('resend', name: _logName, error: e, stackTrace: s);
return DC.error(AuthFailure.serverError(e));
}
}
}
@@ -0,0 +1,36 @@
part of '../auth_dtos.dart';
@freezed
class ResendDto with _$ResendDto {
const factory ResendDto({
@JsonKey(name: 'status') String? status,
@JsonKey(name: 'message') String? message,
@JsonKey(name: 'data') ResendDataDto? data,
}) = _ResendDto;
factory ResendDto.fromJson(Map<String, dynamic> json) =>
_$ResendDtoFromJson(json);
const ResendDto._();
/// mapping ke domain
Resend toDomain() => Resend(
status: status ?? '',
message: message ?? '',
otpToken: data?.otpToken ?? '',
expiresIn: data?.expiresIn ?? 0,
nextResendIn: data?.nextResendIn ?? 0,
);
}
@freezed
class ResendDataDto with _$ResendDataDto {
const factory ResendDataDto({
@JsonKey(name: 'otp_token') String? otpToken,
@JsonKey(name: 'expires_in') int? expiresIn,
@JsonKey(name: 'next_resend_in') int? nextResendIn,
}) = _ResendDataDto;
factory ResendDataDto.fromJson(Map<String, dynamic> json) =>
_$ResendDataDtoFromJson(json);
}
@@ -135,4 +135,28 @@ class AuthRepository implements IAuthRepository {
return left(const AuthFailure.unexpectedError());
}
}
@override
Future<Either<AuthFailure, Resend>> resend({
required String phoneNumber,
required String purpose,
}) async {
try {
final result = await _remoteDataProvider.resend(
phoneNumber: phoneNumber,
purpose: purpose,
);
if (result.hasError) {
return left(result.error!);
}
final auth = result.data!.toDomain();
return right(auth);
} catch (e, s) {
log('resendError', name: _logName, error: e, stackTrace: s);
return left(const AuthFailure.unexpectedError());
}
}
}