add auth register

This commit is contained in:
Phuoc Nguyen
2025-11-07 15:55:02 +07:00
parent ce7396f729
commit 9e55983d82
16 changed files with 2376 additions and 110 deletions

View File

@@ -0,0 +1,245 @@
/// Authentication Remote Data Source
///
/// Handles all authentication-related API calls.
library;
import 'package:dio/dio.dart';
import 'package:worker/core/errors/exceptions.dart';
import 'package:worker/features/auth/data/models/auth_session_model.dart';
import 'package:worker/features/auth/domain/entities/city.dart';
import 'package:worker/features/auth/domain/entities/customer_group.dart';
/// Authentication Remote Data Source
///
/// Provides methods for:
/// - Getting session (CSRF token and SID)
/// - Fetching cities for registration
/// - Fetching customer groups (roles) for registration
/// - User registration
class AuthRemoteDataSource {
final Dio _dio;
AuthRemoteDataSource(this._dio);
/// Get Session
///
/// Fetches session data including SID and CSRF token.
/// This should be called before making authenticated requests.
///
/// API: POST /api/method/dbiz_common.dbiz_common.api.auth.get_session
Future<GetSessionResponse> getSession() async {
try {
final response = await _dio.post<Map<String, dynamic>>(
'/api/method/dbiz_common.dbiz_common.api.auth.get_session',
data: '',
);
if (response.statusCode == 200 && response.data != null) {
return GetSessionResponse.fromJson(response.data!);
} else {
throw ServerException(
'Failed to get session: ${response.statusCode}',
);
}
} on DioException catch (e) {
if (e.response?.statusCode == 401) {
throw const UnauthorizedException();
} else if (e.response?.statusCode == 404) {
throw NotFoundException('Session endpoint not found');
} else {
throw NetworkException(
e.message ?? 'Failed to get session',
);
}
} catch (e) {
throw ServerException('Unexpected error: $e');
}
}
/// Get Cities
///
/// Fetches list of cities/provinces for address selection.
/// Requires authenticated session (CSRF token and Cookie).
///
/// API: POST /api/method/frappe.client.get_list
/// DocType: City
Future<List<City>> getCities({
required String csrfToken,
required String sid,
}) async {
try {
final response = await _dio.post<Map<String, dynamic>>(
'/api/method/frappe.client.get_list',
data: {
'doctype': 'City',
'fields': ['city_name', 'name', 'code'],
'limit_page_length': 0,
},
options: Options(
headers: {
'X-Frappe-Csrf-Token': csrfToken,
'Cookie': 'sid=$sid',
},
),
);
if (response.statusCode == 200 && response.data != null) {
final message = response.data!['message'];
if (message is List) {
return message
.map((json) => City.fromJson(json as Map<String, dynamic>))
.toList();
} else {
throw ServerException('Invalid response format for cities');
}
} else {
throw ServerException(
'Failed to get cities: ${response.statusCode}',
);
}
} on DioException catch (e) {
if (e.response?.statusCode == 401) {
throw const UnauthorizedException();
} else if (e.response?.statusCode == 404) {
throw NotFoundException('Cities endpoint not found');
} else {
throw NetworkException(
e.message ?? 'Failed to get cities',
);
}
} catch (e) {
throw ServerException('Unexpected error: $e');
}
}
/// Get Customer Groups (Roles)
///
/// Fetches list of customer groups for user role selection.
/// Requires authenticated session (CSRF token and Cookie).
///
/// API: POST /api/method/frappe.client.get_list
/// DocType: Customer Group
Future<List<CustomerGroup>> getCustomerGroups({
required String csrfToken,
required String sid,
}) async {
try {
final response = await _dio.post<Map<String, dynamic>>(
'/api/method/frappe.client.get_list',
data: {
'doctype': 'Customer Group',
'fields': ['customer_group_name', 'name', 'value'],
'filters': {
'is_group': 0,
'is_active': 1,
'customer': 1,
},
'limit_page_length': 0,
},
options: Options(
headers: {
'X-Frappe-Csrf-Token': csrfToken,
'Cookie': 'sid=$sid',
},
),
);
if (response.statusCode == 200 && response.data != null) {
final message = response.data!['message'];
if (message is List) {
return message
.map((json) =>
CustomerGroup.fromJson(json as Map<String, dynamic>))
.toList();
} else {
throw ServerException('Invalid response format for customer groups');
}
} else {
throw ServerException(
'Failed to get customer groups: ${response.statusCode}',
);
}
} on DioException catch (e) {
if (e.response?.statusCode == 401) {
throw const UnauthorizedException();
} else if (e.response?.statusCode == 404) {
throw NotFoundException('Customer groups endpoint not found');
} else {
throw NetworkException(
e.message ?? 'Failed to get customer groups',
);
}
} catch (e) {
throw ServerException('Unexpected error: $e');
}
}
/// Register User
///
/// Registers a new user with the provided information.
/// Requires authenticated session (CSRF token and Cookie).
///
/// API: POST /api/method/building_material.building_material.api.user.register
Future<Map<String, dynamic>> register({
required String csrfToken,
required String sid,
required String fullName,
required String phone,
required String email,
required String customerGroupCode,
required String cityCode,
String? companyName,
String? taxCode,
String? idCardFrontBase64,
String? idCardBackBase64,
List<String>? certificatesBase64,
}) async {
try {
final response = await _dio.post<Map<String, dynamic>>(
'/api/method/building_material.building_material.api.user.register',
data: {
'full_name': fullName,
'phone': phone,
'email': email,
'customer_group_code': customerGroupCode,
'city_code': cityCode,
'company_name': companyName,
'tax_code': taxCode,
'id_card_front_base64': idCardFrontBase64,
'id_card_back_base64': idCardBackBase64,
'certificates_base64': certificatesBase64 ?? [],
},
options: Options(
headers: {
'X-Frappe-Csrf-Token': csrfToken,
'Cookie': 'sid=$sid',
},
),
);
if (response.statusCode == 200 && response.data != null) {
return response.data!;
} else {
throw ServerException(
'Failed to register: ${response.statusCode}',
);
}
} on DioException catch (e) {
if (e.response?.statusCode == 401) {
throw const UnauthorizedException();
} else if (e.response?.statusCode == 400) {
throw ValidationException(
e.response?.data?['message'] as String? ?? 'Validation error',
);
} else if (e.response?.statusCode == 404) {
throw NotFoundException('Register endpoint not found');
} else {
throw NetworkException(
e.message ?? 'Failed to register',
);
}
} catch (e) {
throw ServerException('Unexpected error: $e');
}
}
}

