check phone repo
This commit is contained in:
parent
c072e4c168
commit
c3263edb89
@ -1 +1,14 @@
|
||||
// TODO: define your code
|
||||
import '../../domain/auth/auth.dart';
|
||||
|
||||
extension StringExt on String {
|
||||
CheckPhoneStatus toCheckPhoneStatus() {
|
||||
switch (this) {
|
||||
case 'NO_REGISTERED':
|
||||
return CheckPhoneStatus.notRegistered;
|
||||
case 'PASSWORD_REQUIRED':
|
||||
return CheckPhoneStatus.passwordRequired;
|
||||
default:
|
||||
return CheckPhoneStatus.unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3
lib/common/url/api_path.dart
Normal file
3
lib/common/url/api_path.dart
Normal file
@ -0,0 +1,3 @@
|
||||
class ApiPath {
|
||||
static String checkPhone = '/api/v1/customer-auth/check-phone';
|
||||
}
|
||||
23
lib/domain/auth/auth.dart
Normal file
23
lib/domain/auth/auth.dart
Normal file
@ -0,0 +1,23 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
|
||||
import '../../common/api/api_failure.dart';
|
||||
|
||||
part 'auth.freezed.dart';
|
||||
|
||||
part 'entities/check_phone_entity.dart';
|
||||
part 'failures/auth_failure.dart';
|
||||
part 'repositories/i_auth_repository.dart';
|
||||
|
||||
enum CheckPhoneStatus { notRegistered, passwordRequired, unknown }
|
||||
|
||||
extension CheckPhoneStatusX on CheckPhoneStatus {
|
||||
String toStringType() => switch (this) {
|
||||
CheckPhoneStatus.notRegistered => 'NOT_REGISTERED',
|
||||
CheckPhoneStatus.passwordRequired => 'PASSWORD_REQUIRED',
|
||||
CheckPhoneStatus.unknown => '',
|
||||
};
|
||||
|
||||
bool get isNotRegistered => this == CheckPhoneStatus.notRegistered;
|
||||
bool get isPasswordRequired => this == CheckPhoneStatus.passwordRequired;
|
||||
}
|
||||
683
lib/domain/auth/auth.freezed.dart
Normal file
683
lib/domain/auth/auth.freezed.dart
Normal file
@ -0,0 +1,683 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'auth.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
|
||||
);
|
||||
|
||||
/// @nodoc
|
||||
mixin _$CheckPhone {
|
||||
String get status => throw _privateConstructorUsedError;
|
||||
String get message => throw _privateConstructorUsedError;
|
||||
String get phoneNumber => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of CheckPhone
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$CheckPhoneCopyWith<CheckPhone> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $CheckPhoneCopyWith<$Res> {
|
||||
factory $CheckPhoneCopyWith(
|
||||
CheckPhone value,
|
||||
$Res Function(CheckPhone) then,
|
||||
) = _$CheckPhoneCopyWithImpl<$Res, CheckPhone>;
|
||||
@useResult
|
||||
$Res call({String status, String message, String phoneNumber});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$CheckPhoneCopyWithImpl<$Res, $Val extends CheckPhone>
|
||||
implements $CheckPhoneCopyWith<$Res> {
|
||||
_$CheckPhoneCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of CheckPhone
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? status = null,
|
||||
Object? message = null,
|
||||
Object? phoneNumber = null,
|
||||
}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
status: null == status
|
||||
? _value.status
|
||||
: status // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
message: null == message
|
||||
? _value.message
|
||||
: message // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
phoneNumber: null == phoneNumber
|
||||
? _value.phoneNumber
|
||||
: phoneNumber // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$CheckPhoneImplCopyWith<$Res>
|
||||
implements $CheckPhoneCopyWith<$Res> {
|
||||
factory _$$CheckPhoneImplCopyWith(
|
||||
_$CheckPhoneImpl value,
|
||||
$Res Function(_$CheckPhoneImpl) then,
|
||||
) = __$$CheckPhoneImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({String status, String message, String phoneNumber});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$CheckPhoneImplCopyWithImpl<$Res>
|
||||
extends _$CheckPhoneCopyWithImpl<$Res, _$CheckPhoneImpl>
|
||||
implements _$$CheckPhoneImplCopyWith<$Res> {
|
||||
__$$CheckPhoneImplCopyWithImpl(
|
||||
_$CheckPhoneImpl _value,
|
||||
$Res Function(_$CheckPhoneImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of CheckPhone
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? status = null,
|
||||
Object? message = null,
|
||||
Object? phoneNumber = null,
|
||||
}) {
|
||||
return _then(
|
||||
_$CheckPhoneImpl(
|
||||
status: null == status
|
||||
? _value.status
|
||||
: status // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
message: null == message
|
||||
? _value.message
|
||||
: message // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
phoneNumber: null == phoneNumber
|
||||
? _value.phoneNumber
|
||||
: phoneNumber // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$CheckPhoneImpl implements _CheckPhone {
|
||||
const _$CheckPhoneImpl({
|
||||
required this.status,
|
||||
required this.message,
|
||||
required this.phoneNumber,
|
||||
});
|
||||
|
||||
@override
|
||||
final String status;
|
||||
@override
|
||||
final String message;
|
||||
@override
|
||||
final String phoneNumber;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'CheckPhone(status: $status, message: $message, phoneNumber: $phoneNumber)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$CheckPhoneImpl &&
|
||||
(identical(other.status, status) || other.status == status) &&
|
||||
(identical(other.message, message) || other.message == message) &&
|
||||
(identical(other.phoneNumber, phoneNumber) ||
|
||||
other.phoneNumber == phoneNumber));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, status, message, phoneNumber);
|
||||
|
||||
/// Create a copy of CheckPhone
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$CheckPhoneImplCopyWith<_$CheckPhoneImpl> get copyWith =>
|
||||
__$$CheckPhoneImplCopyWithImpl<_$CheckPhoneImpl>(this, _$identity);
|
||||
}
|
||||
|
||||
abstract class _CheckPhone implements CheckPhone {
|
||||
const factory _CheckPhone({
|
||||
required final String status,
|
||||
required final String message,
|
||||
required final String phoneNumber,
|
||||
}) = _$CheckPhoneImpl;
|
||||
|
||||
@override
|
||||
String get status;
|
||||
@override
|
||||
String get message;
|
||||
@override
|
||||
String get phoneNumber;
|
||||
|
||||
/// Create a copy of CheckPhone
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$CheckPhoneImplCopyWith<_$CheckPhoneImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$AuthFailure {
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function(ApiFailure failure) serverError,
|
||||
required TResult Function() unexpectedError,
|
||||
required TResult Function(String erroMessage) dynamicErrorMessage,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function(ApiFailure failure)? serverError,
|
||||
TResult? Function()? unexpectedError,
|
||||
TResult? Function(String erroMessage)? dynamicErrorMessage,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function(ApiFailure failure)? serverError,
|
||||
TResult Function()? unexpectedError,
|
||||
TResult Function(String erroMessage)? dynamicErrorMessage,
|
||||
required TResult orElse(),
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(_ServerError value) serverError,
|
||||
required TResult Function(_UnexpectedError value) unexpectedError,
|
||||
required TResult Function(_DynamicErrorMessage value) dynamicErrorMessage,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(_ServerError value)? serverError,
|
||||
TResult? Function(_UnexpectedError value)? unexpectedError,
|
||||
TResult? Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(_ServerError value)? serverError,
|
||||
TResult Function(_UnexpectedError value)? unexpectedError,
|
||||
TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||
required TResult orElse(),
|
||||
}) => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $AuthFailureCopyWith<$Res> {
|
||||
factory $AuthFailureCopyWith(
|
||||
AuthFailure value,
|
||||
$Res Function(AuthFailure) then,
|
||||
) = _$AuthFailureCopyWithImpl<$Res, AuthFailure>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$AuthFailureCopyWithImpl<$Res, $Val extends AuthFailure>
|
||||
implements $AuthFailureCopyWith<$Res> {
|
||||
_$AuthFailureCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of AuthFailure
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$ServerErrorImplCopyWith<$Res> {
|
||||
factory _$$ServerErrorImplCopyWith(
|
||||
_$ServerErrorImpl value,
|
||||
$Res Function(_$ServerErrorImpl) then,
|
||||
) = __$$ServerErrorImplCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call({ApiFailure failure});
|
||||
|
||||
$ApiFailureCopyWith<$Res> get failure;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$ServerErrorImplCopyWithImpl<$Res>
|
||||
extends _$AuthFailureCopyWithImpl<$Res, _$ServerErrorImpl>
|
||||
implements _$$ServerErrorImplCopyWith<$Res> {
|
||||
__$$ServerErrorImplCopyWithImpl(
|
||||
_$ServerErrorImpl _value,
|
||||
$Res Function(_$ServerErrorImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of AuthFailure
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? failure = null}) {
|
||||
return _then(
|
||||
_$ServerErrorImpl(
|
||||
null == failure
|
||||
? _value.failure
|
||||
: failure // ignore: cast_nullable_to_non_nullable
|
||||
as ApiFailure,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Create a copy of AuthFailure
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$ApiFailureCopyWith<$Res> get failure {
|
||||
return $ApiFailureCopyWith<$Res>(_value.failure, (value) {
|
||||
return _then(_value.copyWith(failure: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$ServerErrorImpl implements _ServerError {
|
||||
const _$ServerErrorImpl(this.failure);
|
||||
|
||||
@override
|
||||
final ApiFailure failure;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AuthFailure.serverError(failure: $failure)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$ServerErrorImpl &&
|
||||
(identical(other.failure, failure) || other.failure == failure));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, failure);
|
||||
|
||||
/// Create a copy of AuthFailure
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$ServerErrorImplCopyWith<_$ServerErrorImpl> get copyWith =>
|
||||
__$$ServerErrorImplCopyWithImpl<_$ServerErrorImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function(ApiFailure failure) serverError,
|
||||
required TResult Function() unexpectedError,
|
||||
required TResult Function(String erroMessage) dynamicErrorMessage,
|
||||
}) {
|
||||
return serverError(failure);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function(ApiFailure failure)? serverError,
|
||||
TResult? Function()? unexpectedError,
|
||||
TResult? Function(String erroMessage)? dynamicErrorMessage,
|
||||
}) {
|
||||
return serverError?.call(failure);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function(ApiFailure failure)? serverError,
|
||||
TResult Function()? unexpectedError,
|
||||
TResult Function(String erroMessage)? dynamicErrorMessage,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (serverError != null) {
|
||||
return serverError(failure);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(_ServerError value) serverError,
|
||||
required TResult Function(_UnexpectedError value) unexpectedError,
|
||||
required TResult Function(_DynamicErrorMessage value) dynamicErrorMessage,
|
||||
}) {
|
||||
return serverError(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(_ServerError value)? serverError,
|
||||
TResult? Function(_UnexpectedError value)? unexpectedError,
|
||||
TResult? Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||
}) {
|
||||
return serverError?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(_ServerError value)? serverError,
|
||||
TResult Function(_UnexpectedError value)? unexpectedError,
|
||||
TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (serverError != null) {
|
||||
return serverError(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _ServerError implements AuthFailure {
|
||||
const factory _ServerError(final ApiFailure failure) = _$ServerErrorImpl;
|
||||
|
||||
ApiFailure get failure;
|
||||
|
||||
/// Create a copy of AuthFailure
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$ServerErrorImplCopyWith<_$ServerErrorImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$UnexpectedErrorImplCopyWith<$Res> {
|
||||
factory _$$UnexpectedErrorImplCopyWith(
|
||||
_$UnexpectedErrorImpl value,
|
||||
$Res Function(_$UnexpectedErrorImpl) then,
|
||||
) = __$$UnexpectedErrorImplCopyWithImpl<$Res>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$UnexpectedErrorImplCopyWithImpl<$Res>
|
||||
extends _$AuthFailureCopyWithImpl<$Res, _$UnexpectedErrorImpl>
|
||||
implements _$$UnexpectedErrorImplCopyWith<$Res> {
|
||||
__$$UnexpectedErrorImplCopyWithImpl(
|
||||
_$UnexpectedErrorImpl _value,
|
||||
$Res Function(_$UnexpectedErrorImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of AuthFailure
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$UnexpectedErrorImpl implements _UnexpectedError {
|
||||
const _$UnexpectedErrorImpl();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AuthFailure.unexpectedError()';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType && other is _$UnexpectedErrorImpl);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function(ApiFailure failure) serverError,
|
||||
required TResult Function() unexpectedError,
|
||||
required TResult Function(String erroMessage) dynamicErrorMessage,
|
||||
}) {
|
||||
return unexpectedError();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function(ApiFailure failure)? serverError,
|
||||
TResult? Function()? unexpectedError,
|
||||
TResult? Function(String erroMessage)? dynamicErrorMessage,
|
||||
}) {
|
||||
return unexpectedError?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function(ApiFailure failure)? serverError,
|
||||
TResult Function()? unexpectedError,
|
||||
TResult Function(String erroMessage)? dynamicErrorMessage,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (unexpectedError != null) {
|
||||
return unexpectedError();
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(_ServerError value) serverError,
|
||||
required TResult Function(_UnexpectedError value) unexpectedError,
|
||||
required TResult Function(_DynamicErrorMessage value) dynamicErrorMessage,
|
||||
}) {
|
||||
return unexpectedError(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(_ServerError value)? serverError,
|
||||
TResult? Function(_UnexpectedError value)? unexpectedError,
|
||||
TResult? Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||
}) {
|
||||
return unexpectedError?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(_ServerError value)? serverError,
|
||||
TResult Function(_UnexpectedError value)? unexpectedError,
|
||||
TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (unexpectedError != null) {
|
||||
return unexpectedError(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _UnexpectedError implements AuthFailure {
|
||||
const factory _UnexpectedError() = _$UnexpectedErrorImpl;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$DynamicErrorMessageImplCopyWith<$Res> {
|
||||
factory _$$DynamicErrorMessageImplCopyWith(
|
||||
_$DynamicErrorMessageImpl value,
|
||||
$Res Function(_$DynamicErrorMessageImpl) then,
|
||||
) = __$$DynamicErrorMessageImplCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call({String erroMessage});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$DynamicErrorMessageImplCopyWithImpl<$Res>
|
||||
extends _$AuthFailureCopyWithImpl<$Res, _$DynamicErrorMessageImpl>
|
||||
implements _$$DynamicErrorMessageImplCopyWith<$Res> {
|
||||
__$$DynamicErrorMessageImplCopyWithImpl(
|
||||
_$DynamicErrorMessageImpl _value,
|
||||
$Res Function(_$DynamicErrorMessageImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of AuthFailure
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? erroMessage = null}) {
|
||||
return _then(
|
||||
_$DynamicErrorMessageImpl(
|
||||
null == erroMessage
|
||||
? _value.erroMessage
|
||||
: erroMessage // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$DynamicErrorMessageImpl implements _DynamicErrorMessage {
|
||||
const _$DynamicErrorMessageImpl(this.erroMessage);
|
||||
|
||||
@override
|
||||
final String erroMessage;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AuthFailure.dynamicErrorMessage(erroMessage: $erroMessage)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$DynamicErrorMessageImpl &&
|
||||
(identical(other.erroMessage, erroMessage) ||
|
||||
other.erroMessage == erroMessage));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, erroMessage);
|
||||
|
||||
/// Create a copy of AuthFailure
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$DynamicErrorMessageImplCopyWith<_$DynamicErrorMessageImpl> get copyWith =>
|
||||
__$$DynamicErrorMessageImplCopyWithImpl<_$DynamicErrorMessageImpl>(
|
||||
this,
|
||||
_$identity,
|
||||
);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function(ApiFailure failure) serverError,
|
||||
required TResult Function() unexpectedError,
|
||||
required TResult Function(String erroMessage) dynamicErrorMessage,
|
||||
}) {
|
||||
return dynamicErrorMessage(erroMessage);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function(ApiFailure failure)? serverError,
|
||||
TResult? Function()? unexpectedError,
|
||||
TResult? Function(String erroMessage)? dynamicErrorMessage,
|
||||
}) {
|
||||
return dynamicErrorMessage?.call(erroMessage);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function(ApiFailure failure)? serverError,
|
||||
TResult Function()? unexpectedError,
|
||||
TResult Function(String erroMessage)? dynamicErrorMessage,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (dynamicErrorMessage != null) {
|
||||
return dynamicErrorMessage(erroMessage);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(_ServerError value) serverError,
|
||||
required TResult Function(_UnexpectedError value) unexpectedError,
|
||||
required TResult Function(_DynamicErrorMessage value) dynamicErrorMessage,
|
||||
}) {
|
||||
return dynamicErrorMessage(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(_ServerError value)? serverError,
|
||||
TResult? Function(_UnexpectedError value)? unexpectedError,
|
||||
TResult? Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||
}) {
|
||||
return dynamicErrorMessage?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(_ServerError value)? serverError,
|
||||
TResult Function(_UnexpectedError value)? unexpectedError,
|
||||
TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (dynamicErrorMessage != null) {
|
||||
return dynamicErrorMessage(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _DynamicErrorMessage implements AuthFailure {
|
||||
const factory _DynamicErrorMessage(final String erroMessage) =
|
||||
_$DynamicErrorMessageImpl;
|
||||
|
||||
String get erroMessage;
|
||||
|
||||
/// Create a copy of AuthFailure
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$DynamicErrorMessageImplCopyWith<_$DynamicErrorMessageImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
13
lib/domain/auth/entities/check_phone_entity.dart
Normal file
13
lib/domain/auth/entities/check_phone_entity.dart
Normal file
@ -0,0 +1,13 @@
|
||||
part of '../auth.dart';
|
||||
|
||||
@freezed
|
||||
class CheckPhone with _$CheckPhone {
|
||||
const factory CheckPhone({
|
||||
required String status,
|
||||
required String message,
|
||||
required String phoneNumber,
|
||||
}) = _CheckPhone;
|
||||
|
||||
factory CheckPhone.empty() =>
|
||||
const CheckPhone(status: '', message: '', phoneNumber: '');
|
||||
}
|
||||
9
lib/domain/auth/failures/auth_failure.dart
Normal file
9
lib/domain/auth/failures/auth_failure.dart
Normal file
@ -0,0 +1,9 @@
|
||||
part of '../auth.dart';
|
||||
|
||||
@freezed
|
||||
sealed class AuthFailure with _$AuthFailure {
|
||||
const factory AuthFailure.serverError(ApiFailure failure) = _ServerError;
|
||||
const factory AuthFailure.unexpectedError() = _UnexpectedError;
|
||||
const factory AuthFailure.dynamicErrorMessage(String erroMessage) =
|
||||
_DynamicErrorMessage;
|
||||
}
|
||||
7
lib/domain/auth/repositories/i_auth_repository.dart
Normal file
7
lib/domain/auth/repositories/i_auth_repository.dart
Normal file
@ -0,0 +1,7 @@
|
||||
part of '../auth.dart';
|
||||
|
||||
abstract class IAuthRepository {
|
||||
Future<Either<AuthFailure, CheckPhone>> checkPhone({
|
||||
required String phoneNumber,
|
||||
});
|
||||
}
|
||||
@ -9,12 +9,12 @@ abstract class Env {
|
||||
@dev
|
||||
class DevEnv implements Env {
|
||||
@override
|
||||
String get baseUrl => ''; // example value
|
||||
String get baseUrl => 'http://192.168.1.30:4000'; // example value
|
||||
}
|
||||
|
||||
@Injectable(as: Env)
|
||||
@prod
|
||||
class ProdEnv implements Env {
|
||||
@override
|
||||
String get baseUrl => '';
|
||||
String get baseUrl => 'https://enaklo-pos-be.altru.id';
|
||||
}
|
||||
|
||||
8
lib/infrastructure/auth/auth_dtos.dart
Normal file
8
lib/infrastructure/auth/auth_dtos.dart
Normal file
@ -0,0 +1,8 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import '../../domain/auth/auth.dart';
|
||||
|
||||
part 'auth_dtos.freezed.dart';
|
||||
part 'auth_dtos.g.dart';
|
||||
|
||||
part 'dto/check_phone_dto.dart';
|
||||
410
lib/infrastructure/auth/auth_dtos.freezed.dart
Normal file
410
lib/infrastructure/auth/auth_dtos.freezed.dart
Normal file
@ -0,0 +1,410 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'auth_dtos.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
|
||||
);
|
||||
|
||||
CheckPhoneDto _$CheckPhoneDtoFromJson(Map<String, dynamic> json) {
|
||||
return _CheckPhoneDto.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$CheckPhoneDto {
|
||||
@JsonKey(name: 'status')
|
||||
String? get status => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'message')
|
||||
String? get message => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'data')
|
||||
CheckPhoneDataDto? get data => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this CheckPhoneDto to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of CheckPhoneDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$CheckPhoneDtoCopyWith<CheckPhoneDto> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $CheckPhoneDtoCopyWith<$Res> {
|
||||
factory $CheckPhoneDtoCopyWith(
|
||||
CheckPhoneDto value,
|
||||
$Res Function(CheckPhoneDto) then,
|
||||
) = _$CheckPhoneDtoCopyWithImpl<$Res, CheckPhoneDto>;
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: 'status') String? status,
|
||||
@JsonKey(name: 'message') String? message,
|
||||
@JsonKey(name: 'data') CheckPhoneDataDto? data,
|
||||
});
|
||||
|
||||
$CheckPhoneDataDtoCopyWith<$Res>? get data;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$CheckPhoneDtoCopyWithImpl<$Res, $Val extends CheckPhoneDto>
|
||||
implements $CheckPhoneDtoCopyWith<$Res> {
|
||||
_$CheckPhoneDtoCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of CheckPhoneDto
|
||||
/// 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 CheckPhoneDataDto?,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
|
||||
/// Create a copy of CheckPhoneDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$CheckPhoneDataDtoCopyWith<$Res>? get data {
|
||||
if (_value.data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $CheckPhoneDataDtoCopyWith<$Res>(_value.data!, (value) {
|
||||
return _then(_value.copyWith(data: value) as $Val);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$CheckPhoneDtoImplCopyWith<$Res>
|
||||
implements $CheckPhoneDtoCopyWith<$Res> {
|
||||
factory _$$CheckPhoneDtoImplCopyWith(
|
||||
_$CheckPhoneDtoImpl value,
|
||||
$Res Function(_$CheckPhoneDtoImpl) then,
|
||||
) = __$$CheckPhoneDtoImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: 'status') String? status,
|
||||
@JsonKey(name: 'message') String? message,
|
||||
@JsonKey(name: 'data') CheckPhoneDataDto? data,
|
||||
});
|
||||
|
||||
@override
|
||||
$CheckPhoneDataDtoCopyWith<$Res>? get data;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$CheckPhoneDtoImplCopyWithImpl<$Res>
|
||||
extends _$CheckPhoneDtoCopyWithImpl<$Res, _$CheckPhoneDtoImpl>
|
||||
implements _$$CheckPhoneDtoImplCopyWith<$Res> {
|
||||
__$$CheckPhoneDtoImplCopyWithImpl(
|
||||
_$CheckPhoneDtoImpl _value,
|
||||
$Res Function(_$CheckPhoneDtoImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of CheckPhoneDto
|
||||
/// 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(
|
||||
_$CheckPhoneDtoImpl(
|
||||
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 CheckPhoneDataDto?,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$CheckPhoneDtoImpl extends _CheckPhoneDto {
|
||||
const _$CheckPhoneDtoImpl({
|
||||
@JsonKey(name: 'status') this.status,
|
||||
@JsonKey(name: 'message') this.message,
|
||||
@JsonKey(name: 'data') this.data,
|
||||
}) : super._();
|
||||
|
||||
factory _$CheckPhoneDtoImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$CheckPhoneDtoImplFromJson(json);
|
||||
|
||||
@override
|
||||
@JsonKey(name: 'status')
|
||||
final String? status;
|
||||
@override
|
||||
@JsonKey(name: 'message')
|
||||
final String? message;
|
||||
@override
|
||||
@JsonKey(name: 'data')
|
||||
final CheckPhoneDataDto? data;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'CheckPhoneDto(status: $status, message: $message, data: $data)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$CheckPhoneDtoImpl &&
|
||||
(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 CheckPhoneDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$CheckPhoneDtoImplCopyWith<_$CheckPhoneDtoImpl> get copyWith =>
|
||||
__$$CheckPhoneDtoImplCopyWithImpl<_$CheckPhoneDtoImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$CheckPhoneDtoImplToJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _CheckPhoneDto extends CheckPhoneDto {
|
||||
const factory _CheckPhoneDto({
|
||||
@JsonKey(name: 'status') final String? status,
|
||||
@JsonKey(name: 'message') final String? message,
|
||||
@JsonKey(name: 'data') final CheckPhoneDataDto? data,
|
||||
}) = _$CheckPhoneDtoImpl;
|
||||
const _CheckPhoneDto._() : super._();
|
||||
|
||||
factory _CheckPhoneDto.fromJson(Map<String, dynamic> json) =
|
||||
_$CheckPhoneDtoImpl.fromJson;
|
||||
|
||||
@override
|
||||
@JsonKey(name: 'status')
|
||||
String? get status;
|
||||
@override
|
||||
@JsonKey(name: 'message')
|
||||
String? get message;
|
||||
@override
|
||||
@JsonKey(name: 'data')
|
||||
CheckPhoneDataDto? get data;
|
||||
|
||||
/// Create a copy of CheckPhoneDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$CheckPhoneDtoImplCopyWith<_$CheckPhoneDtoImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
CheckPhoneDataDto _$CheckPhoneDataDtoFromJson(Map<String, dynamic> json) {
|
||||
return _CheckPhoneDataDto.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$CheckPhoneDataDto {
|
||||
@JsonKey(name: 'phone_number')
|
||||
String? get phoneNumber => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this CheckPhoneDataDto to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of CheckPhoneDataDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$CheckPhoneDataDtoCopyWith<CheckPhoneDataDto> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $CheckPhoneDataDtoCopyWith<$Res> {
|
||||
factory $CheckPhoneDataDtoCopyWith(
|
||||
CheckPhoneDataDto value,
|
||||
$Res Function(CheckPhoneDataDto) then,
|
||||
) = _$CheckPhoneDataDtoCopyWithImpl<$Res, CheckPhoneDataDto>;
|
||||
@useResult
|
||||
$Res call({@JsonKey(name: 'phone_number') String? phoneNumber});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$CheckPhoneDataDtoCopyWithImpl<$Res, $Val extends CheckPhoneDataDto>
|
||||
implements $CheckPhoneDataDtoCopyWith<$Res> {
|
||||
_$CheckPhoneDataDtoCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of CheckPhoneDataDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? phoneNumber = freezed}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
phoneNumber: freezed == phoneNumber
|
||||
? _value.phoneNumber
|
||||
: phoneNumber // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$CheckPhoneDataDtoImplCopyWith<$Res>
|
||||
implements $CheckPhoneDataDtoCopyWith<$Res> {
|
||||
factory _$$CheckPhoneDataDtoImplCopyWith(
|
||||
_$CheckPhoneDataDtoImpl value,
|
||||
$Res Function(_$CheckPhoneDataDtoImpl) then,
|
||||
) = __$$CheckPhoneDataDtoImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({@JsonKey(name: 'phone_number') String? phoneNumber});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$CheckPhoneDataDtoImplCopyWithImpl<$Res>
|
||||
extends _$CheckPhoneDataDtoCopyWithImpl<$Res, _$CheckPhoneDataDtoImpl>
|
||||
implements _$$CheckPhoneDataDtoImplCopyWith<$Res> {
|
||||
__$$CheckPhoneDataDtoImplCopyWithImpl(
|
||||
_$CheckPhoneDataDtoImpl _value,
|
||||
$Res Function(_$CheckPhoneDataDtoImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of CheckPhoneDataDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? phoneNumber = freezed}) {
|
||||
return _then(
|
||||
_$CheckPhoneDataDtoImpl(
|
||||
phoneNumber: freezed == phoneNumber
|
||||
? _value.phoneNumber
|
||||
: phoneNumber // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$CheckPhoneDataDtoImpl implements _CheckPhoneDataDto {
|
||||
const _$CheckPhoneDataDtoImpl({
|
||||
@JsonKey(name: 'phone_number') this.phoneNumber,
|
||||
});
|
||||
|
||||
factory _$CheckPhoneDataDtoImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$CheckPhoneDataDtoImplFromJson(json);
|
||||
|
||||
@override
|
||||
@JsonKey(name: 'phone_number')
|
||||
final String? phoneNumber;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'CheckPhoneDataDto(phoneNumber: $phoneNumber)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$CheckPhoneDataDtoImpl &&
|
||||
(identical(other.phoneNumber, phoneNumber) ||
|
||||
other.phoneNumber == phoneNumber));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, phoneNumber);
|
||||
|
||||
/// Create a copy of CheckPhoneDataDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$CheckPhoneDataDtoImplCopyWith<_$CheckPhoneDataDtoImpl> get copyWith =>
|
||||
__$$CheckPhoneDataDtoImplCopyWithImpl<_$CheckPhoneDataDtoImpl>(
|
||||
this,
|
||||
_$identity,
|
||||
);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$CheckPhoneDataDtoImplToJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _CheckPhoneDataDto implements CheckPhoneDataDto {
|
||||
const factory _CheckPhoneDataDto({
|
||||
@JsonKey(name: 'phone_number') final String? phoneNumber,
|
||||
}) = _$CheckPhoneDataDtoImpl;
|
||||
|
||||
factory _CheckPhoneDataDto.fromJson(Map<String, dynamic> json) =
|
||||
_$CheckPhoneDataDtoImpl.fromJson;
|
||||
|
||||
@override
|
||||
@JsonKey(name: 'phone_number')
|
||||
String? get phoneNumber;
|
||||
|
||||
/// Create a copy of CheckPhoneDataDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$CheckPhoneDataDtoImplCopyWith<_$CheckPhoneDataDtoImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
31
lib/infrastructure/auth/auth_dtos.g.dart
Normal file
31
lib/infrastructure/auth/auth_dtos.g.dart
Normal file
@ -0,0 +1,31 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'auth_dtos.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$CheckPhoneDtoImpl _$$CheckPhoneDtoImplFromJson(Map<String, dynamic> json) =>
|
||||
_$CheckPhoneDtoImpl(
|
||||
status: json['status'] as String?,
|
||||
message: json['message'] as String?,
|
||||
data: json['data'] == null
|
||||
? null
|
||||
: CheckPhoneDataDto.fromJson(json['data'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$CheckPhoneDtoImplToJson(_$CheckPhoneDtoImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'status': instance.status,
|
||||
'message': instance.message,
|
||||
'data': instance.data,
|
||||
};
|
||||
|
||||
_$CheckPhoneDataDtoImpl _$$CheckPhoneDataDtoImplFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _$CheckPhoneDataDtoImpl(phoneNumber: json['phone_number'] as String?);
|
||||
|
||||
Map<String, dynamic> _$$CheckPhoneDataDtoImplToJson(
|
||||
_$CheckPhoneDataDtoImpl instance,
|
||||
) => <String, dynamic>{'phone_number': instance.phoneNumber};
|
||||
@ -0,0 +1,53 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
30
lib/infrastructure/auth/dto/check_phone_dto.dart
Normal file
30
lib/infrastructure/auth/dto/check_phone_dto.dart
Normal file
@ -0,0 +1,30 @@
|
||||
part of '../auth_dtos.dart';
|
||||
|
||||
@freezed
|
||||
class CheckPhoneDto with _$CheckPhoneDto {
|
||||
const CheckPhoneDto._();
|
||||
|
||||
const factory CheckPhoneDto({
|
||||
@JsonKey(name: 'status') String? status,
|
||||
@JsonKey(name: 'message') String? message,
|
||||
@JsonKey(name: 'data') CheckPhoneDataDto? data,
|
||||
}) = _CheckPhoneDto;
|
||||
|
||||
factory CheckPhoneDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$CheckPhoneDtoFromJson(json);
|
||||
CheckPhone toDomain() => CheckPhone(
|
||||
status: status ?? '',
|
||||
message: message ?? '',
|
||||
phoneNumber: data?.phoneNumber ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class CheckPhoneDataDto with _$CheckPhoneDataDto {
|
||||
const factory CheckPhoneDataDto({
|
||||
@JsonKey(name: 'phone_number') String? phoneNumber,
|
||||
}) = _CheckPhoneDataDto;
|
||||
|
||||
factory CheckPhoneDataDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$CheckPhoneDataDtoFromJson(json);
|
||||
}
|
||||
38
lib/infrastructure/auth/repositories/auth_repository.dart
Normal file
38
lib/infrastructure/auth/repositories/auth_repository.dart
Normal file
@ -0,0 +1,38 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../domain/auth/auth.dart';
|
||||
import '../datasources/remote_data_provider.dart';
|
||||
|
||||
@Injectable(as: IAuthRepository)
|
||||
class AuthRepository implements IAuthRepository {
|
||||
final AuthRemoteDataProvider _remoteDataProvider;
|
||||
|
||||
final String _logName = 'AuthRepository';
|
||||
|
||||
AuthRepository(this._remoteDataProvider);
|
||||
|
||||
@override
|
||||
Future<Either<AuthFailure, CheckPhone>> checkPhone({
|
||||
required String phoneNumber,
|
||||
}) async {
|
||||
try {
|
||||
final result = await _remoteDataProvider.checkPhone(
|
||||
phoneNumber: phoneNumber,
|
||||
);
|
||||
|
||||
if (result.hasError) {
|
||||
return left(result.error!);
|
||||
}
|
||||
|
||||
final auth = result.data!.toDomain();
|
||||
|
||||
return right(auth);
|
||||
} catch (e, s) {
|
||||
log('checkPhoneError', name: _logName, error: e, stackTrace: s);
|
||||
return left(const AuthFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user