From 846c96e90d38a354730c5b6819dee206573ecd66 Mon Sep 17 00:00:00 2001 From: Lukas Lihotzki Date: Wed, 5 May 2021 12:08:03 +0200 Subject: [PATCH] refactor: move identifier type detection into AuthenticationIdentifier --- .../model/auth/authentication_identifier.dart | 18 ++++++++++++++++++ .../model/auth/authentication_password.dart | 19 ++----------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/src/model/auth/authentication_identifier.dart b/lib/src/model/auth/authentication_identifier.dart index e46613b8..29242a83 100644 --- a/lib/src/model/auth/authentication_identifier.dart +++ b/lib/src/model/auth/authentication_identifier.dart @@ -21,6 +21,11 @@ * SOFTWARE. */ +import 'authentication_types.dart'; +import 'authentication_user_identifier.dart'; +import 'authentication_phone_identifier.dart'; +import 'authentication_third_party_identifier.dart'; + class AuthenticationIdentifier { String type; @@ -29,6 +34,19 @@ class AuthenticationIdentifier { AuthenticationIdentifier.fromJson(Map json) : type = json['type']; + factory AuthenticationIdentifier.subFromJson(Map json) { + switch (json['type']) { + case AuthenticationIdentifierTypes.userId: + return AuthenticationUserIdentifier.fromJson(json); + case AuthenticationIdentifierTypes.phone: + return AuthenticationPhoneIdentifier.fromJson(json); + case AuthenticationIdentifierTypes.thirdParty: + return AuthenticationThirdPartyIdentifier.fromJson(json); + default: + return AuthenticationIdentifier.fromJson(json); + } + } + Map toJson() { final data = {}; data['type'] = type; diff --git a/lib/src/model/auth/authentication_password.dart b/lib/src/model/auth/authentication_password.dart index 77ed95d4..f727c6c0 100644 --- a/lib/src/model/auth/authentication_password.dart +++ b/lib/src/model/auth/authentication_password.dart @@ -25,8 +25,6 @@ import 'authentication_user_identifier.dart'; import 'authentication_data.dart'; import 'authentication_identifier.dart'; -import 'authentication_phone_identifier.dart'; -import 'authentication_third_party_identifier.dart'; import 'authentication_types.dart'; class AuthenticationPassword extends AuthenticationData { @@ -47,21 +45,8 @@ class AuthenticationPassword extends AuthenticationData { AuthenticationPassword.fromJson(Map json) : user = json['user'], password = json['password'], - identifier = AuthenticationIdentifier.fromJson(json['identifier']), - super.fromJson(json) { - switch (identifier.type) { - case AuthenticationIdentifierTypes.userId: - identifier = AuthenticationUserIdentifier.fromJson(json['identifier']); - break; - case AuthenticationIdentifierTypes.phone: - identifier = AuthenticationPhoneIdentifier.fromJson(json['identifier']); - break; - case AuthenticationIdentifierTypes.thirdParty: - identifier = - AuthenticationThirdPartyIdentifier.fromJson(json['identifier']); - break; - } - } + identifier = AuthenticationIdentifier.subFromJson(json['identifier']), + super.fromJson(json); @override Map toJson() {