From 6a0795180b3c5f367b0e78620f6a528b2af33222 Mon Sep 17 00:00:00 2001
From: Sergey Dmitriev <51058739+0niel@users.noreply.github.com>
Date: Wed, 15 Feb 2023 22:41:30 +0300
Subject: [PATCH] feature: Create NFC-Pass Device Connect (#279)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* Add deferredLoading
* feature: Create NFC-Pass Device Connect
* feat: Create Nfc Fetcher and refactor auth bloc
* Удалён AuthBloc. Его функции перенесены в Profile Bloc
* Теперь в события не передаются токены доступа к апи. Управление токенами делегируется на репозиторий/remote data-source или отдельные пакеты для управления сетевыми запросами
* Создан `fetchNfcCode` event для получения кода пропуск
* feat: Add NFC fetching and errors feedback
* Update AndroidManifest.xml
---
android/app/src/main/AndroidManifest.xml | 1 +
android/build.gradle | 4 +-
.../gradle/wrapper/gradle-wrapper.properties | 2 +-
lib/common/errors/exceptions.dart | 4 +
lib/common/errors/failures.dart | 4 +
lib/data/datasources/user_local.dart | 40 +-
lib/data/datasources/user_remote.dart | 182 +-
lib/data/models/nfc_pass_model.dart | 33 +
lib/data/models/user_model.dart | 15 +-
.../repositories/user_repository_impl.dart | 113 +-
lib/domain/entities/nfc_pass.dart | 20 +
lib/domain/entities/user.dart | 6 +
lib/domain/repositories/user_repository.dart | 31 +-
lib/domain/usecases/connect_nfc_pass.dart | 30 +
lib/domain/usecases/fetch_nfc_code.dart | 34 +
lib/domain/usecases/get_announces.dart | 16 +-
lib/domain/usecases/get_attendance.dart | 7 +-
lib/domain/usecases/get_employees.dart | 7 +-
lib/domain/usecases/get_nfc_passes.dart | 29 +
lib/domain/usecases/get_scores.dart | 16 +-
lib/domain/usecases/get_user_data.dart | 15 +-
lib/domain/usecases/log_in.dart | 17 +-
.../usecases/send_nfc_not_exist_feedback.dart | 31 +
lib/main.dart | 33 +-
.../bloc/announces_bloc/announces_bloc.dart | 2 +-
.../bloc/announces_bloc/announces_event.dart | 8 +-
.../bloc/attendance_bloc/attendance_bloc.dart | 2 +-
.../attendance_bloc/attendance_event.dart | 4 +-
.../bloc/auth_bloc/auth_bloc.dart | 65 -
.../bloc/auth_bloc/auth_event.dart | 22 -
.../bloc/auth_bloc/auth_state.dart | 30 -
.../bloc/employee_bloc/employee_bloc.dart | 3 +-
.../bloc/employee_bloc/employee_event.dart | 5 +-
.../nfc_feedback_bloc/nfc_feedback_bloc.dart | 35 +
.../nfc_feedback_bloc.freezed.dart | 922 ++++++++
.../nfc_feedback_bloc/nfc_feedback_event.dart | 12 +
.../nfc_feedback_bloc/nfc_feedback_state.dart | 9 +
.../bloc/nfc_pass_bloc/nfc_pass_bloc.dart | 169 ++
.../nfc_pass_bloc/nfc_pass_bloc.freezed.dart | 1865 +++++++++++++++++
.../bloc/nfc_pass_bloc/nfc_pass_event.dart | 19 +
.../bloc/nfc_pass_bloc/nfc_pass_state.dart | 15 +
.../bloc/profile_bloc/profile_bloc.dart | 28 -
.../bloc/profile_bloc/profile_event.dart | 14 -
.../bloc/profile_bloc/profile_state.dart | 21 -
.../bloc/scores_bloc/scores_bloc.dart | 2 +-
.../bloc/scores_bloc/scores_event.dart | 8 +-
.../bloc/user_bloc/user_bloc.dart | 100 +
.../bloc/user_bloc/user_bloc.freezed.dart | 1125 ++++++++++
.../bloc/user_bloc/user_event.dart | 9 +
.../bloc/user_bloc/user_state.dart | 9 +
lib/presentation/core/routes/routes.dart | 5 +
lib/presentation/core/routes/routes.gr.dart | 203 +-
lib/presentation/pages/login/login_page.dart | 42 +-
lib/presentation/pages/map/map_page.dart | 1 -
.../profile/profile_attendance_page.dart | 19 +-
.../pages/profile/profile_lectors_page.dart | 21 +-
.../pages/profile/profile_nfc_pass_page.dart | 695 ++++++
.../pages/profile/profile_page.dart | 299 ++-
.../pages/profile/profile_scores_page.dart | 20 +-
lib/service_locator.dart | 52 +-
pubspec.yaml | 24 +-
61 files changed, 5921 insertions(+), 653 deletions(-)
create mode 100644 lib/data/models/nfc_pass_model.dart
create mode 100644 lib/domain/entities/nfc_pass.dart
create mode 100644 lib/domain/usecases/connect_nfc_pass.dart
create mode 100644 lib/domain/usecases/fetch_nfc_code.dart
create mode 100644 lib/domain/usecases/get_nfc_passes.dart
create mode 100644 lib/domain/usecases/send_nfc_not_exist_feedback.dart
delete mode 100644 lib/presentation/bloc/auth_bloc/auth_bloc.dart
delete mode 100644 lib/presentation/bloc/auth_bloc/auth_event.dart
delete mode 100644 lib/presentation/bloc/auth_bloc/auth_state.dart
create mode 100644 lib/presentation/bloc/nfc_feedback_bloc/nfc_feedback_bloc.dart
create mode 100644 lib/presentation/bloc/nfc_feedback_bloc/nfc_feedback_bloc.freezed.dart
create mode 100644 lib/presentation/bloc/nfc_feedback_bloc/nfc_feedback_event.dart
create mode 100644 lib/presentation/bloc/nfc_feedback_bloc/nfc_feedback_state.dart
create mode 100644 lib/presentation/bloc/nfc_pass_bloc/nfc_pass_bloc.dart
create mode 100644 lib/presentation/bloc/nfc_pass_bloc/nfc_pass_bloc.freezed.dart
create mode 100644 lib/presentation/bloc/nfc_pass_bloc/nfc_pass_event.dart
create mode 100644 lib/presentation/bloc/nfc_pass_bloc/nfc_pass_state.dart
delete mode 100644 lib/presentation/bloc/profile_bloc/profile_bloc.dart
delete mode 100644 lib/presentation/bloc/profile_bloc/profile_event.dart
delete mode 100644 lib/presentation/bloc/profile_bloc/profile_state.dart
create mode 100644 lib/presentation/bloc/user_bloc/user_bloc.dart
create mode 100644 lib/presentation/bloc/user_bloc/user_bloc.freezed.dart
create mode 100644 lib/presentation/bloc/user_bloc/user_event.dart
create mode 100644 lib/presentation/bloc/user_bloc/user_state.dart
create mode 100644 lib/presentation/pages/profile/profile_nfc_pass_page.dart
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 3aaa4d79..e0f4381a 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -3,6 +3,7 @@
package="ninja.mirea.mireaapp">
+
setTokenToCache(String token);
Future getTokenFromCache();
Future removeTokenFromCache();
+
+ Future getNfcCodeFromCache();
+ Future setNfcCodeToCache(int code);
+ Future removeNfcCodeFromCache();
}
class UserLocalDataImpl implements UserLocalData {
final SharedPreferences sharedPreferences;
+ final FlutterSecureStorage secureStorage;
- UserLocalDataImpl({required this.sharedPreferences});
+ UserLocalDataImpl({
+ required this.sharedPreferences,
+ required this.secureStorage,
+ });
@override
Future setTokenToCache(String token) {
- return sharedPreferences.setString('auth_token', token);
+ return secureStorage.write(key: 'lks_access_token', value: token);
}
@override
- Future getTokenFromCache() {
- String? token = sharedPreferences.getString('auth_token');
+ Future getTokenFromCache() async {
+ String? token = await secureStorage.read(key: 'lks_access_token');
if (token == null) throw CacheException('Auth token are not set');
return Future.value(token);
}
@override
Future removeTokenFromCache() {
- return sharedPreferences.remove('auth_token');
+ return secureStorage.delete(key: 'lks_access_token');
+ }
+
+ @override
+ Future getNfcCodeFromCache() async {
+ String? value = await secureStorage.read(key: 'nfc_code');
+
+ if (value == null) throw CacheException('NFC code are not set');
+
+ return Future.value(int.parse(value));
+ }
+
+ @override
+ Future setNfcCodeToCache(int code) async {
+ await secureStorage.write(key: 'nfc_code', value: code.toString());
+ }
+
+ @override
+ Future removeNfcCodeFromCache() async {
+ await secureStorage.delete(key: 'nfc_code');
}
}
diff --git a/lib/data/datasources/user_remote.dart b/lib/data/datasources/user_remote.dart
index 0539bcb9..0c984f19 100644
--- a/lib/data/datasources/user_remote.dart
+++ b/lib/data/datasources/user_remote.dart
@@ -6,22 +6,29 @@ import 'package:rtu_mirea_app/common/oauth.dart';
import 'package:rtu_mirea_app/data/models/announce_model.dart';
import 'package:rtu_mirea_app/data/models/attendance_model.dart';
import 'package:rtu_mirea_app/data/models/employee_model.dart';
+import 'package:rtu_mirea_app/data/models/nfc_pass_model.dart';
import 'package:rtu_mirea_app/data/models/score_model.dart';
import 'package:rtu_mirea_app/data/models/user_model.dart';
abstract class UserRemoteData {
Future auth();
Future logOut();
- Future getProfileData(String token);
- Future> getAnnounces(String token);
- Future> getEmployees(String token, String name);
- Future> getAttendance(
- String token, String dateStart, String dateEnd);
- Future