refactor(auth): rename local to cache auth data source

This commit is contained in:
Hugo Pointcheval 2022-11-10 13:31:00 -05:00
parent c0a91d6437
commit b2a9dac7c6
Signed by: hugo
GPG Key ID: A9E8E9615379254F
5 changed files with 29 additions and 38 deletions

View File

@ -1,19 +1,21 @@
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
export 'constants/form_field.dart';
export 'constants/form_name.dart';
export 'enums/enums.dart';
export 'exceptions/exceptions.dart';
export 'utils/utils.dart';

View File

@ -15,29 +15,28 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:wyatt_architecture/wyatt_architecture.dart';
import 'package:wyatt_authentication_bloc/src/domain/data_sources/local/authentication_local_data_source.dart';
import 'package:wyatt_authentication_bloc/src/domain/entities/account.dart';
import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
import 'package:wyatt_type_utils/wyatt_type_utils.dart';
class AuthenticationCacheDataSourceImpl<T extends Object>
extends AuthenticationLocalDataSource<T> {
extends AuthenticationCacheDataSource<T> {
Account? _account;
T? _data;
AuthenticationCacheDataSourceImpl();
@override
void storeAccount(Account? account) {
Future<void> storeAccount(Account? account) async {
_account = account;
}
@override
void storeData(T? data) {
Future<void> storeData(T? data) async {
_data = data;
}
@override
Account loadAccount() {
Future<Account> loadAccount() async {
if (_account.isNotNull) {
return _account!;
}
@ -45,7 +44,7 @@ class AuthenticationCacheDataSourceImpl<T extends Object>
}
@override
T loadData() {
Future<T> loadData() async {
if (_data.isNotNull) {
return _data!;
}
@ -53,8 +52,16 @@ class AuthenticationCacheDataSourceImpl<T extends Object>
}
@override
void destroy() {
Future<void> destroy() async {
_data = null;
_account = null;
}
@override
Future<AccountWrapper<T>> load() async {
if (_account.isNull) {
throw ClientException('Cached account is invalid');
}
return AccountWrapperModel(_account, _data);
}
}

View File

@ -14,6 +14,5 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
export 'local/authentication_biometrics_data_source.dart';
export 'local/authentication_local_data_source.dart';
export 'local/authentication_cache_data_source.dart';
export 'remote/authentication_remote_data_source.dart';

View File

@ -1,19 +0,0 @@
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:wyatt_architecture/wyatt_architecture.dart';
abstract class AuthenticationBiometricsDataSource extends BaseLocalDataSource {}

View File

@ -16,12 +16,14 @@
import 'package:wyatt_architecture/wyatt_architecture.dart';
import 'package:wyatt_authentication_bloc/src/domain/entities/account.dart';
import 'package:wyatt_authentication_bloc/src/domain/entities/account_wrapper.dart';
abstract class AuthenticationLocalDataSource<T extends Object>
abstract class AuthenticationCacheDataSource<T extends Object>
extends BaseLocalDataSource {
void storeAccount(Account? account);
void storeData(T? data);
Account loadAccount();
T loadData();
void destroy();
Future<void> storeAccount(Account? account);
Future<void> storeData(T? data);
Future<Account> loadAccount();
Future<T> loadData();
Future<AccountWrapper<T>> load();
Future<void> destroy();
}