From eb83043b504f7050f439027b78c3401ddfe3a8e4 Mon Sep 17 00:00:00 2001 From: Mikolaj Date: Mon, 6 Jan 2025 20:40:15 +0100 Subject: [PATCH] Fix review changes --- .../lib/core/cubits/auth/auth_cubit.dart | 19 +++++++++---------- .../demo/no_op_document_reference.dart | 14 +++----------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/recipients_app/lib/core/cubits/auth/auth_cubit.dart b/recipients_app/lib/core/cubits/auth/auth_cubit.dart index 553f90bf4..7fe1d6acb 100644 --- a/recipients_app/lib/core/cubits/auth/auth_cubit.dart +++ b/recipients_app/lib/core/cubits/auth/auth_cubit.dart @@ -23,11 +23,7 @@ class AuthCubit extends Cubit { if (user != null) { try { final recipient = await userRepository.fetchRecipient(user); - Organization? organization; - - if (recipient?.organizationRef != null) { - organization = await organizationRepository.fetchOrganization(recipient!.organizationRef!); - } + final Organization? organization = await _fetchOrganization(recipient); emit( AuthState( @@ -62,11 +58,7 @@ class AuthCubit extends Cubit { if (user != null) { final recipient = await userRepository.fetchRecipient(user); - Organization? organization; - - if (recipient?.organizationRef != null) { - organization = await organizationRepository.fetchOrganization(recipient!.organizationRef!); - } + final Organization? organization = await _fetchOrganization(recipient); emit( AuthState( @@ -109,4 +101,11 @@ class AuthCubit extends Cubit { await userRepository.signOut(); emit(const AuthState()); } + + Future _fetchOrganization(Recipient? recipient) async { + if (recipient?.organizationRef != null) { + return await organizationRepository.fetchOrganization(recipient!.organizationRef!); + } + return null; + } } diff --git a/recipients_app/lib/data/datasource/demo/no_op_document_reference.dart b/recipients_app/lib/data/datasource/demo/no_op_document_reference.dart index 9e3548e92..8006c327c 100644 --- a/recipients_app/lib/data/datasource/demo/no_op_document_reference.dart +++ b/recipients_app/lib/data/datasource/demo/no_op_document_reference.dart @@ -1,66 +1,58 @@ import "package:cloud_firestore/cloud_firestore.dart"; +// We are using DocumentReference in repository / data source. That's why we need to get +// no-op implementation for it for demo data source. + // ignore: subtype_of_sealed_class class NoOpDocumentReference implements DocumentReference> { const NoOpDocumentReference(); @override CollectionReference> collection(String collectionPath) { - // TODO: implement collection throw UnimplementedError(); } @override Future delete() { - // TODO: implement delete throw UnimplementedError(); } @override - // TODO: implement firestore FirebaseFirestore get firestore => throw UnimplementedError(); @override Future>> get([GetOptions? options]) { - // TODO: implement get throw UnimplementedError(); } @override - // TODO: implement id String get id => throw UnimplementedError(); @override - // TODO: implement parent CollectionReference> get parent => throw UnimplementedError(); @override - // TODO: implement path String get path => throw UnimplementedError(); @override Future set(Map data, [SetOptions? options]) { - // TODO: implement set throw UnimplementedError(); } @override Stream>> snapshots( {bool includeMetadataChanges = false, ListenSource source = ListenSource.defaultSource,}) { - // TODO: implement snapshots throw UnimplementedError(); } @override Future update(Map data) { - // TODO: implement update throw UnimplementedError(); } @override DocumentReference withConverter( {required FromFirestore fromFirestore, required ToFirestore toFirestore,}) { - // TODO: implement withConverter throw UnimplementedError(); } }