forked from eatvio/eatvio_app
feat(oauth): Issue-691
This commit is contained in:
44
lib/features/settings/models/oauth_account_model.dart
Normal file
44
lib/features/settings/models/oauth_account_model.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'oauth_account_model.freezed.dart';
|
||||
part 'oauth_account_model.g.dart';
|
||||
|
||||
@freezed
|
||||
abstract class OAuthAccountModel with _$OAuthAccountModel {
|
||||
const factory OAuthAccountModel({
|
||||
@JsonKey(name: 'oauth_id') required String oauthId,
|
||||
required String name,
|
||||
required String email,
|
||||
required String phone,
|
||||
@JsonKey(name: 'linked_at') required DateTime linkedAt,
|
||||
}) = _OAuthAccountModel;
|
||||
|
||||
factory OAuthAccountModel.fromJson(Map<String, dynamic> json) => _$OAuthAccountModelFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class OAuthAccountsResponseModel with _$OAuthAccountsResponseModel {
|
||||
const factory OAuthAccountsResponseModel({required bool success, required OAuthAccountsDataModel data}) = _OAuthAccountsResponseModel;
|
||||
|
||||
factory OAuthAccountsResponseModel.fromJson(Map<String, dynamic> json) => _$OAuthAccountsResponseModelFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class OAuthAccountsDataModel with _$OAuthAccountsDataModel {
|
||||
const factory OAuthAccountsDataModel({
|
||||
@JsonKey(fromJson: _oauthAccountFromJson) OAuthAccountModel? vk,
|
||||
@JsonKey(fromJson: _oauthAccountFromJson) OAuthAccountModel? yandex,
|
||||
}) = _OAuthAccountsDataModel;
|
||||
|
||||
factory OAuthAccountsDataModel.fromJson(Map<String, dynamic> json) => _$OAuthAccountsDataModelFromJson(json);
|
||||
}
|
||||
|
||||
// Custom converter to handle both empty array [] and object
|
||||
OAuthAccountModel? _oauthAccountFromJson(dynamic json) {
|
||||
if (json == null) return null;
|
||||
if (json is List && json.isEmpty) return null;
|
||||
if (json is Map<String, dynamic>) {
|
||||
return OAuthAccountModel.fromJson(json);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
17
lib/features/settings/models/oauth_attach_request.dart
Normal file
17
lib/features/settings/models/oauth_attach_request.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'oauth_attach_request.freezed.dart';
|
||||
part 'oauth_attach_request.g.dart';
|
||||
|
||||
@freezed
|
||||
abstract class OAuthAttachRequest with _$OAuthAttachRequest {
|
||||
const factory OAuthAttachRequest({
|
||||
required String provider,
|
||||
@JsonKey(name: 'client_id') String? clientId,
|
||||
@JsonKey(name: 'access_token') required String accessToken,
|
||||
@JsonKey(name: 'refresh_token') required String refreshToken,
|
||||
}) = _OAuthAttachRequest;
|
||||
|
||||
factory OAuthAttachRequest.fromJson(Map<String, dynamic> json) => _$OAuthAttachRequestFromJson(json);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user