Set Password Repo

This commit is contained in:
efrilm
2025-09-18 06:57:08 +07:00
parent c40f96fc88
commit 1a0c0cf49b
16 changed files with 2453 additions and 0 deletions
+1
View File
@@ -8,3 +8,4 @@ part 'auth_dtos.g.dart';
part 'dto/check_phone_dto.dart';
part 'dto/register_dto.dart';
part 'dto/verify_dto.dart';
part 'dto/login_dto.dart';
@@ -1248,3 +1248,700 @@ abstract class _VerifyDataDto implements VerifyDataDto {
_$$VerifyDataDtoImplCopyWith<_$VerifyDataDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
LoginDto _$LoginDtoFromJson(Map<String, dynamic> json) {
return _LoginDto.fromJson(json);
}
/// @nodoc
mixin _$LoginDto {
@JsonKey(name: 'status')
String? get status => throw _privateConstructorUsedError;
@JsonKey(name: 'message')
String? get message => throw _privateConstructorUsedError;
@JsonKey(name: 'data')
LoginDataDto? get data => throw _privateConstructorUsedError;
/// Serializes this LoginDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of LoginDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$LoginDtoCopyWith<LoginDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $LoginDtoCopyWith<$Res> {
factory $LoginDtoCopyWith(LoginDto value, $Res Function(LoginDto) then) =
_$LoginDtoCopyWithImpl<$Res, LoginDto>;
@useResult
$Res call({
@JsonKey(name: 'status') String? status,
@JsonKey(name: 'message') String? message,
@JsonKey(name: 'data') LoginDataDto? data,
});
$LoginDataDtoCopyWith<$Res>? get data;
}
/// @nodoc
class _$LoginDtoCopyWithImpl<$Res, $Val extends LoginDto>
implements $LoginDtoCopyWith<$Res> {
_$LoginDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of LoginDto
/// 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 LoginDataDto?,
)
as $Val,
);
}
/// Create a copy of LoginDto
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$LoginDataDtoCopyWith<$Res>? get data {
if (_value.data == null) {
return null;
}
return $LoginDataDtoCopyWith<$Res>(_value.data!, (value) {
return _then(_value.copyWith(data: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$LoginDtoImplCopyWith<$Res>
implements $LoginDtoCopyWith<$Res> {
factory _$$LoginDtoImplCopyWith(
_$LoginDtoImpl value,
$Res Function(_$LoginDtoImpl) then,
) = __$$LoginDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
@JsonKey(name: 'status') String? status,
@JsonKey(name: 'message') String? message,
@JsonKey(name: 'data') LoginDataDto? data,
});
@override
$LoginDataDtoCopyWith<$Res>? get data;
}
/// @nodoc
class __$$LoginDtoImplCopyWithImpl<$Res>
extends _$LoginDtoCopyWithImpl<$Res, _$LoginDtoImpl>
implements _$$LoginDtoImplCopyWith<$Res> {
__$$LoginDtoImplCopyWithImpl(
_$LoginDtoImpl _value,
$Res Function(_$LoginDtoImpl) _then,
) : super(_value, _then);
/// Create a copy of LoginDto
/// 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(
_$LoginDtoImpl(
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 LoginDataDto?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$LoginDtoImpl extends _LoginDto {
const _$LoginDtoImpl({
@JsonKey(name: 'status') this.status,
@JsonKey(name: 'message') this.message,
@JsonKey(name: 'data') this.data,
}) : super._();
factory _$LoginDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$LoginDtoImplFromJson(json);
@override
@JsonKey(name: 'status')
final String? status;
@override
@JsonKey(name: 'message')
final String? message;
@override
@JsonKey(name: 'data')
final LoginDataDto? data;
@override
String toString() {
return 'LoginDto(status: $status, message: $message, data: $data)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$LoginDtoImpl &&
(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 LoginDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$LoginDtoImplCopyWith<_$LoginDtoImpl> get copyWith =>
__$$LoginDtoImplCopyWithImpl<_$LoginDtoImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$LoginDtoImplToJson(this);
}
}
abstract class _LoginDto extends LoginDto {
const factory _LoginDto({
@JsonKey(name: 'status') final String? status,
@JsonKey(name: 'message') final String? message,
@JsonKey(name: 'data') final LoginDataDto? data,
}) = _$LoginDtoImpl;
const _LoginDto._() : super._();
factory _LoginDto.fromJson(Map<String, dynamic> json) =
_$LoginDtoImpl.fromJson;
@override
@JsonKey(name: 'status')
String? get status;
@override
@JsonKey(name: 'message')
String? get message;
@override
@JsonKey(name: 'data')
LoginDataDto? get data;
/// Create a copy of LoginDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$LoginDtoImplCopyWith<_$LoginDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
LoginDataDto _$LoginDataDtoFromJson(Map<String, dynamic> json) {
return _LoginDataDto.fromJson(json);
}
/// @nodoc
mixin _$LoginDataDto {
@JsonKey(name: 'access_token')
String? get accessToken => throw _privateConstructorUsedError;
@JsonKey(name: 'refresh_token')
String? get refreshToken => throw _privateConstructorUsedError;
@JsonKey(name: 'user')
UserDto? get user => throw _privateConstructorUsedError;
/// Serializes this LoginDataDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of LoginDataDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$LoginDataDtoCopyWith<LoginDataDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $LoginDataDtoCopyWith<$Res> {
factory $LoginDataDtoCopyWith(
LoginDataDto value,
$Res Function(LoginDataDto) then,
) = _$LoginDataDtoCopyWithImpl<$Res, LoginDataDto>;
@useResult
$Res call({
@JsonKey(name: 'access_token') String? accessToken,
@JsonKey(name: 'refresh_token') String? refreshToken,
@JsonKey(name: 'user') UserDto? user,
});
$UserDtoCopyWith<$Res>? get user;
}
/// @nodoc
class _$LoginDataDtoCopyWithImpl<$Res, $Val extends LoginDataDto>
implements $LoginDataDtoCopyWith<$Res> {
_$LoginDataDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of LoginDataDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? accessToken = freezed,
Object? refreshToken = freezed,
Object? user = freezed,
}) {
return _then(
_value.copyWith(
accessToken: freezed == accessToken
? _value.accessToken
: accessToken // ignore: cast_nullable_to_non_nullable
as String?,
refreshToken: freezed == refreshToken
? _value.refreshToken
: refreshToken // ignore: cast_nullable_to_non_nullable
as String?,
user: freezed == user
? _value.user
: user // ignore: cast_nullable_to_non_nullable
as UserDto?,
)
as $Val,
);
}
/// Create a copy of LoginDataDto
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$UserDtoCopyWith<$Res>? get user {
if (_value.user == null) {
return null;
}
return $UserDtoCopyWith<$Res>(_value.user!, (value) {
return _then(_value.copyWith(user: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$LoginDataDtoImplCopyWith<$Res>
implements $LoginDataDtoCopyWith<$Res> {
factory _$$LoginDataDtoImplCopyWith(
_$LoginDataDtoImpl value,
$Res Function(_$LoginDataDtoImpl) then,
) = __$$LoginDataDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
@JsonKey(name: 'access_token') String? accessToken,
@JsonKey(name: 'refresh_token') String? refreshToken,
@JsonKey(name: 'user') UserDto? user,
});
@override
$UserDtoCopyWith<$Res>? get user;
}
/// @nodoc
class __$$LoginDataDtoImplCopyWithImpl<$Res>
extends _$LoginDataDtoCopyWithImpl<$Res, _$LoginDataDtoImpl>
implements _$$LoginDataDtoImplCopyWith<$Res> {
__$$LoginDataDtoImplCopyWithImpl(
_$LoginDataDtoImpl _value,
$Res Function(_$LoginDataDtoImpl) _then,
) : super(_value, _then);
/// Create a copy of LoginDataDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? accessToken = freezed,
Object? refreshToken = freezed,
Object? user = freezed,
}) {
return _then(
_$LoginDataDtoImpl(
accessToken: freezed == accessToken
? _value.accessToken
: accessToken // ignore: cast_nullable_to_non_nullable
as String?,
refreshToken: freezed == refreshToken
? _value.refreshToken
: refreshToken // ignore: cast_nullable_to_non_nullable
as String?,
user: freezed == user
? _value.user
: user // ignore: cast_nullable_to_non_nullable
as UserDto?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$LoginDataDtoImpl implements _LoginDataDto {
const _$LoginDataDtoImpl({
@JsonKey(name: 'access_token') this.accessToken,
@JsonKey(name: 'refresh_token') this.refreshToken,
@JsonKey(name: 'user') this.user,
});
factory _$LoginDataDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$LoginDataDtoImplFromJson(json);
@override
@JsonKey(name: 'access_token')
final String? accessToken;
@override
@JsonKey(name: 'refresh_token')
final String? refreshToken;
@override
@JsonKey(name: 'user')
final UserDto? user;
@override
String toString() {
return 'LoginDataDto(accessToken: $accessToken, refreshToken: $refreshToken, user: $user)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$LoginDataDtoImpl &&
(identical(other.accessToken, accessToken) ||
other.accessToken == accessToken) &&
(identical(other.refreshToken, refreshToken) ||
other.refreshToken == refreshToken) &&
(identical(other.user, user) || other.user == user));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType, accessToken, refreshToken, user);
/// Create a copy of LoginDataDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$LoginDataDtoImplCopyWith<_$LoginDataDtoImpl> get copyWith =>
__$$LoginDataDtoImplCopyWithImpl<_$LoginDataDtoImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$LoginDataDtoImplToJson(this);
}
}
abstract class _LoginDataDto implements LoginDataDto {
const factory _LoginDataDto({
@JsonKey(name: 'access_token') final String? accessToken,
@JsonKey(name: 'refresh_token') final String? refreshToken,
@JsonKey(name: 'user') final UserDto? user,
}) = _$LoginDataDtoImpl;
factory _LoginDataDto.fromJson(Map<String, dynamic> json) =
_$LoginDataDtoImpl.fromJson;
@override
@JsonKey(name: 'access_token')
String? get accessToken;
@override
@JsonKey(name: 'refresh_token')
String? get refreshToken;
@override
@JsonKey(name: 'user')
UserDto? get user;
/// Create a copy of LoginDataDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$LoginDataDtoImplCopyWith<_$LoginDataDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
UserDto _$UserDtoFromJson(Map<String, dynamic> json) {
return _UserDto.fromJson(json);
}
/// @nodoc
mixin _$UserDto {
@JsonKey(name: 'id')
String? get id => throw _privateConstructorUsedError;
@JsonKey(name: 'name')
String? get name => throw _privateConstructorUsedError;
@JsonKey(name: 'phone_number')
String? get phoneNumber => throw _privateConstructorUsedError;
@JsonKey(name: 'birth_date')
String? get birthDate => throw _privateConstructorUsedError;
/// Serializes this UserDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of UserDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$UserDtoCopyWith<UserDto> get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $UserDtoCopyWith<$Res> {
factory $UserDtoCopyWith(UserDto value, $Res Function(UserDto) then) =
_$UserDtoCopyWithImpl<$Res, UserDto>;
@useResult
$Res call({
@JsonKey(name: 'id') String? id,
@JsonKey(name: 'name') String? name,
@JsonKey(name: 'phone_number') String? phoneNumber,
@JsonKey(name: 'birth_date') String? birthDate,
});
}
/// @nodoc
class _$UserDtoCopyWithImpl<$Res, $Val extends UserDto>
implements $UserDtoCopyWith<$Res> {
_$UserDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of UserDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = freezed,
Object? name = freezed,
Object? phoneNumber = freezed,
Object? birthDate = freezed,
}) {
return _then(
_value.copyWith(
id: freezed == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String?,
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
phoneNumber: freezed == phoneNumber
? _value.phoneNumber
: phoneNumber // ignore: cast_nullable_to_non_nullable
as String?,
birthDate: freezed == birthDate
? _value.birthDate
: birthDate // ignore: cast_nullable_to_non_nullable
as String?,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$UserDtoImplCopyWith<$Res> implements $UserDtoCopyWith<$Res> {
factory _$$UserDtoImplCopyWith(
_$UserDtoImpl value,
$Res Function(_$UserDtoImpl) then,
) = __$$UserDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
@JsonKey(name: 'id') String? id,
@JsonKey(name: 'name') String? name,
@JsonKey(name: 'phone_number') String? phoneNumber,
@JsonKey(name: 'birth_date') String? birthDate,
});
}
/// @nodoc
class __$$UserDtoImplCopyWithImpl<$Res>
extends _$UserDtoCopyWithImpl<$Res, _$UserDtoImpl>
implements _$$UserDtoImplCopyWith<$Res> {
__$$UserDtoImplCopyWithImpl(
_$UserDtoImpl _value,
$Res Function(_$UserDtoImpl) _then,
) : super(_value, _then);
/// Create a copy of UserDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = freezed,
Object? name = freezed,
Object? phoneNumber = freezed,
Object? birthDate = freezed,
}) {
return _then(
_$UserDtoImpl(
id: freezed == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String?,
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
phoneNumber: freezed == phoneNumber
? _value.phoneNumber
: phoneNumber // ignore: cast_nullable_to_non_nullable
as String?,
birthDate: freezed == birthDate
? _value.birthDate
: birthDate // ignore: cast_nullable_to_non_nullable
as String?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$UserDtoImpl extends _UserDto {
const _$UserDtoImpl({
@JsonKey(name: 'id') this.id,
@JsonKey(name: 'name') this.name,
@JsonKey(name: 'phone_number') this.phoneNumber,
@JsonKey(name: 'birth_date') this.birthDate,
}) : super._();
factory _$UserDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$UserDtoImplFromJson(json);
@override
@JsonKey(name: 'id')
final String? id;
@override
@JsonKey(name: 'name')
final String? name;
@override
@JsonKey(name: 'phone_number')
final String? phoneNumber;
@override
@JsonKey(name: 'birth_date')
final String? birthDate;
@override
String toString() {
return 'UserDto(id: $id, name: $name, phoneNumber: $phoneNumber, birthDate: $birthDate)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$UserDtoImpl &&
(identical(other.id, id) || other.id == id) &&
(identical(other.name, name) || other.name == name) &&
(identical(other.phoneNumber, phoneNumber) ||
other.phoneNumber == phoneNumber) &&
(identical(other.birthDate, birthDate) ||
other.birthDate == birthDate));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode =>
Object.hash(runtimeType, id, name, phoneNumber, birthDate);
/// Create a copy of UserDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$UserDtoImplCopyWith<_$UserDtoImpl> get copyWith =>
__$$UserDtoImplCopyWithImpl<_$UserDtoImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$UserDtoImplToJson(this);
}
}
abstract class _UserDto extends UserDto {
const factory _UserDto({
@JsonKey(name: 'id') final String? id,
@JsonKey(name: 'name') final String? name,
@JsonKey(name: 'phone_number') final String? phoneNumber,
@JsonKey(name: 'birth_date') final String? birthDate,
}) = _$UserDtoImpl;
const _UserDto._() : super._();
factory _UserDto.fromJson(Map<String, dynamic> json) = _$UserDtoImpl.fromJson;
@override
@JsonKey(name: 'id')
String? get id;
@override
@JsonKey(name: 'name')
String? get name;
@override
@JsonKey(name: 'phone_number')
String? get phoneNumber;
@override
@JsonKey(name: 'birth_date')
String? get birthDate;
/// Create a copy of UserDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$UserDtoImplCopyWith<_$UserDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
+48
View File
@@ -85,3 +85,51 @@ _$VerifyDataDtoImpl _$$VerifyDataDtoImplFromJson(Map<String, dynamic> json) =>
Map<String, dynamic> _$$VerifyDataDtoImplToJson(_$VerifyDataDtoImpl instance) =>
<String, dynamic>{'registration_token': instance.registrationToken};
_$LoginDtoImpl _$$LoginDtoImplFromJson(Map<String, dynamic> json) =>
_$LoginDtoImpl(
status: json['status'] as String?,
message: json['message'] as String?,
data: json['data'] == null
? null
: LoginDataDto.fromJson(json['data'] as Map<String, dynamic>),
);
Map<String, dynamic> _$$LoginDtoImplToJson(_$LoginDtoImpl instance) =>
<String, dynamic>{
'status': instance.status,
'message': instance.message,
'data': instance.data,
};
_$LoginDataDtoImpl _$$LoginDataDtoImplFromJson(Map<String, dynamic> json) =>
_$LoginDataDtoImpl(
accessToken: json['access_token'] as String?,
refreshToken: json['refresh_token'] as String?,
user: json['user'] == null
? null
: UserDto.fromJson(json['user'] as Map<String, dynamic>),
);
Map<String, dynamic> _$$LoginDataDtoImplToJson(_$LoginDataDtoImpl instance) =>
<String, dynamic>{
'access_token': instance.accessToken,
'refresh_token': instance.refreshToken,
'user': instance.user,
};
_$UserDtoImpl _$$UserDtoImplFromJson(Map<String, dynamic> json) =>
_$UserDtoImpl(
id: json['id'] as String?,
name: json['name'] as String?,
phoneNumber: json['phone_number'] as String?,
birthDate: json['birth_date'] as String?,
);
Map<String, dynamic> _$$UserDtoImplToJson(_$UserDtoImpl instance) =>
<String, dynamic>{
'id': instance.id,
'name': instance.name,
'phone_number': instance.phoneNumber,
'birth_date': instance.birthDate,
};
@@ -136,4 +136,51 @@ class AuthRemoteDataProvider {
return DC.error(AuthFailure.serverError(e));
}
}
Future<DC<AuthFailure, LoginDto>> setPassword({
required String registrationToken,
required String password,
required String confirmPassword,
}) async {
try {
final response = await _apiClient.post(
ApiPath.setPassword,
data: {
'registration_token': registrationToken,
'password': password,
'confirm_password': confirmPassword,
},
);
if (response.data['success'] == false) {
if ((response.data['errors'] as List).isNotEmpty) {
if (response.data['errors'][0]['code'] == "900") {
return DC.error(
AuthFailure.dynamicErrorMessage(
'Invalid Registration, Lakukan kembali dari awal',
),
);
} else {
return DC.error(
AuthFailure.dynamicErrorMessage(
'Terjadi kesalahan coba lagi nanti',
),
);
}
} else {
return DC.error(
AuthFailure.dynamicErrorMessage(
'Terjadi kesalahan coba lagi nanti',
),
);
}
}
final dto = LoginDto.fromJson(response.data['data']);
return DC.data(dto);
} on ApiFailure catch (e, s) {
log('setPassword', name: _logName, error: e, stackTrace: s);
return DC.error(AuthFailure.serverError(e));
}
}
}
@@ -0,0 +1,58 @@
part of '../auth_dtos.dart';
@freezed
class LoginDto with _$LoginDto {
const factory LoginDto({
@JsonKey(name: 'status') String? status,
@JsonKey(name: 'message') String? message,
@JsonKey(name: 'data') LoginDataDto? data,
}) = _LoginDto;
factory LoginDto.fromJson(Map<String, dynamic> json) =>
_$LoginDtoFromJson(json);
const LoginDto._();
/// mapping ke domain
Login toDomain() => Login(
status: status ?? '',
message: message ?? '',
accessToken: data?.accessToken ?? '',
refreshToken: data?.refreshToken ?? '',
user: data?.user?.toDomain() ?? User.empty(),
);
}
@freezed
class LoginDataDto with _$LoginDataDto {
const factory LoginDataDto({
@JsonKey(name: 'access_token') String? accessToken,
@JsonKey(name: 'refresh_token') String? refreshToken,
@JsonKey(name: 'user') UserDto? user,
}) = _LoginDataDto;
factory LoginDataDto.fromJson(Map<String, dynamic> json) =>
_$LoginDataDtoFromJson(json);
}
@freezed
class UserDto with _$UserDto {
const factory UserDto({
@JsonKey(name: 'id') String? id,
@JsonKey(name: 'name') String? name,
@JsonKey(name: 'phone_number') String? phoneNumber,
@JsonKey(name: 'birth_date') String? birthDate,
}) = _UserDto;
factory UserDto.fromJson(Map<String, dynamic> json) =>
_$UserDtoFromJson(json);
const UserDto._();
User toDomain() => User(
id: id ?? '',
name: name ?? '',
phoneNumber: phoneNumber ?? '',
birthDate: birthDate ?? '',
);
}
@@ -85,4 +85,30 @@ class AuthRepository implements IAuthRepository {
return left(const AuthFailure.unexpectedError());
}
}
@override
Future<Either<AuthFailure, Login>> setPassword({
required String registrationToken,
required String password,
required String confirmPassword,
}) async {
try {
final result = await _remoteDataProvider.setPassword(
registrationToken: registrationToken,
password: password,
confirmPassword: confirmPassword,
);
if (result.hasError) {
return left(result.error!);
}
final auth = result.data!.toDomain();
return right(auth);
} catch (e, s) {
log('setPasswordError', name: _logName, error: e, stackTrace: s);
return left(const AuthFailure.unexpectedError());
}
}
}