Skip to content

Commit

Permalink
Merge pull request #15 from a-givertzman/issue_14
Browse files Browse the repository at this point in the history
notice list (#14 )
Тикет закрыт, весь функционал реализован
Статус групповых сообщений вынесен в отдельный тикет #16
  • Loading branch information
a-givertzman authored Feb 9, 2022
2 parents bc76dc4 + 9ac828c commit 0e8c27c
Show file tree
Hide file tree
Showing 34 changed files with 1,241 additions and 205 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences_ios","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/shared_preferences_ios-2.0.8/","native_build":true,"dependencies":[]}],"android":[{"name":"shared_preferences_android","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/shared_preferences_android-2.0.9/","native_build":true,"dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-2.0.2/","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.1.4/","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-2.0.3/","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.0.4/","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/shared_preferences_windows-2.0.3/","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"shared_preferences_web","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-2.0.2/","dependencies":[]}]},"dependencyGraph":[{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2022-01-20 22:51:44.455668","version":"2.9.0-1.0.pre.414"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences_ios","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/shared_preferences_ios-2.0.8/","native_build":true,"dependencies":[]}],"android":[{"name":"shared_preferences_android","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/shared_preferences_android-2.0.9/","native_build":true,"dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-2.0.2/","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.1.4/","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-2.0.3/","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.0.4/","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/shared_preferences_windows-2.0.3/","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"shared_preferences_web","path":"/Users/antonlobanov/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-2.0.2/","dependencies":[]}]},"dependencyGraph":[{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2022-02-09 16:25:47.691942","version":"2.11.0-0.0.pre.493"}
1 change: 1 addition & 0 deletions lib/assets/texts/app_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ class AppText {
static const settingsPage = 'Настройки';
static const userLogout = 'Выйти их профиля';
static const purchases = 'Закупки';
static const noNotines = 'Сообщений нет';
}
10 changes: 5 additions & 5 deletions lib/dev/log/log.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// ignore_for_file: avoid_print

void log(Object? m1, [Object? m2, Object? m3, Object? m4]) {
final String s1 = m1 != null ? m1.toString() : '';
final String s2 = m2 != null ? m2.toString() : '';
final String s3 = m3 != null ? m3.toString() : '';
final String s4 = m4 != null ? m4.toString() : '';
void log(Object? message1, [Object? message2, Object? message3, Object? message4]) {
final String s1 = message1 != null ? message1.toString() : '';
final String s2 = message2 != null ? message2.toString() : '';
final String s3 = message3 != null ? message3.toString() : '';
final String s4 = message4 != null ? message4.toString() : '';
assert(
() {
try {
Expand Down
6 changes: 4 additions & 2 deletions lib/domain/auth/app_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class AppUser extends DataObject {
super(remote: remote) {
_init();
}
AppUser empty() {
/// Метод возвращает новый экземпляр класса
/// с прежним remote, но без данных
AppUser clear() {
return AppUser(remote: _remote);
}
void _init() {
Expand Down Expand Up @@ -48,7 +50,7 @@ class AppUser extends DataObject {
}
}
@override
Future<AppUser> fetch({Map params = const {}}) {
Future<AppUser> fetch({Map<String, dynamic> params = const {}}) {
// TODO: implement fetch
return super
.fetch(params: params)
Expand Down
8 changes: 4 additions & 4 deletions lib/domain/auth/authenticate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import 'package:flowers_app/domain/core/local_store/local_store.dart';

class Authenticate {
final _storeKey = 'spwd';
final LocalStore _localStore;
// final FirebaseAuth _firebaseAuth;
AppUser _user;
Authenticate({
required LocalStore localStore,
required AppUser user,
// required FirebaseAuth firebaseAuth,
}) :
_localStore = localStore,
_user = user;
// _firebaseAuth = firebaseAuth;
AppUser getUser() {
Expand All @@ -24,6 +21,7 @@ class Authenticate {
return _user.exists();
}
Future<AuthResult> authenticateIfStored() async {
final _localStore = LocalStore();
final phoneNumber = await _localStore.readString(_storeKey);
if (phoneNumber != '') {
return authenticateByPhoneNumber(phoneNumber);
Expand All @@ -41,6 +39,7 @@ class Authenticate {
},).then((user) {
log('[Authenticate.authenticateByPhoneNumber] user: $user');
if (user.exists()) {
final _localStore = LocalStore();
_localStore.writeString(_storeKey, phoneNumber);
return AuthResult(
authenticated: true,
Expand All @@ -64,8 +63,9 @@ class Authenticate {
});
}
Future<AuthResult> logout() async {
final _localStore = LocalStore();
await _localStore.remove(_storeKey);
_user = _user.empty();
_user = _user.clear();
// _firebaseAuth.signOut();
return AuthResult(
authenticated: false,
Expand Down
77 changes: 42 additions & 35 deletions lib/domain/core/entities/data_collection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:async';
import 'package:flowers_app/dev/log/log.dart';
import 'package:flowers_app/domain/core/entities/data_object.dart';
import 'package:flowers_app/domain/core/errors/failure.dart';
import 'package:flowers_app/infrastructure/api/response.dart';
import 'package:flowers_app/infrastructure/datasource/data_set.dart';

/// Класс реализует список загрузку списка элементов
Expand All @@ -13,7 +14,6 @@ import 'package:flowers_app/infrastructure/datasource/data_set.dart';
/// при вызове метода fetch будет читать записи из источника
/// и формировать из каждой записи экземпляр класса PurchaseProduct
class DataCollection<T> {
// final String id;
final DataSet<Map<String, dynamic>> remote;
final _streamController = StreamController<List<T>>();
final DataObject Function(Map<String, dynamic>) dataMaper;
Expand All @@ -24,24 +24,23 @@ class DataCollection<T> {
}

DataCollection({
// required this.id,
required this.remote,
required this.dataMaper,
});

Future refresh() async {
_dispatch();
Future<void> refresh() {
return _dispatch();
}

void _dispatch() {
Future<void> _dispatch() {
log('[$runtimeType($DataCollection)._dispatch]');
// _streamController.sink.add(List.empty());
fetch()
return fetch()
.then(
(data) {
final List<T> _data = [];
for (final element in data as List) {
_data.add(element as T);
for (final element in data) {
_data.add(element);
}
_streamController.sink.add(_data);
}
Expand All @@ -51,35 +50,43 @@ class DataCollection<T> {
_streamController.addError(e as Object);
});
}
Future<dynamic> fetch() async {
Future<List<T>> fetchWith({required Map<String, dynamic> params}) {
log('[$runtimeType($DataCollection).fetchWith]');
return remote
.fetchWith(params: params)
.then((response) => _fetchOnSuccess(response))
.onError((error, stackTrace) => _fetchOnFailure(error, stackTrace));
}
Future<List<T>> fetch() {
log('[$runtimeType($DataCollection).fetch]');
return remote
.fetch()
.then(
(response) {
if (response.hasError()) {
return Failure(
message: response.errorMessage(),
stackTrace: StackTrace.empty,
);
}
final sqlList = response.data();
final List<dynamic> list = [];
sqlList.forEach((key, row) {
final p = dataMaper(row as Map<String, dynamic>);
list.add(p);
});
// for (final row in sqlList) {
// final p = dataMaper(row);
// list.add(p);
// }
return list;
}
).onError((error, stackTrace) {
throw Failure.dataCollection(
message: 'Ошибка в методе fetch класса $runtimeType($DataCollection):\n$error',
stackTrace: stackTrace,
);
});
.then((response) => _fetchOnSuccess(response))
.onError((error, stackTrace) => _fetchOnFailure(error, stackTrace));
}
List<T> _fetchOnSuccess(Response<Map<String, dynamic>> response) {
if (response.hasError()) {
throw Failure(
message: response.errorMessage(),
stackTrace: StackTrace.empty,
);
}
final sqlList = response.data();
final List<T> list = [];
sqlList.forEach((key, row) {
final p = dataMaper(row as Map<String, dynamic>) as T;
list.add(p);
});
// for (final row in sqlList) {
// final p = dataMaper(row);
// list.add(p);
// }
return list;
}
Future<List<T>> _fetchOnFailure(Object? error, StackTrace stackTrace) {
throw Failure.dataCollection(
message: 'Ошибка в методе fetchWith класса $runtimeType($DataCollection):\n$error',
stackTrace: stackTrace,
);
}
}
23 changes: 19 additions & 4 deletions lib/domain/core/entities/data_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@ abstract class IDataObject {
class DataObject implements IDataObject {
final Map<String, ValueObject> _map = {};
final DataSet _remote;
late bool isEmpty;
bool _valid = true;

DataObject({
required DataSet remote,
}): _remote = remote;
}):
_remote = remote,
isEmpty = false;
/// Конструктор возвращает екземпляр класса
/// с пустым remote и без данных
/// Поле empty = true
DataObject.empty():
_remote = DataSet.empty(),
isEmpty = true;
Map<String, ValueObject> asMap() => _map;
@override
DataSet get remote => _remote;
Expand Down Expand Up @@ -48,7 +56,7 @@ class DataObject implements IDataObject {
_map[key] = value;
}
@override
Future<DataObject> fetch({Map params = const {}}) async {
Future<DataObject> fetch({Map<String, dynamic> params = const {}}) async {
return _remote
.fetchWith(params: params)
.then(
Expand All @@ -73,7 +81,6 @@ class DataObject implements IDataObject {
/// или успешно проинициализированн методом fromRow
@override
bool valid() {
// TODO: implement valid
return _valid;
}
@override
Expand All @@ -94,4 +101,12 @@ class DataObject implements IDataObject {
}
return this;
}
@override
String toString() {
String str = '$runtimeType($DataObject) {\n\t';
_map.forEach((key, value) {
str += '\n\t$key: $value,';
});
return '$str}';
}
}
31 changes: 26 additions & 5 deletions lib/domain/core/local_store/local_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,53 @@ class LocalStore {
(prefs) => prefs,
);
}
Future<String> readString(String key) {
Future<String> readRawString(String key) {
return _getPrefs().then((prefs) {
final value = prefs.getString(key) ?? '';
log('[LocalStore.readRawString] key: $key;\tvalue: $value');
return value;
});
}
Future<bool> writeRawString(String key, String value) {
return _getPrefs().then((prefs) {
return prefs.setString(key, value).then((value) {
log('[LocalStore.writeRawString] key: $key;\tvalue: $value');
return value;
});
});
} Future<String> readString(String key) {
return _getPrefs().then((prefs) {
final value = prefs.getString(key) ?? '';
log('[LocalStore.readString] key: $key;\tvalue: $value');
return decodeStr(value);
});
}
Future<bool> writeString(String key, String value) {
return _getPrefs().then((prefs) {
return prefs.setString(key, encodeStr(value));
return prefs.setString(key, encodeStr(value)).then((value) {
log('[LocalStore.writeString] key: $key;\tvalue: $value');
return value;
});
});
}
Future<bool> remove(String key) {
return _getPrefs().then((prefs) {
return prefs.remove(key);
return prefs.remove(key).then((value) {
log('[LocalStore.remove] deleted key: $key');
return value;
});
});
}
String encodeStr(String value) {
final bytes = utf8.encode(value);
final base64Str = base64.encode(bytes);
log('[encodeStr] base64Str: $base64Str');
log('[LocalStore.encodeStr] str: $value to $base64Str');
return base64Str;
}
String decodeStr(String value) {
final b64 = base64.decode(value);
final str = utf8.decode(b64);
log('[decodeStr] str: $str');
log('[LocalStore.decodeStr] value: $value to $str');
return str;
}
}
Loading

0 comments on commit 0e8c27c

Please sign in to comment.