added api for forgot password

This commit is contained in:
llsajjad
2025-09-16 15:51:56 +03:30
parent 09ac79fd79
commit 69980925ad
13 changed files with 886 additions and 130 deletions
+1
View File
@@ -1,4 +1,5 @@
class AuthApi {
static const String login = '/api/v1/profile/login';
static const String logout = '/api/v1/profile/logout';
static const String forgotPassword = '/api/v1/profile/forgot-password';
}
+16
View File
@@ -5,6 +5,7 @@ import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tm_app/core/utils/logger.dart';
import 'package:tm_app/data/services/api/auth_api.dart';
import 'package:tm_app/data/services/model/forgot_password_response/forgot_password_response_model.dart';
import 'package:tm_app/data/services/model/login_response/login_response_model.dart';
import 'package:tm_app/data/services/model/logout_response/logout_response.dart';
@@ -56,4 +57,19 @@ class AuthService {
await prefs.remove('refresh_token');
appLogger.info('tokens cleared!');
}
Future<Result<ForgotPasswordResponseModel>> forgotPassword({
required String email,
}) async {
final data = jsonEncode({"email": email});
final result = await _networkManager.makeRequest(
AuthApi.forgotPassword,
method: 'POST',
(json) => ForgotPasswordResponseModel.fromJson(json),
data: data,
);
return result;
}
}
@@ -0,0 +1,32 @@
// ignore_for_file: invalid_annotation_target
import 'package:freezed_annotation/freezed_annotation.dart';
import '../error/error_model.dart';
part 'forgot_password_response_model.freezed.dart';
part 'forgot_password_response_model.g.dart';
@freezed
abstract class ForgotPasswordResponseModel with _$ForgotPasswordResponseModel {
const factory ForgotPasswordResponseModel({
required bool success,
required String? message,
required ForgotPasswordData? data,
required ErrorModel? error,
required Map<String, dynamic>? meta,
}) = _ForgotPasswordResponseModel;
factory ForgotPasswordResponseModel.fromJson(Map<String, Object?> json) =>
_$ForgotPasswordResponseModelFromJson(json);
}
@freezed
abstract class ForgotPasswordData with _$ForgotPasswordData {
const factory ForgotPasswordData({
required String? message,
required bool? success,
}) = _ForgotPasswordData;
factory ForgotPasswordData.fromJson(Map<String, Object?> json) =>
_$ForgotPasswordDataFromJson(json);
}
@@ -0,0 +1,611 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// 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 'forgot_password_response_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$ForgotPasswordResponseModel {
bool get success; String? get message; ForgotPasswordData? get data; ErrorModel? get error; Map<String, dynamic>? get meta;
/// Create a copy of ForgotPasswordResponseModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$ForgotPasswordResponseModelCopyWith<ForgotPasswordResponseModel> get copyWith => _$ForgotPasswordResponseModelCopyWithImpl<ForgotPasswordResponseModel>(this as ForgotPasswordResponseModel, _$identity);
/// Serializes this ForgotPasswordResponseModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is ForgotPasswordResponseModel&&(identical(other.success, success) || other.success == success)&&(identical(other.message, message) || other.message == message)&&(identical(other.data, data) || other.data == data)&&(identical(other.error, error) || other.error == error)&&const DeepCollectionEquality().equals(other.meta, meta));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,success,message,data,error,const DeepCollectionEquality().hash(meta));
@override
String toString() {
return 'ForgotPasswordResponseModel(success: $success, message: $message, data: $data, error: $error, meta: $meta)';
}
}
/// @nodoc
abstract mixin class $ForgotPasswordResponseModelCopyWith<$Res> {
factory $ForgotPasswordResponseModelCopyWith(ForgotPasswordResponseModel value, $Res Function(ForgotPasswordResponseModel) _then) = _$ForgotPasswordResponseModelCopyWithImpl;
@useResult
$Res call({
bool success, String? message, ForgotPasswordData? data, ErrorModel? error, Map<String, dynamic>? meta
});
$ForgotPasswordDataCopyWith<$Res>? get data;$ErrorModelCopyWith<$Res>? get error;
}
/// @nodoc
class _$ForgotPasswordResponseModelCopyWithImpl<$Res>
implements $ForgotPasswordResponseModelCopyWith<$Res> {
_$ForgotPasswordResponseModelCopyWithImpl(this._self, this._then);
final ForgotPasswordResponseModel _self;
final $Res Function(ForgotPasswordResponseModel) _then;
/// Create a copy of ForgotPasswordResponseModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? success = null,Object? message = freezed,Object? data = freezed,Object? error = freezed,Object? meta = freezed,}) {
return _then(_self.copyWith(
success: null == success ? _self.success : success // ignore: cast_nullable_to_non_nullable
as bool,message: freezed == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String?,data: freezed == data ? _self.data : data // ignore: cast_nullable_to_non_nullable
as ForgotPasswordData?,error: freezed == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
as ErrorModel?,meta: freezed == meta ? _self.meta : meta // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
));
}
/// Create a copy of ForgotPasswordResponseModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ForgotPasswordDataCopyWith<$Res>? get data {
if (_self.data == null) {
return null;
}
return $ForgotPasswordDataCopyWith<$Res>(_self.data!, (value) {
return _then(_self.copyWith(data: value));
});
}/// Create a copy of ForgotPasswordResponseModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ErrorModelCopyWith<$Res>? get error {
if (_self.error == null) {
return null;
}
return $ErrorModelCopyWith<$Res>(_self.error!, (value) {
return _then(_self.copyWith(error: value));
});
}
}
/// Adds pattern-matching-related methods to [ForgotPasswordResponseModel].
extension ForgotPasswordResponseModelPatterns on ForgotPasswordResponseModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _ForgotPasswordResponseModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _ForgotPasswordResponseModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _ForgotPasswordResponseModel value) $default,){
final _that = this;
switch (_that) {
case _ForgotPasswordResponseModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _ForgotPasswordResponseModel value)? $default,){
final _that = this;
switch (_that) {
case _ForgotPasswordResponseModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( bool success, String? message, ForgotPasswordData? data, ErrorModel? error, Map<String, dynamic>? meta)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _ForgotPasswordResponseModel() when $default != null:
return $default(_that.success,_that.message,_that.data,_that.error,_that.meta);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( bool success, String? message, ForgotPasswordData? data, ErrorModel? error, Map<String, dynamic>? meta) $default,) {final _that = this;
switch (_that) {
case _ForgotPasswordResponseModel():
return $default(_that.success,_that.message,_that.data,_that.error,_that.meta);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( bool success, String? message, ForgotPasswordData? data, ErrorModel? error, Map<String, dynamic>? meta)? $default,) {final _that = this;
switch (_that) {
case _ForgotPasswordResponseModel() when $default != null:
return $default(_that.success,_that.message,_that.data,_that.error,_that.meta);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _ForgotPasswordResponseModel implements ForgotPasswordResponseModel {
const _ForgotPasswordResponseModel({required this.success, required this.message, required this.data, required this.error, required final Map<String, dynamic>? meta}): _meta = meta;
factory _ForgotPasswordResponseModel.fromJson(Map<String, dynamic> json) => _$ForgotPasswordResponseModelFromJson(json);
@override final bool success;
@override final String? message;
@override final ForgotPasswordData? data;
@override final ErrorModel? error;
final Map<String, dynamic>? _meta;
@override Map<String, dynamic>? get meta {
final value = _meta;
if (value == null) return null;
if (_meta is EqualUnmodifiableMapView) return _meta;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}
/// Create a copy of ForgotPasswordResponseModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$ForgotPasswordResponseModelCopyWith<_ForgotPasswordResponseModel> get copyWith => __$ForgotPasswordResponseModelCopyWithImpl<_ForgotPasswordResponseModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$ForgotPasswordResponseModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ForgotPasswordResponseModel&&(identical(other.success, success) || other.success == success)&&(identical(other.message, message) || other.message == message)&&(identical(other.data, data) || other.data == data)&&(identical(other.error, error) || other.error == error)&&const DeepCollectionEquality().equals(other._meta, _meta));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,success,message,data,error,const DeepCollectionEquality().hash(_meta));
@override
String toString() {
return 'ForgotPasswordResponseModel(success: $success, message: $message, data: $data, error: $error, meta: $meta)';
}
}
/// @nodoc
abstract mixin class _$ForgotPasswordResponseModelCopyWith<$Res> implements $ForgotPasswordResponseModelCopyWith<$Res> {
factory _$ForgotPasswordResponseModelCopyWith(_ForgotPasswordResponseModel value, $Res Function(_ForgotPasswordResponseModel) _then) = __$ForgotPasswordResponseModelCopyWithImpl;
@override @useResult
$Res call({
bool success, String? message, ForgotPasswordData? data, ErrorModel? error, Map<String, dynamic>? meta
});
@override $ForgotPasswordDataCopyWith<$Res>? get data;@override $ErrorModelCopyWith<$Res>? get error;
}
/// @nodoc
class __$ForgotPasswordResponseModelCopyWithImpl<$Res>
implements _$ForgotPasswordResponseModelCopyWith<$Res> {
__$ForgotPasswordResponseModelCopyWithImpl(this._self, this._then);
final _ForgotPasswordResponseModel _self;
final $Res Function(_ForgotPasswordResponseModel) _then;
/// Create a copy of ForgotPasswordResponseModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? success = null,Object? message = freezed,Object? data = freezed,Object? error = freezed,Object? meta = freezed,}) {
return _then(_ForgotPasswordResponseModel(
success: null == success ? _self.success : success // ignore: cast_nullable_to_non_nullable
as bool,message: freezed == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String?,data: freezed == data ? _self.data : data // ignore: cast_nullable_to_non_nullable
as ForgotPasswordData?,error: freezed == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
as ErrorModel?,meta: freezed == meta ? _self._meta : meta // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
));
}
/// Create a copy of ForgotPasswordResponseModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ForgotPasswordDataCopyWith<$Res>? get data {
if (_self.data == null) {
return null;
}
return $ForgotPasswordDataCopyWith<$Res>(_self.data!, (value) {
return _then(_self.copyWith(data: value));
});
}/// Create a copy of ForgotPasswordResponseModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ErrorModelCopyWith<$Res>? get error {
if (_self.error == null) {
return null;
}
return $ErrorModelCopyWith<$Res>(_self.error!, (value) {
return _then(_self.copyWith(error: value));
});
}
}
/// @nodoc
mixin _$ForgotPasswordData {
String? get message; bool? get success;
/// Create a copy of ForgotPasswordData
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$ForgotPasswordDataCopyWith<ForgotPasswordData> get copyWith => _$ForgotPasswordDataCopyWithImpl<ForgotPasswordData>(this as ForgotPasswordData, _$identity);
/// Serializes this ForgotPasswordData to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is ForgotPasswordData&&(identical(other.message, message) || other.message == message)&&(identical(other.success, success) || other.success == success));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,message,success);
@override
String toString() {
return 'ForgotPasswordData(message: $message, success: $success)';
}
}
/// @nodoc
abstract mixin class $ForgotPasswordDataCopyWith<$Res> {
factory $ForgotPasswordDataCopyWith(ForgotPasswordData value, $Res Function(ForgotPasswordData) _then) = _$ForgotPasswordDataCopyWithImpl;
@useResult
$Res call({
String? message, bool? success
});
}
/// @nodoc
class _$ForgotPasswordDataCopyWithImpl<$Res>
implements $ForgotPasswordDataCopyWith<$Res> {
_$ForgotPasswordDataCopyWithImpl(this._self, this._then);
final ForgotPasswordData _self;
final $Res Function(ForgotPasswordData) _then;
/// Create a copy of ForgotPasswordData
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? message = freezed,Object? success = freezed,}) {
return _then(_self.copyWith(
message: freezed == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String?,success: freezed == success ? _self.success : success // ignore: cast_nullable_to_non_nullable
as bool?,
));
}
}
/// Adds pattern-matching-related methods to [ForgotPasswordData].
extension ForgotPasswordDataPatterns on ForgotPasswordData {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _ForgotPasswordData value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _ForgotPasswordData() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _ForgotPasswordData value) $default,){
final _that = this;
switch (_that) {
case _ForgotPasswordData():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _ForgotPasswordData value)? $default,){
final _that = this;
switch (_that) {
case _ForgotPasswordData() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String? message, bool? success)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _ForgotPasswordData() when $default != null:
return $default(_that.message,_that.success);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String? message, bool? success) $default,) {final _that = this;
switch (_that) {
case _ForgotPasswordData():
return $default(_that.message,_that.success);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String? message, bool? success)? $default,) {final _that = this;
switch (_that) {
case _ForgotPasswordData() when $default != null:
return $default(_that.message,_that.success);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _ForgotPasswordData implements ForgotPasswordData {
const _ForgotPasswordData({required this.message, required this.success});
factory _ForgotPasswordData.fromJson(Map<String, dynamic> json) => _$ForgotPasswordDataFromJson(json);
@override final String? message;
@override final bool? success;
/// Create a copy of ForgotPasswordData
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$ForgotPasswordDataCopyWith<_ForgotPasswordData> get copyWith => __$ForgotPasswordDataCopyWithImpl<_ForgotPasswordData>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$ForgotPasswordDataToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ForgotPasswordData&&(identical(other.message, message) || other.message == message)&&(identical(other.success, success) || other.success == success));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,message,success);
@override
String toString() {
return 'ForgotPasswordData(message: $message, success: $success)';
}
}
/// @nodoc
abstract mixin class _$ForgotPasswordDataCopyWith<$Res> implements $ForgotPasswordDataCopyWith<$Res> {
factory _$ForgotPasswordDataCopyWith(_ForgotPasswordData value, $Res Function(_ForgotPasswordData) _then) = __$ForgotPasswordDataCopyWithImpl;
@override @useResult
$Res call({
String? message, bool? success
});
}
/// @nodoc
class __$ForgotPasswordDataCopyWithImpl<$Res>
implements _$ForgotPasswordDataCopyWith<$Res> {
__$ForgotPasswordDataCopyWithImpl(this._self, this._then);
final _ForgotPasswordData _self;
final $Res Function(_ForgotPasswordData) _then;
/// Create a copy of ForgotPasswordData
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? message = freezed,Object? success = freezed,}) {
return _then(_ForgotPasswordData(
message: freezed == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String?,success: freezed == success ? _self.success : success // ignore: cast_nullable_to_non_nullable
as bool?,
));
}
}
// dart format on
@@ -0,0 +1,42 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'forgot_password_response_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_ForgotPasswordResponseModel _$ForgotPasswordResponseModelFromJson(
Map<String, dynamic> json,
) => _ForgotPasswordResponseModel(
success: json['success'] as bool,
message: json['message'] as String?,
data:
json['data'] == null
? null
: ForgotPasswordData.fromJson(json['data'] as Map<String, dynamic>),
error:
json['error'] == null
? null
: ErrorModel.fromJson(json['error'] as Map<String, dynamic>),
meta: json['meta'] as Map<String, dynamic>?,
);
Map<String, dynamic> _$ForgotPasswordResponseModelToJson(
_ForgotPasswordResponseModel instance,
) => <String, dynamic>{
'success': instance.success,
'message': instance.message,
'data': instance.data,
'error': instance.error,
'meta': instance.meta,
};
_ForgotPasswordData _$ForgotPasswordDataFromJson(Map<String, dynamic> json) =>
_ForgotPasswordData(
message: json['message'] as String?,
success: json['success'] as bool?,
);
Map<String, dynamic> _$ForgotPasswordDataToJson(_ForgotPasswordData instance) =>
<String, dynamic>{'message': instance.message, 'success': instance.success};