View File

@@ -57,6 +57,48 @@ sealed class AuthSessionResponse with _$AuthSessionResponse {
_$AuthSessionResponseFromJson(json);
}
/// Session Data (for GET SESSION API)
///
/// Represents the session data structure from get_session API.
@freezed
sealed class GetSessionData with _$GetSessionData {
const factory GetSessionData({
required String sid,
@JsonKey(name: 'csrf_token') required String csrfToken,
}) = _GetSessionData;
factory GetSessionData.fromJson(Map<String, dynamic> json) =>
_$GetSessionDataFromJson(json);
}
/// Get Session Message
///
/// Wrapper for session data in get_session API response.
@freezed
sealed class GetSessionMessage with _$GetSessionMessage {
const factory GetSessionMessage({
required GetSessionData data,
}) = _GetSessionMessage;
factory GetSessionMessage.fromJson(Map<String, dynamic> json) =>
_$GetSessionMessageFromJson(json);
}
/// Get Session Response
///
/// Complete response from get_session API.
@freezed
sealed class GetSessionResponse with _$GetSessionResponse {
const factory GetSessionResponse({
required GetSessionMessage message,
@JsonKey(name: 'home_page') required String homePage,
@JsonKey(name: 'full_name') required String fullName,
}) = _GetSessionResponse;
factory GetSessionResponse.fromJson(Map<String, dynamic> json) =>
_$GetSessionResponseFromJson(json);
}
/// Session Storage Model
///
/// Simplified model for storing session data in Hive.
@@ -73,7 +115,17 @@ sealed class SessionData with _$SessionData {
factory SessionData.fromJson(Map<String, dynamic> json) =>
_$SessionDataFromJson(json);
/// Create from API response
/// Create from get_session API response
factory SessionData.fromGetSessionResponse(GetSessionResponse response) {
return SessionData(
sid: response.message.data.sid,
csrfToken: response.message.data.csrfToken,
fullName: response.fullName,
createdAt: DateTime.now(),
);
}
/// Create from auth login API response
factory SessionData.fromAuthResponse(AuthSessionResponse response) {
return SessionData(
sid: response.message.sid,

View File

@@ -834,6 +834,822 @@ $LoginMessageCopyWith<$Res> get message {
}
/// @nodoc
mixin _$GetSessionData {
String get sid;@JsonKey(name: 'csrf_token') String get csrfToken;
/// Create a copy of GetSessionData
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$GetSessionDataCopyWith<GetSessionData> get copyWith => _$GetSessionDataCopyWithImpl<GetSessionData>(this as GetSessionData, _$identity);
/// Serializes this GetSessionData to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is GetSessionData&&(identical(other.sid, sid) || other.sid == sid)&&(identical(other.csrfToken, csrfToken) || other.csrfToken == csrfToken));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,sid,csrfToken);
@override
String toString() {
return 'GetSessionData(sid: $sid, csrfToken: $csrfToken)';
}
}
/// @nodoc
abstract mixin class $GetSessionDataCopyWith<$Res> {
factory $GetSessionDataCopyWith(GetSessionData value, $Res Function(GetSessionData) _then) = _$GetSessionDataCopyWithImpl;
@useResult
$Res call({
String sid,@JsonKey(name: 'csrf_token') String csrfToken
});
}
/// @nodoc
class _$GetSessionDataCopyWithImpl<$Res>
implements $GetSessionDataCopyWith<$Res> {
_$GetSessionDataCopyWithImpl(this._self, this._then);
final GetSessionData _self;
final $Res Function(GetSessionData) _then;
/// Create a copy of GetSessionData
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? sid = null,Object? csrfToken = null,}) {
return _then(_self.copyWith(
sid: null == sid ? _self.sid : sid // ignore: cast_nullable_to_non_nullable
as String,csrfToken: null == csrfToken ? _self.csrfToken : csrfToken // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// Adds pattern-matching-related methods to [GetSessionData].
extension GetSessionDataPatterns on GetSessionData {
/// 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( _GetSessionData value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _GetSessionData() 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( _GetSessionData value) $default,){
final _that = this;
switch (_that) {
case _GetSessionData():
return $default(_that);}
}
/// 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( _GetSessionData value)? $default,){
final _that = this;
switch (_that) {
case _GetSessionData() 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 sid, @JsonKey(name: 'csrf_token') String csrfToken)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _GetSessionData() when $default != null:
return $default(_that.sid,_that.csrfToken);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 sid, @JsonKey(name: 'csrf_token') String csrfToken) $default,) {final _that = this;
switch (_that) {
case _GetSessionData():
return $default(_that.sid,_that.csrfToken);}
}
/// 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 sid, @JsonKey(name: 'csrf_token') String csrfToken)? $default,) {final _that = this;
switch (_that) {
case _GetSessionData() when $default != null:
return $default(_that.sid,_that.csrfToken);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _GetSessionData implements GetSessionData {
const _GetSessionData({required this.sid, @JsonKey(name: 'csrf_token') required this.csrfToken});
factory _GetSessionData.fromJson(Map<String, dynamic> json) => _$GetSessionDataFromJson(json);
@override final String sid;
@override@JsonKey(name: 'csrf_token') final String csrfToken;
/// Create a copy of GetSessionData
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$GetSessionDataCopyWith<_GetSessionData> get copyWith => __$GetSessionDataCopyWithImpl<_GetSessionData>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$GetSessionDataToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _GetSessionData&&(identical(other.sid, sid) || other.sid == sid)&&(identical(other.csrfToken, csrfToken) || other.csrfToken == csrfToken));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,sid,csrfToken);
@override
String toString() {
return 'GetSessionData(sid: $sid, csrfToken: $csrfToken)';
}
}
/// @nodoc
abstract mixin class _$GetSessionDataCopyWith<$Res> implements $GetSessionDataCopyWith<$Res> {
factory _$GetSessionDataCopyWith(_GetSessionData value, $Res Function(_GetSessionData) _then) = __$GetSessionDataCopyWithImpl;
@override @useResult
$Res call({
String sid,@JsonKey(name: 'csrf_token') String csrfToken
});
}
/// @nodoc
class __$GetSessionDataCopyWithImpl<$Res>
implements _$GetSessionDataCopyWith<$Res> {
__$GetSessionDataCopyWithImpl(this._self, this._then);
final _GetSessionData _self;
final $Res Function(_GetSessionData) _then;
/// Create a copy of GetSessionData
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? sid = null,Object? csrfToken = null,}) {
return _then(_GetSessionData(
sid: null == sid ? _self.sid : sid // ignore: cast_nullable_to_non_nullable
as String,csrfToken: null == csrfToken ? _self.csrfToken : csrfToken // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
mixin _$GetSessionMessage {
GetSessionData get data;
/// Create a copy of GetSessionMessage
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$GetSessionMessageCopyWith<GetSessionMessage> get copyWith => _$GetSessionMessageCopyWithImpl<GetSessionMessage>(this as GetSessionMessage, _$identity);
/// Serializes this GetSessionMessage to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is GetSessionMessage&&(identical(other.data, data) || other.data == data));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,data);
@override
String toString() {
return 'GetSessionMessage(data: $data)';
}
}
/// @nodoc
abstract mixin class $GetSessionMessageCopyWith<$Res> {
factory $GetSessionMessageCopyWith(GetSessionMessage value, $Res Function(GetSessionMessage) _then) = _$GetSessionMessageCopyWithImpl;
@useResult
$Res call({
GetSessionData data
});
$GetSessionDataCopyWith<$Res> get data;
}
/// @nodoc
class _$GetSessionMessageCopyWithImpl<$Res>
implements $GetSessionMessageCopyWith<$Res> {
_$GetSessionMessageCopyWithImpl(this._self, this._then);
final GetSessionMessage _self;
final $Res Function(GetSessionMessage) _then;
/// Create a copy of GetSessionMessage
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? data = null,}) {
return _then(_self.copyWith(
data: null == data ? _self.data : data // ignore: cast_nullable_to_non_nullable
as GetSessionData,
));
}
/// Create a copy of GetSessionMessage
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$GetSessionDataCopyWith<$Res> get data {
return $GetSessionDataCopyWith<$Res>(_self.data, (value) {
return _then(_self.copyWith(data: value));
});
}
}
/// Adds pattern-matching-related methods to [GetSessionMessage].
extension GetSessionMessagePatterns on GetSessionMessage {
/// 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( _GetSessionMessage value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _GetSessionMessage() 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( _GetSessionMessage value) $default,){
final _that = this;
switch (_that) {
case _GetSessionMessage():
return $default(_that);}
}
/// 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( _GetSessionMessage value)? $default,){
final _that = this;
switch (_that) {
case _GetSessionMessage() 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( GetSessionData data)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _GetSessionMessage() when $default != null:
return $default(_that.data);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( GetSessionData data) $default,) {final _that = this;
switch (_that) {
case _GetSessionMessage():
return $default(_that.data);}
}
/// 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( GetSessionData data)? $default,) {final _that = this;
switch (_that) {
case _GetSessionMessage() when $default != null:
return $default(_that.data);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _GetSessionMessage implements GetSessionMessage {
const _GetSessionMessage({required this.data});
factory _GetSessionMessage.fromJson(Map<String, dynamic> json) => _$GetSessionMessageFromJson(json);
@override final GetSessionData data;
/// Create a copy of GetSessionMessage
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$GetSessionMessageCopyWith<_GetSessionMessage> get copyWith => __$GetSessionMessageCopyWithImpl<_GetSessionMessage>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$GetSessionMessageToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _GetSessionMessage&&(identical(other.data, data) || other.data == data));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,data);
@override
String toString() {
return 'GetSessionMessage(data: $data)';
}
}
/// @nodoc
abstract mixin class _$GetSessionMessageCopyWith<$Res> implements $GetSessionMessageCopyWith<$Res> {
factory _$GetSessionMessageCopyWith(_GetSessionMessage value, $Res Function(_GetSessionMessage) _then) = __$GetSessionMessageCopyWithImpl;
@override @useResult
$Res call({
GetSessionData data
});
@override $GetSessionDataCopyWith<$Res> get data;
}
/// @nodoc
class __$GetSessionMessageCopyWithImpl<$Res>
implements _$GetSessionMessageCopyWith<$Res> {
__$GetSessionMessageCopyWithImpl(this._self, this._then);
final _GetSessionMessage _self;
final $Res Function(_GetSessionMessage) _then;
/// Create a copy of GetSessionMessage
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? data = null,}) {
return _then(_GetSessionMessage(
data: null == data ? _self.data : data // ignore: cast_nullable_to_non_nullable
as GetSessionData,
));
}
/// Create a copy of GetSessionMessage
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$GetSessionDataCopyWith<$Res> get data {
return $GetSessionDataCopyWith<$Res>(_self.data, (value) {
return _then(_self.copyWith(data: value));
});
}
}
/// @nodoc
mixin _$GetSessionResponse {
GetSessionMessage get message;@JsonKey(name: 'home_page') String get homePage;@JsonKey(name: 'full_name') String get fullName;
/// Create a copy of GetSessionResponse
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$GetSessionResponseCopyWith<GetSessionResponse> get copyWith => _$GetSessionResponseCopyWithImpl<GetSessionResponse>(this as GetSessionResponse, _$identity);
/// Serializes this GetSessionResponse to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is GetSessionResponse&&(identical(other.message, message) || other.message == message)&&(identical(other.homePage, homePage) || other.homePage == homePage)&&(identical(other.fullName, fullName) || other.fullName == fullName));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,message,homePage,fullName);
@override
String toString() {
return 'GetSessionResponse(message: $message, homePage: $homePage, fullName: $fullName)';
}
}
/// @nodoc
abstract mixin class $GetSessionResponseCopyWith<$Res> {
factory $GetSessionResponseCopyWith(GetSessionResponse value, $Res Function(GetSessionResponse) _then) = _$GetSessionResponseCopyWithImpl;
@useResult
$Res call({
GetSessionMessage message,@JsonKey(name: 'home_page') String homePage,@JsonKey(name: 'full_name') String fullName
});
$GetSessionMessageCopyWith<$Res> get message;
}
/// @nodoc
class _$GetSessionResponseCopyWithImpl<$Res>
implements $GetSessionResponseCopyWith<$Res> {
_$GetSessionResponseCopyWithImpl(this._self, this._then);
final GetSessionResponse _self;
final $Res Function(GetSessionResponse) _then;
/// Create a copy of GetSessionResponse
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? message = null,Object? homePage = null,Object? fullName = null,}) {
return _then(_self.copyWith(
message: null == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as GetSessionMessage,homePage: null == homePage ? _self.homePage : homePage // ignore: cast_nullable_to_non_nullable
as String,fullName: null == fullName ? _self.fullName : fullName // ignore: cast_nullable_to_non_nullable
as String,
));
}
/// Create a copy of GetSessionResponse
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$GetSessionMessageCopyWith<$Res> get message {
return $GetSessionMessageCopyWith<$Res>(_self.message, (value) {
return _then(_self.copyWith(message: value));
});
}
}
/// Adds pattern-matching-related methods to [GetSessionResponse].
extension GetSessionResponsePatterns on GetSessionResponse {
/// 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( _GetSessionResponse value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _GetSessionResponse() 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( _GetSessionResponse value) $default,){
final _that = this;
switch (_that) {
case _GetSessionResponse():
return $default(_that);}
}
/// 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( _GetSessionResponse value)? $default,){
final _that = this;
switch (_that) {
case _GetSessionResponse() 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( GetSessionMessage message, @JsonKey(name: 'home_page') String homePage, @JsonKey(name: 'full_name') String fullName)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _GetSessionResponse() when $default != null:
return $default(_that.message,_that.homePage,_that.fullName);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( GetSessionMessage message, @JsonKey(name: 'home_page') String homePage, @JsonKey(name: 'full_name') String fullName) $default,) {final _that = this;
switch (_that) {
case _GetSessionResponse():
return $default(_that.message,_that.homePage,_that.fullName);}
}
/// 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( GetSessionMessage message, @JsonKey(name: 'home_page') String homePage, @JsonKey(name: 'full_name') String fullName)? $default,) {final _that = this;
switch (_that) {
case _GetSessionResponse() when $default != null:
return $default(_that.message,_that.homePage,_that.fullName);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _GetSessionResponse implements GetSessionResponse {
const _GetSessionResponse({required this.message, @JsonKey(name: 'home_page') required this.homePage, @JsonKey(name: 'full_name') required this.fullName});
factory _GetSessionResponse.fromJson(Map<String, dynamic> json) => _$GetSessionResponseFromJson(json);
@override final GetSessionMessage message;
@override@JsonKey(name: 'home_page') final String homePage;
@override@JsonKey(name: 'full_name') final String fullName;
/// Create a copy of GetSessionResponse
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$GetSessionResponseCopyWith<_GetSessionResponse> get copyWith => __$GetSessionResponseCopyWithImpl<_GetSessionResponse>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$GetSessionResponseToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _GetSessionResponse&&(identical(other.message, message) || other.message == message)&&(identical(other.homePage, homePage) || other.homePage == homePage)&&(identical(other.fullName, fullName) || other.fullName == fullName));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,message,homePage,fullName);
@override
String toString() {
return 'GetSessionResponse(message: $message, homePage: $homePage, fullName: $fullName)';
}
}
/// @nodoc
abstract mixin class _$GetSessionResponseCopyWith<$Res> implements $GetSessionResponseCopyWith<$Res> {
factory _$GetSessionResponseCopyWith(_GetSessionResponse value, $Res Function(_GetSessionResponse) _then) = __$GetSessionResponseCopyWithImpl;
@override @useResult
$Res call({
GetSessionMessage message,@JsonKey(name: 'home_page') String homePage,@JsonKey(name: 'full_name') String fullName
});
@override $GetSessionMessageCopyWith<$Res> get message;
}
/// @nodoc
class __$GetSessionResponseCopyWithImpl<$Res>
implements _$GetSessionResponseCopyWith<$Res> {
__$GetSessionResponseCopyWithImpl(this._self, this._then);
final _GetSessionResponse _self;
final $Res Function(_GetSessionResponse) _then;
/// Create a copy of GetSessionResponse
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? message = null,Object? homePage = null,Object? fullName = null,}) {
return _then(_GetSessionResponse(
message: null == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as GetSessionMessage,homePage: null == homePage ? _self.homePage : homePage // ignore: cast_nullable_to_non_nullable
as String,fullName: null == fullName ? _self.fullName : fullName // ignore: cast_nullable_to_non_nullable
as String,
));
}
/// Create a copy of GetSessionResponse
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$GetSessionMessageCopyWith<$Res> get message {
return $GetSessionMessageCopyWith<$Res>(_self.message, (value) {
return _then(_self.copyWith(message: value));
});
}
}
/// @nodoc
mixin _$SessionData {

View File

@@ -93,6 +93,57 @@ Map<String, dynamic> _$AuthSessionResponseToJson(
'full_name': instance.fullName,
};
_GetSessionData _$GetSessionDataFromJson(Map<String, dynamic> json) =>
$checkedCreate('_GetSessionData', json, ($checkedConvert) {
final val = _GetSessionData(
sid: $checkedConvert('sid', (v) => v as String),
csrfToken: $checkedConvert('csrf_token', (v) => v as String),
);
return val;
}, fieldKeyMap: const {'csrfToken': 'csrf_token'});
Map<String, dynamic> _$GetSessionDataToJson(_GetSessionData instance) =>
<String, dynamic>{'sid': instance.sid, 'csrf_token': instance.csrfToken};
_GetSessionMessage _$GetSessionMessageFromJson(Map<String, dynamic> json) =>
$checkedCreate('_GetSessionMessage', json, ($checkedConvert) {
final val = _GetSessionMessage(
data: $checkedConvert(
'data',
(v) => GetSessionData.fromJson(v as Map<String, dynamic>),
),
);
return val;
});
Map<String, dynamic> _$GetSessionMessageToJson(_GetSessionMessage instance) =>
<String, dynamic>{'data': instance.data.toJson()};
_GetSessionResponse _$GetSessionResponseFromJson(Map<String, dynamic> json) =>
$checkedCreate(
'_GetSessionResponse',
json,
($checkedConvert) {
final val = _GetSessionResponse(
message: $checkedConvert(
'message',
(v) => GetSessionMessage.fromJson(v as Map<String, dynamic>),
),
homePage: $checkedConvert('home_page', (v) => v as String),
fullName: $checkedConvert('full_name', (v) => v as String),
);
return val;
},
fieldKeyMap: const {'homePage': 'home_page', 'fullName': 'full_name'},
);
Map<String, dynamic> _$GetSessionResponseToJson(_GetSessionResponse instance) =>
<String, dynamic>{
'message': instance.message.toJson(),
'home_page': instance.homePage,
'full_name': instance.fullName,
};
_SessionData _$SessionDataFromJson(Map<String, dynamic> json) => $checkedCreate(
'_SessionData',
json,