From 6509247fbda4fcab4b78f5b85c9d5f105167aa88 Mon Sep 17 00:00:00 2001 From: MikeWallaceDev Date: Mon, 28 Feb 2022 21:02:46 -0500 Subject: [PATCH 1/9] refactor: put document business logic into service --- .../lib/workspace/application/doc/doc_bloc.dart | 12 ++++++------ .../doc/doc_service.dart} | 13 ++++--------- .../lib/workspace/infrastructure/deps_resolver.dart | 4 ++-- 3 files changed, 12 insertions(+), 17 deletions(-) rename frontend/app_flowy/lib/workspace/{infrastructure/repos/document_repo.dart => application/doc/doc_service.dart} (74%) diff --git a/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart b/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart index 538c7b42b3..56ad3378b5 100644 --- a/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart @@ -1,5 +1,5 @@ import 'dart:convert'; -import 'package:app_flowy/workspace/infrastructure/repos/document_repo.dart'; +import 'package:app_flowy/workspace/application/doc/doc_service.dart'; import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; @@ -17,7 +17,7 @@ typedef FlutterQuillDocument = Document; class DocumentBloc extends Bloc { final View view; - final DocumentRepository repo; + final DocumentService service; final ViewListener listener; final TrashRepo trashRepo; late FlutterQuillDocument document; @@ -25,7 +25,7 @@ class DocumentBloc extends Bloc { DocumentBloc({ required this.view, - required this.repo, + required this.service, required this.listener, required this.trashRepo, }) : super(DocumentState.initial()) { @@ -62,7 +62,7 @@ class DocumentBloc extends Bloc { await _subscription?.cancel(); } - repo.closeDocument(); + service.closeDocument(docId: view.id); return super.close(); } @@ -82,7 +82,7 @@ class DocumentBloc extends Bloc { }); listener.start(); - final result = await repo.openDocument(); + final result = await service.openDocument(docId: view.id); result.fold( (doc) { document = _decodeJsonToDocument(doc.deltaJson); @@ -108,7 +108,7 @@ class DocumentBloc extends Bloc { void _composeDelta(Delta composedDelta, Delta documentDelta) async { final json = jsonEncode(composedDelta.toJson()); Log.debug("doc_id: $view.id - Send json: $json"); - final result = await repo.composeDelta(data: json); + final result = await service.composeDelta(docId: view.id, data: json); result.fold((rustDoc) { // final json = utf8.decode(doc.data); diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/document_repo.dart b/frontend/app_flowy/lib/workspace/application/doc/doc_service.dart similarity index 74% rename from frontend/app_flowy/lib/workspace/infrastructure/repos/document_repo.dart rename to frontend/app_flowy/lib/workspace/application/doc/doc_service.dart index 61fefab94a..975f4f7ce6 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/document_repo.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/doc_service.dart @@ -4,25 +4,20 @@ import 'package:flowy_sdk/protobuf/flowy-collaboration/document_info.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -class DocumentRepository { - final String docId; - DocumentRepository({ - required this.docId, - }); - - Future> openDocument() { +class DocumentService { + Future> openDocument({required String docId}) { final request = ViewId(value: docId); return FolderEventOpenView(request).send(); } - Future> composeDelta({required String data}) { + Future> composeDelta({required String docId, required String data}) { final request = DocumentDelta.create() ..docId = docId ..deltaJson = data; return FolderEventApplyDocDelta(request).send(); } - Future> closeDocument() { + Future> closeDocument({required String docId}) { final request = ViewId(value: docId); return FolderEventCloseView(request).send(); } diff --git a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart index 43502772af..15ef0a2733 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart @@ -1,5 +1,6 @@ import 'package:app_flowy/workspace/application/app/app_bloc.dart'; import 'package:app_flowy/workspace/application/doc/doc_bloc.dart'; +import 'package:app_flowy/workspace/application/doc/doc_service.dart'; import 'package:app_flowy/workspace/application/doc/share_bloc.dart'; import 'package:app_flowy/workspace/application/home/home_listen_bloc.dart'; import 'package:app_flowy/workspace/application/menu/menu_bloc.dart'; @@ -9,7 +10,6 @@ import 'package:app_flowy/workspace/application/view/view_bloc.dart'; import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/document_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; @@ -83,7 +83,7 @@ class HomeDepsResolver { getIt.registerFactoryParam( (view, _) => DocumentBloc( view: view, - repo: DocumentRepository(docId: view.id), + service: DocumentService(), listener: getIt(param1: view), trashRepo: getIt(), ), From 95d33c75a5732d2d0c19b7321a3392bcf1e74d69 Mon Sep 17 00:00:00 2001 From: MikeWallaceDev Date: Mon, 28 Feb 2022 21:17:08 -0500 Subject: [PATCH 2/9] refactor: Put Trash business logic in service --- .../workspace/application/doc/doc_bloc.dart | 11 +++--- .../application/trash/trash_bloc.dart | 17 +++++---- .../trash/trash_listener.dart} | 36 +----------------- .../application/trash/trash_service.dart | 37 +++++++++++++++++++ .../infrastructure/deps_resolver.dart | 9 +++-- 5 files changed, 59 insertions(+), 51 deletions(-) rename frontend/app_flowy/lib/workspace/{infrastructure/repos/trash_repo.dart => application/trash/trash_listener.dart} (64%) create mode 100644 frontend/app_flowy/lib/workspace/application/trash/trash_service.dart diff --git a/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart b/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart index 56ad3378b5..c8f51c6256 100644 --- a/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart @@ -1,6 +1,6 @@ import 'dart:convert'; import 'package:app_flowy/workspace/application/doc/doc_service.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart'; +import 'package:app_flowy/workspace/application/trash/trash_service.dart'; import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; @@ -11,6 +11,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:dartz/dartz.dart'; import 'dart:async'; + part 'doc_bloc.freezed.dart'; typedef FlutterQuillDocument = Document; @@ -19,7 +20,7 @@ class DocumentBloc extends Bloc { final View view; final DocumentService service; final ViewListener listener; - final TrashRepo trashRepo; + final TrashService trashService; late FlutterQuillDocument document; StreamSubscription? _subscription; @@ -27,7 +28,7 @@ class DocumentBloc extends Bloc { required this.view, required this.service, required this.listener, - required this.trashRepo, + required this.trashService, }) : super(DocumentState.initial()) { on((event, emit) async { await event.map( @@ -41,12 +42,12 @@ class DocumentBloc extends Bloc { emit(state.copyWith(isDeleted: false)); }, deletePermanently: (DeletePermanently value) async { - final result = await trashRepo.deleteViews([Tuple2(view.id, TrashType.TrashView)]); + final result = await trashService.deleteViews([Tuple2(view.id, TrashType.TrashView)]); final newState = result.fold((l) => state.copyWith(forceClose: true), (r) => state); emit(newState); }, restorePage: (RestorePage value) async { - final result = await trashRepo.putback(view.id); + final result = await trashService.putback(view.id); final newState = result.fold((l) => state.copyWith(isDeleted: false), (r) => state); emit(newState); }, diff --git a/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart b/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart index 0829484de0..8bef2e41fd 100644 --- a/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart @@ -1,20 +1,21 @@ -import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:app_flowy/workspace/application/trash/trash_service.dart'; +import 'package:app_flowy/workspace/application/trash/trash_listener.dart'; part 'trash_bloc.freezed.dart'; class TrashBloc extends Bloc { - final TrashRepo repo; + final TrashService service; final TrashListener listener; - TrashBloc({required this.repo, required this.listener}) : super(TrashState.init()) { + TrashBloc({required this.service, required this.listener}) : super(TrashState.init()) { on((event, emit) async { await event.map(initial: (e) async { listener.startListening(trashUpdated: _listenTrashUpdated); - final result = await repo.readTrash(); + final result = await service.readTrash(); emit(result.fold( (object) => state.copyWith(objects: object.items, successOrFailure: left(unit)), (error) => state.copyWith(successOrFailure: right(error)), @@ -22,16 +23,16 @@ class TrashBloc extends Bloc { }, didReceiveTrash: (e) async { emit(state.copyWith(objects: e.trash)); }, putback: (e) async { - final result = await repo.putback(e.trashId); + final result = await service.putback(e.trashId); await _handleResult(result, emit); }, delete: (e) async { - final result = await repo.deleteViews([Tuple2(e.trash.id, e.trash.ty)]); + final result = await service.deleteViews([Tuple2(e.trash.id, e.trash.ty)]); await _handleResult(result, emit); }, deleteAll: (e) async { - final result = await repo.deleteAll(); + final result = await service.deleteAll(); await _handleResult(result, emit); }, restoreAll: (e) async { - final result = await repo.restoreAll(); + final result = await service.restoreAll(); await _handleResult(result, emit); }); }); diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart b/frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart similarity index 64% rename from frontend/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart rename to frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart index 3d2d3ee5ad..3d558d1b4e 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart +++ b/frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart @@ -1,45 +1,13 @@ import 'dart:async'; import 'dart:typed_data'; -import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; import 'package:flowy_sdk/rust_stream.dart'; -class TrashRepo { - Future> readTrash() { - return FolderEventReadTrash().send(); - } - - Future> putback(String trashId) { - final id = TrashId.create()..id = trashId; - - return FolderEventPutbackTrash(id).send(); - } - - Future> deleteViews(List> trashList) { - final items = trashList.map((trash) { - return TrashId.create() - ..id = trash.value1 - ..ty = trash.value2; - }); - - final ids = RepeatedTrashId(items: items); - return FolderEventDeleteTrash(ids).send(); - } - - Future> restoreAll() { - return FolderEventRestoreAllTrash().send(); - } - - Future> deleteAll() { - return FolderEventDeleteAllTrash().send(); - } -} - typedef TrashUpdatedCallback = void Function(Either, FlowyError> trashOrFailed); class TrashListener { diff --git a/frontend/app_flowy/lib/workspace/application/trash/trash_service.dart b/frontend/app_flowy/lib/workspace/application/trash/trash_service.dart new file mode 100644 index 0000000000..0e7149050a --- /dev/null +++ b/frontend/app_flowy/lib/workspace/application/trash/trash_service.dart @@ -0,0 +1,37 @@ +import 'dart:async'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; + +class TrashService { + Future> readTrash() { + return FolderEventReadTrash().send(); + } + + Future> putback(String trashId) { + final id = TrashId.create()..id = trashId; + + return FolderEventPutbackTrash(id).send(); + } + + Future> deleteViews(List> trashList) { + final items = trashList.map((trash) { + return TrashId.create() + ..id = trash.value1 + ..ty = trash.value2; + }); + + final ids = RepeatedTrashId(items: items); + return FolderEventDeleteTrash(ids).send(); + } + + Future> restoreAll() { + return FolderEventRestoreAllTrash().send(); + } + + Future> deleteAll() { + return FolderEventDeleteAllTrash().send(); + } +} + diff --git a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart index 15ef0a2733..1fa805d34a 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart @@ -6,11 +6,12 @@ import 'package:app_flowy/workspace/application/home/home_listen_bloc.dart'; import 'package:app_flowy/workspace/application/menu/menu_bloc.dart'; import 'package:app_flowy/workspace/application/menu/menu_user_bloc.dart'; import 'package:app_flowy/workspace/application/trash/trash_bloc.dart'; +import 'package:app_flowy/workspace/application/trash/trash_listener.dart'; +import 'package:app_flowy/workspace/application/trash/trash_service.dart'; import 'package:app_flowy/workspace/application/view/view_bloc.dart'; import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/workspace_repo.dart'; @@ -85,16 +86,16 @@ class HomeDepsResolver { view: view, service: DocumentService(), listener: getIt(param1: view), - trashRepo: getIt(), + trashService: getIt(), ), ); // trash - getIt.registerLazySingleton(() => TrashRepo()); + getIt.registerLazySingleton(() => TrashService()); getIt.registerLazySingleton(() => TrashListener()); getIt.registerFactory( () => TrashBloc( - repo: getIt(), + service: getIt(), listener: getIt(), ), ); From a979037644c5562bce3fc34f1aaff398dcd91083 Mon Sep 17 00:00:00 2001 From: MikeWallaceDev Date: Mon, 28 Feb 2022 21:42:46 -0500 Subject: [PATCH 3/9] refactor: put App business logic in a service. --- .../workspace/application/app/app_bloc.dart | 19 ++++--- .../app/app_listener.dart} | 57 +------------------ .../application/app/app_service.dart | 57 +++++++++++++++++++ .../infrastructure/deps_resolver.dart | 5 +- 4 files changed, 74 insertions(+), 64 deletions(-) rename frontend/app_flowy/lib/workspace/{infrastructure/repos/app_repo.dart => application/app/app_listener.dart} (61%) create mode 100644 frontend/app_flowy/lib/workspace/application/app/app_service.dart diff --git a/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart b/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart index ce5415d407..0c497e9302 100644 --- a/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart @@ -1,4 +1,5 @@ -import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart'; +import 'package:app_flowy/workspace/application/app/app_listener.dart'; +import 'package:app_flowy/workspace/application/app/app_service.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; @@ -10,9 +11,12 @@ import 'package:dartz/dartz.dart'; part 'app_bloc.freezed.dart'; class AppBloc extends Bloc { - final AppRepository repo; + final App app; + final AppService service; final AppListener listener; - AppBloc({required App app, required this.repo, required this.listener}) : super(AppState.initial(app)) { + + AppBloc({required this.app, required this.service, required this.listener}) + : super(AppState.initial(app)) { on((event, emit) async { await event.map(initial: (e) async { listener.startListening( @@ -21,7 +25,8 @@ class AppBloc extends Bloc { ); await _fetchViews(emit); }, createView: (CreateView value) async { - final viewOrFailed = await repo.createView(name: value.name, desc: value.desc, viewType: value.viewType); + final viewOrFailed = + await service.createView(appId: app.id, name: value.name, desc: value.desc, viewType: value.viewType); viewOrFailed.fold( (view) => emit(state.copyWith( latestCreatedView: view, @@ -35,13 +40,13 @@ class AppBloc extends Bloc { }, didReceiveViews: (e) async { await handleDidReceiveViews(e.views, emit); }, delete: (e) async { - final result = await repo.delete(); + final result = await service.delete(appId: app.id); result.fold( (unit) => emit(state.copyWith(successOrFailure: left(unit))), (error) => emit(state.copyWith(successOrFailure: right(error))), ); }, rename: (e) async { - final result = await repo.updateApp(name: e.newName); + final result = await service.updateApp(appId: app.id, name: e.newName); result.fold( (l) => emit(state.copyWith(successOrFailure: left(unit))), (error) => emit(state.copyWith(successOrFailure: right(error))), @@ -81,7 +86,7 @@ class AppBloc extends Bloc { } Future _fetchViews(Emitter emit) async { - final viewsOrFailed = await repo.getViews(); + final viewsOrFailed = await service.getViews(appId: app.id); viewsOrFailed.fold( (apps) => emit(state.copyWith(views: apps)), (error) { diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart b/frontend/app_flowy/lib/workspace/application/app/app_listener.dart similarity index 61% rename from frontend/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart rename to frontend/app_flowy/lib/workspace/application/app/app_listener.dart index 050cf834fb..b2970b931d 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart +++ b/frontend/app_flowy/lib/workspace/application/app/app_listener.dart @@ -1,67 +1,14 @@ import 'dart:async'; import 'dart:typed_data'; import 'package:dartz/dartz.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; import 'package:flowy_sdk/log.dart'; -import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; import 'package:flowy_sdk/rust_stream.dart'; -import 'helper.dart'; - -class AppRepository { - String appId; - AppRepository({ - required this.appId, - }); - - Future> getAppDesc() { - final request = AppId.create()..value = appId; - - return FolderEventReadApp(request).send(); - } - - Future> createView({ - required String name, - required String desc, - required ViewType viewType, - }) { - final request = CreateViewPayload.create() - ..belongToId = appId - ..name = name - ..desc = desc - ..viewType = viewType; - - return FolderEventCreateView(request).send(); - } - - Future, FlowyError>> getViews() { - final request = AppId.create()..value = appId; - - return FolderEventReadApp(request).send().then((result) { - return result.fold( - (app) => left(app.belongings.items), - (error) => right(error), - ); - }); - } - - Future> delete() { - final request = AppId.create()..value = appId; - return FolderEventDeleteApp(request).send(); - } - - Future> updateApp({String? name}) { - UpdateAppPayload request = UpdateAppPayload.create()..appId = appId; - - if (name != null) { - request.name = name; - } - return FolderEventUpdateApp(request).send(); - } -} typedef AppDidUpdateCallback = void Function(App app); typedef ViewsDidChangeCallback = void Function(Either, FlowyError> viewsOrFailed); diff --git a/frontend/app_flowy/lib/workspace/application/app/app_service.dart b/frontend/app_flowy/lib/workspace/application/app/app_service.dart new file mode 100644 index 0000000000..e97229fcd7 --- /dev/null +++ b/frontend/app_flowy/lib/workspace/application/app/app_service.dart @@ -0,0 +1,57 @@ +import 'dart:async'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; + +class AppService { + + Future> getAppDesc({required String appId}) { + final request = AppId.create()..value = appId; + + return FolderEventReadApp(request).send(); + } + + Future> createView({ + required String appId, + required String name, + required String desc, + required ViewType viewType, + }) { + final request = CreateViewPayload.create() + ..belongToId = appId + ..name = name + ..desc = desc + ..viewType = viewType; + + return FolderEventCreateView(request).send(); + } + + Future, FlowyError>> getViews({required String appId}) { + final request = AppId.create()..value = appId; + + return FolderEventReadApp(request).send().then((result) { + return result.fold( + (app) => left(app.belongings.items), + (error) => right(error), + ); + }); + } + + Future> delete({required String appId}) { + final request = AppId.create()..value = appId; + return FolderEventDeleteApp(request).send(); + } + + Future> updateApp({required String appId, String? name}) { + UpdateAppPayload request = UpdateAppPayload.create()..appId = appId; + + if (name != null) { + request.name = name; + } + return FolderEventUpdateApp(request).send(); + } +} + + diff --git a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart index 1fa805d34a..f35af8f95e 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart @@ -1,4 +1,6 @@ import 'package:app_flowy/workspace/application/app/app_bloc.dart'; +import 'package:app_flowy/workspace/application/app/app_listener.dart'; +import 'package:app_flowy/workspace/application/app/app_service.dart'; import 'package:app_flowy/workspace/application/doc/doc_bloc.dart'; import 'package:app_flowy/workspace/application/doc/doc_service.dart'; import 'package:app_flowy/workspace/application/doc/share_bloc.dart'; @@ -11,7 +13,6 @@ import 'package:app_flowy/workspace/application/trash/trash_service.dart'; import 'package:app_flowy/workspace/application/view/view_bloc.dart'; import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/workspace_repo.dart'; @@ -75,7 +76,7 @@ class HomeDepsResolver { getIt.registerFactoryParam( (app, _) => AppBloc( app: app, - repo: AppRepository(appId: app.id), + service: AppService(), listener: AppListener(appId: app.id), ), ); From 871d0bb7be8de64e9b24b860be3883e2142bd806 Mon Sep 17 00:00:00 2001 From: MikeWallaceDev Date: Mon, 28 Feb 2022 22:38:11 -0500 Subject: [PATCH 4/9] refactor: put Workspace business logic in a service --- .../workspace/application/menu/menu_bloc.dart | 13 ++-- .../workspace/workspace_listener.dart} | 78 ++++--------------- .../workspace/workspace_service.dart | 46 +++++++++++ .../infrastructure/deps_resolver.dart | 10 ++- 4 files changed, 75 insertions(+), 72 deletions(-) rename frontend/app_flowy/lib/workspace/{infrastructure/repos/workspace_repo.dart => application/workspace/workspace_listener.dart} (61%) create mode 100644 frontend/app_flowy/lib/workspace/application/workspace/workspace_service.dart diff --git a/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart b/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart index a601e99721..d00f3e7737 100644 --- a/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart @@ -1,6 +1,7 @@ import 'dart:async'; +import 'package:app_flowy/workspace/application/workspace/workspace_listener.dart'; +import 'package:app_flowy/workspace/application/workspace/workspace_service.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/workspace_repo.dart'; import 'package:app_flowy/workspace/presentation/stack_page/blank/blank_page.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/log.dart'; @@ -12,9 +13,11 @@ import 'package:flutter_bloc/flutter_bloc.dart'; part 'menu_bloc.freezed.dart'; class MenuBloc extends Bloc { - final WorkspaceRepo repo; + final WorkspaceService service; final WorkspaceListener listener; - MenuBloc({required this.repo, required this.listener}) : super(MenuState.initial()) { + final String workspaceId; + + MenuBloc({required this.workspaceId, required this.service, required this.listener}) : super(MenuState.initial()) { on((event, emit) async { await event.map( initial: (e) async { @@ -48,7 +51,7 @@ class MenuBloc extends Bloc { } Future _performActionOnCreateApp(CreateApp event, Emitter emit) async { - final result = await repo.createApp(event.name, event.desc ?? ""); + final result = await service.createApp(workspaceId: workspaceId, name: event.name, desc: event.desc ?? ""); result.fold( (app) => {}, (error) { @@ -60,7 +63,7 @@ class MenuBloc extends Bloc { // ignore: unused_element Future _fetchApps(Emitter emit) async { - final appsOrFail = await repo.getApps(); + final appsOrFail = await service.getApps(workspaceId: workspaceId); emit(appsOrFail.fold( (apps) => state.copyWith(apps: some(apps)), (error) { diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/workspace_repo.dart b/frontend/app_flowy/lib/workspace/application/workspace/workspace_listener.dart similarity index 61% rename from frontend/app_flowy/lib/workspace/infrastructure/repos/workspace_repo.dart rename to frontend/app_flowy/lib/workspace/application/workspace/workspace_listener.dart index f5465ca81e..10d59f5db4 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/workspace_repo.dart +++ b/frontend/app_flowy/lib/workspace/application/workspace/workspace_listener.dart @@ -1,10 +1,9 @@ import 'dart:async'; import 'dart:typed_data'; +import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; import 'package:dartz/dartz.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flowy_sdk/log.dart'; -import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; @@ -12,56 +11,28 @@ import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; import 'package:flowy_sdk/rust_stream.dart'; -import 'package:app_flowy/generated/locale_keys.g.dart'; -import 'helper.dart'; -class WorkspaceRepo { - UserProfile user; - String workspaceId; - WorkspaceRepo({ - required this.user, - required this.workspaceId, +typedef WorkspaceAppsChangedCallback = void Function(Either, FlowyError> appsOrFail); +typedef WorkspaceUpdatedCallback = void Function(String name, String desc); + +class WorkspaceListener { + WorkspaceListenerService service; + WorkspaceListener({ + required this.service, }); - Future> createApp(String name, String desc) { - final request = CreateAppPayload.create() - ..name = name - ..workspaceId = workspaceId - ..desc = desc; - return FolderEventCreateApp(request).send(); + void start({WorkspaceAppsChangedCallback? addAppCallback, WorkspaceUpdatedCallback? updatedCallback}) { + service.startListening(appsChanged: addAppCallback, update: updatedCallback); } - Future> getWorkspace() { - final request = WorkspaceId.create()..value = workspaceId; - return FolderEventReadWorkspaces(request).send().then((result) { - return result.fold( - (workspaces) { - assert(workspaces.items.length == 1); - - if (workspaces.items.isEmpty) { - return right(FlowyError.create()..msg = LocaleKeys.workspace_notFoundError.tr()); - } else { - return left(workspaces.items[0]); - } - }, - (error) => right(error), - ); - }); - } - - Future, FlowyError>> getApps() { - final request = WorkspaceId.create()..value = workspaceId; - return FolderEventReadWorkspaceApps(request).send().then((result) { - return result.fold( - (apps) => left(apps.items), - (error) => right(error), - ); - }); + Future stop() async { + await service.close(); } } -class WorkspaceListenerRepo { + +class WorkspaceListenerService { StreamSubscription? _subscription; WorkspaceAppsChangedCallback? _appsChanged; WorkspaceUpdatedCallback? _update; @@ -69,7 +40,7 @@ class WorkspaceListenerRepo { final UserProfile user; final String workspaceId; - WorkspaceListenerRepo({ + WorkspaceListenerService({ required this.user, required this.workspaceId, }); @@ -125,22 +96,3 @@ class WorkspaceListenerRepo { // _update = null; } } - -typedef WorkspaceAppsChangedCallback = void Function(Either, FlowyError> appsOrFail); - -typedef WorkspaceUpdatedCallback = void Function(String name, String desc); - -class WorkspaceListener { - WorkspaceListenerRepo repo; - WorkspaceListener({ - required this.repo, - }); - - void start({WorkspaceAppsChangedCallback? addAppCallback, WorkspaceUpdatedCallback? updatedCallback}) { - repo.startListening(appsChanged: addAppCallback, update: updatedCallback); - } - - Future stop() async { - await repo.close(); - } -} diff --git a/frontend/app_flowy/lib/workspace/application/workspace/workspace_service.dart b/frontend/app_flowy/lib/workspace/application/workspace/workspace_service.dart new file mode 100644 index 0000000000..931fbf028b --- /dev/null +++ b/frontend/app_flowy/lib/workspace/application/workspace/workspace_service.dart @@ -0,0 +1,46 @@ +import 'dart:async'; +import 'package:dartz/dartz.dart'; +import 'package:easy_localization/easy_localization.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; +import 'package:app_flowy/generated/locale_keys.g.dart'; + +class WorkspaceService { + Future> createApp({required String workspaceId, required String name, required String desc}) { + final request = CreateAppPayload.create() + ..name = name + ..workspaceId = workspaceId + ..desc = desc; + return FolderEventCreateApp(request).send(); + } + + Future> getWorkspace({required String workspaceId}) { + final request = WorkspaceId.create()..value = workspaceId; + return FolderEventReadWorkspaces(request).send().then((result) { + return result.fold( + (workspaces) { + assert(workspaces.items.length == 1); + + if (workspaces.items.isEmpty) { + return right(FlowyError.create()..msg = LocaleKeys.workspace_notFoundError.tr()); + } else { + return left(workspaces.items[0]); + } + }, + (error) => right(error), + ); + }); + } + + Future, FlowyError>> getApps({required String workspaceId}) { + final request = WorkspaceId.create()..value = workspaceId; + return FolderEventReadWorkspaceApps(request).send().then((result) { + return result.fold( + (apps) => left(apps.items), + (error) => right(error), + ); + }); + } +} diff --git a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart index f35af8f95e..255b18e593 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart @@ -12,10 +12,11 @@ import 'package:app_flowy/workspace/application/trash/trash_listener.dart'; import 'package:app_flowy/workspace/application/trash/trash_service.dart'; import 'package:app_flowy/workspace/application/view/view_bloc.dart'; import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart'; +import 'package:app_flowy/workspace/application/workspace/workspace_listener.dart'; +import 'package:app_flowy/workspace/application/workspace/workspace_service.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/workspace_repo.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; @@ -42,8 +43,8 @@ class HomeDepsResolver { ); //workspace - getIt.registerFactoryParam( - (user, workspaceId) => WorkspaceListener(repo: WorkspaceListenerRepo(user: user, workspaceId: workspaceId))); + getIt.registerFactoryParam((user, workspaceId) => + WorkspaceListener(service: WorkspaceListenerService(user: user, workspaceId: workspaceId))); // View getIt.registerFactoryParam( @@ -60,7 +61,8 @@ class HomeDepsResolver { //Menu Bloc getIt.registerFactoryParam( (user, workspaceId) => MenuBloc( - repo: WorkspaceRepo(user: user, workspaceId: workspaceId), + workspaceId: workspaceId, + service: WorkspaceService(), listener: getIt(param1: user, param2: workspaceId), ), ); From 289b3e31e71f4fb925c1f6550f19a2772bc42d41 Mon Sep 17 00:00:00 2001 From: MikeWallaceDev Date: Mon, 28 Feb 2022 23:06:36 -0500 Subject: [PATCH 5/9] refactor: Put View business logic in a service --- .../workspace/application/doc/doc_bloc.dart | 2 +- .../workspace/application/view/view_bloc.dart | 20 +++++----- .../view/view_listener.dart} | 40 +------------------ .../application/view/view_service.dart | 36 +++++++++++++++++ .../infrastructure/deps_resolver.dart | 6 ++- .../stack_page/doc/doc_stack_page.dart | 9 +++-- 6 files changed, 58 insertions(+), 55 deletions(-) rename frontend/app_flowy/lib/workspace/{infrastructure/repos/view_repo.dart => application/view/view_listener.dart} (71%) create mode 100644 frontend/app_flowy/lib/workspace/application/view/view_service.dart diff --git a/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart b/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart index c8f51c6256..6553c5b959 100644 --- a/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart @@ -1,7 +1,7 @@ import 'dart:convert'; import 'package:app_flowy/workspace/application/doc/doc_service.dart'; import 'package:app_flowy/workspace/application/trash/trash_service.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; +import 'package:app_flowy/workspace/application/view/view_listener.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; diff --git a/frontend/app_flowy/lib/workspace/application/view/view_bloc.dart b/frontend/app_flowy/lib/workspace/application/view/view_bloc.dart index 4bdc939e9a..1528600236 100644 --- a/frontend/app_flowy/lib/workspace/application/view/view_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/view/view_bloc.dart @@ -1,4 +1,5 @@ -import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; +import 'package:app_flowy/workspace/application/view/view_listener.dart'; +import 'package:app_flowy/workspace/application/view/view_service.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; @@ -8,18 +9,19 @@ import 'package:freezed_annotation/freezed_annotation.dart'; part 'view_bloc.freezed.dart'; class ViewBloc extends Bloc { - final ViewRepository repo; - + final ViewService service; final ViewListener listener; + final View view; ViewBloc({ - required this.repo, + required this.view, + required this.service, required this.listener, - }) : super(ViewState.init(repo.view)) { + }) : super(ViewState.init(view)) { on((event, emit) async { await event.map( initial: (e) { - // TODO: Listener can be refctored to a stream. + // TODO: Listener can be refactored to a stream. listener.updatedNotifier.addPublishListener((result) { // emit.forEach(stream, onData: onData) add(ViewEvent.viewDidUpdate(result)); @@ -37,7 +39,7 @@ class ViewBloc extends Bloc { ); }, rename: (e) async { - final result = await repo.updateView(name: e.newName); + final result = await service.updateView(viewId: view.id, name: e.newName); emit( result.fold( (l) => state.copyWith(successOrFailure: left(unit)), @@ -46,7 +48,7 @@ class ViewBloc extends Bloc { ); }, delete: (e) async { - final result = await repo.delete(); + final result = await service.delete(viewId: view.id); emit( result.fold( (l) => state.copyWith(successOrFailure: left(unit)), @@ -55,7 +57,7 @@ class ViewBloc extends Bloc { ); }, duplicate: (e) async { - final result = await repo.duplicate(); + final result = await service.duplicate(viewId: view.id); emit( result.fold( (l) => state.copyWith(successOrFailure: left(unit)), diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart b/frontend/app_flowy/lib/workspace/application/view/view_listener.dart similarity index 71% rename from frontend/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart rename to frontend/app_flowy/lib/workspace/application/view/view_listener.dart index 407b7d62fb..e3c3142fcb 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart +++ b/frontend/app_flowy/lib/workspace/application/view/view_listener.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'dart:typed_data'; +import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; @@ -9,44 +9,6 @@ import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; import 'package:flowy_sdk/rust_stream.dart'; import 'package:flowy_infra/notifier.dart'; -import 'helper.dart'; - -class ViewRepository { - View view; - ViewRepository({ - required this.view, - }); - - Future> readView() { - final request = ViewId(value: view.id); - return FolderEventReadView(request).send(); - } - - Future> updateView({String? name, String? desc}) { - final request = UpdateViewPayload.create()..viewId = view.id; - - if (name != null) { - request.name = name; - } - - if (desc != null) { - request.desc = desc; - } - - return FolderEventUpdateView(request).send(); - } - - Future> delete() { - final request = RepeatedViewId.create()..items.add(view.id); - return FolderEventDeleteView(request).send(); - } - - Future> duplicate() { - final request = ViewId(value: view.id); - return FolderEventDuplicateView(request).send(); - } -} - typedef DeleteNotifierValue = Either; typedef UpdateNotifierValue = Either; typedef RestoreNotifierValue = Either; diff --git a/frontend/app_flowy/lib/workspace/application/view/view_service.dart b/frontend/app_flowy/lib/workspace/application/view/view_service.dart new file mode 100644 index 0000000000..d3d08b0709 --- /dev/null +++ b/frontend/app_flowy/lib/workspace/application/view/view_service.dart @@ -0,0 +1,36 @@ +import 'dart:async'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; + +class ViewService { + Future> readView({required String viewId}) { + final request = ViewId(value: viewId); + return FolderEventReadView(request).send(); + } + + Future> updateView({required String viewId, String? name, String? desc}) { + final request = UpdateViewPayload.create()..viewId = viewId; + + if (name != null) { + request.name = name; + } + + if (desc != null) { + request.desc = desc; + } + + return FolderEventUpdateView(request).send(); + } + + Future> delete({required String viewId}) { + final request = RepeatedViewId.create()..items.add(viewId); + return FolderEventDeleteView(request).send(); + } + + Future> duplicate({required String viewId}) { + final request = ViewId(value: viewId); + return FolderEventDuplicateView(request).send(); + } +} diff --git a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart index 255b18e593..bb35d26bbd 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart @@ -11,12 +11,13 @@ import 'package:app_flowy/workspace/application/trash/trash_bloc.dart'; import 'package:app_flowy/workspace/application/trash/trash_listener.dart'; import 'package:app_flowy/workspace/application/trash/trash_service.dart'; import 'package:app_flowy/workspace/application/view/view_bloc.dart'; +import 'package:app_flowy/workspace/application/view/view_listener.dart'; +import 'package:app_flowy/workspace/application/view/view_service.dart'; import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart'; import 'package:app_flowy/workspace/application/workspace/workspace_listener.dart'; import 'package:app_flowy/workspace/application/workspace/workspace_service.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; @@ -53,7 +54,8 @@ class HomeDepsResolver { getIt.registerFactoryParam( (view, _) => ViewBloc( - repo: ViewRepository(view: view), + view: view, + service: ViewService(), listener: getIt(param1: view), ), ); diff --git a/frontend/app_flowy/lib/workspace/presentation/stack_page/doc/doc_stack_page.dart b/frontend/app_flowy/lib/workspace/presentation/stack_page/doc/doc_stack_page.dart index 8094a81f73..3419df42ae 100644 --- a/frontend/app_flowy/lib/workspace/presentation/stack_page/doc/doc_stack_page.dart +++ b/frontend/app_flowy/lib/workspace/presentation/stack_page/doc/doc_stack_page.dart @@ -1,9 +1,10 @@ import 'package:app_flowy/startup/startup.dart'; import 'package:app_flowy/workspace/application/appearance.dart'; import 'package:app_flowy/workspace/application/doc/share_bloc.dart'; +import 'package:app_flowy/workspace/application/view/view_listener.dart'; +import 'package:app_flowy/workspace/application/view/view_service.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:app_flowy/workspace/domain/view_ext.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; import 'package:app_flowy/workspace/presentation/widgets/dialogs.dart'; import 'package:app_flowy/workspace/presentation/widgets/pop_up_action.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -92,11 +93,11 @@ class DocumentLeftBarItem extends StatefulWidget { class _DocumentLeftBarItemState extends State { final _controller = TextEditingController(); final _focusNode = FocusNode(); - late ViewRepository repo; + late ViewService service; @override void initState() { - repo = ViewRepository(view: widget.view); + service = ViewService(/*view: widget.view*/); _focusNode.addListener(_handleFocusChanged); super.initState(); } @@ -143,7 +144,7 @@ class _DocumentLeftBarItemState extends State { } if (_controller.text != widget.view.name) { - repo.updateView(name: _controller.text); + service.updateView(viewId: widget.view.id, name: _controller.text); } } } From afab7f23c47500a40439020c85fb992267b10c96 Mon Sep 17 00:00:00 2001 From: MikeWallaceDev Date: Mon, 28 Feb 2022 23:37:41 -0500 Subject: [PATCH 6/9] refactor: Put User business logic in a service --- .../application/user_listener.dart} | 57 ------------------- .../lib/user/application/user_service.dart | 57 +++++++++++++++++++ .../lib/user/infrastructure/router.dart | 8 +-- .../user/presentation/skip_log_in_screen.dart | 2 +- .../lib/user/presentation/welcome_screen.dart | 8 +-- .../application/home/home_listen_bloc.dart | 2 +- .../application/menu/menu_user_bloc.dart | 20 ++++--- .../application/workspace/welcome_bloc.dart | 21 +++---- .../infrastructure/deps_resolver.dart | 10 ++-- 9 files changed, 94 insertions(+), 91 deletions(-) rename frontend/app_flowy/lib/{workspace/infrastructure/repos/user_repo.dart => user/application/user_listener.dart} (65%) create mode 100644 frontend/app_flowy/lib/user/application/user_service.dart diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/user_repo.dart b/frontend/app_flowy/lib/user/application/user_listener.dart similarity index 65% rename from frontend/app_flowy/lib/workspace/infrastructure/repos/user_repo.dart rename to frontend/app_flowy/lib/user/application/user_listener.dart index 7514d3dcef..93149b3caf 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/user_repo.dart +++ b/frontend/app_flowy/lib/user/application/user_listener.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'dart:typed_data'; @@ -10,65 +9,9 @@ import 'package:flowy_sdk/protobuf/dart-notify/protobuf.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-user-data-model/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; -// import 'package:flowy_sdk/protobuf/flowy-user/errors.pb.dart' as user_error; import 'package:flowy_sdk/protobuf/flowy-user/dart_notification.pb.dart' as user; import 'package:flowy_sdk/rust_stream.dart'; -class UserRepo { - final UserProfile user; - UserRepo({ - required this.user, - }); - - Future> fetchUserProfile({required String userId}) { - return UserEventGetUserProfile().send(); - } - - Future> deleteWorkspace({required String workspaceId}) { - throw UnimplementedError(); - } - - Future> signOut() { - return UserEventSignOut().send(); - } - - Future> initUser() async { - return UserEventInitUser().send(); - } - - Future, FlowyError>> getWorkspaces() { - final request = WorkspaceId.create(); - - return FolderEventReadWorkspaces(request).send().then((result) { - return result.fold( - (workspaces) => left(workspaces.items), - (error) => right(error), - ); - }); - } - - Future> openWorkspace(String workspaceId) { - final request = WorkspaceId.create()..value = workspaceId; - return FolderEventOpenWorkspace(request).send().then((result) { - return result.fold( - (workspace) => left(workspace), - (error) => right(error), - ); - }); - } - - Future> createWorkspace(String name, String desc) { - final request = CreateWorkspacePayload.create() - ..name = name - ..desc = desc; - return FolderEventCreateWorkspace(request).send().then((result) { - return result.fold( - (workspace) => left(workspace), - (error) => right(error), - ); - }); - } -} typedef UserProfileUpdatedNotifierValue = Either; typedef AuthNotifierValue = Either; diff --git a/frontend/app_flowy/lib/user/application/user_service.dart b/frontend/app_flowy/lib/user/application/user_service.dart new file mode 100644 index 0000000000..35486ac78b --- /dev/null +++ b/frontend/app_flowy/lib/user/application/user_service.dart @@ -0,0 +1,57 @@ +import 'dart:async'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; + +class UserService { + Future> fetchUserProfile({required String userId}) { + return UserEventGetUserProfile().send(); + } + + Future> deleteWorkspace({required String workspaceId}) { + throw UnimplementedError(); + } + + Future> signOut() { + return UserEventSignOut().send(); + } + + Future> initUser() async { + return UserEventInitUser().send(); + } + + Future, FlowyError>> getWorkspaces() { + final request = WorkspaceId.create(); + + return FolderEventReadWorkspaces(request).send().then((result) { + return result.fold( + (workspaces) => left(workspaces.items), + (error) => right(error), + ); + }); + } + + Future> openWorkspace(String workspaceId) { + final request = WorkspaceId.create()..value = workspaceId; + return FolderEventOpenWorkspace(request).send().then((result) { + return result.fold( + (workspace) => left(workspace), + (error) => right(error), + ); + }); + } + + Future> createWorkspace(String name, String desc) { + final request = CreateWorkspacePayload.create() + ..name = name + ..desc = desc; + return FolderEventCreateWorkspace(request).send().then((result) { + return result.fold( + (workspace) => left(workspace), + (error) => right(error), + ); + }); + } +} diff --git a/frontend/app_flowy/lib/user/infrastructure/router.dart b/frontend/app_flowy/lib/user/infrastructure/router.dart index 2fb15420b5..2a54e6c059 100644 --- a/frontend/app_flowy/lib/user/infrastructure/router.dart +++ b/frontend/app_flowy/lib/user/infrastructure/router.dart @@ -4,7 +4,6 @@ import 'package:app_flowy/user/presentation/sign_in_screen.dart'; import 'package:app_flowy/user/presentation/sign_up_screen.dart'; import 'package:app_flowy/user/presentation/skip_log_in_screen.dart'; import 'package:app_flowy/user/presentation/welcome_screen.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:app_flowy/workspace/presentation/home/home_screen.dart'; import 'package:flowy_infra/time/duration.dart'; import 'package:flowy_infra_ui/widget/route/animation.dart'; @@ -38,9 +37,8 @@ class AuthRouter { } class SplashRoute { - Future pushWelcomeScreen(BuildContext context, UserProfile user) async { - final repo = UserRepo(user: user); - final screen = WelcomeScreen(repo: repo); + Future pushWelcomeScreen(BuildContext context, UserProfile userProfile) async { + final screen = WelcomeScreen(userProfile: userProfile); final workspaceId = await Navigator.of(context).push( PageRoutes.fade( () => screen, @@ -48,7 +46,7 @@ class SplashRoute { ), ); - pushHomeScreen(context, repo.user, workspaceId); + pushHomeScreen(context, userProfile, workspaceId); } void pushHomeScreen(BuildContext context, UserProfile userProfile, CurrentWorkspaceSetting workspaceSetting) { diff --git a/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart b/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart index f86feb8226..bff30b8521 100644 --- a/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart +++ b/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart @@ -1,7 +1,7 @@ +import 'package:app_flowy/user/application/user_listener.dart'; import 'package:app_flowy/user/infrastructure/router.dart'; import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart'; import 'package:app_flowy/user/presentation/widgets/background.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flowy_infra/size.dart'; import 'package:flowy_infra/theme.dart'; diff --git a/frontend/app_flowy/lib/user/presentation/welcome_screen.dart b/frontend/app_flowy/lib/user/presentation/welcome_screen.dart index f1b8f2c3bf..81f7cfb50f 100644 --- a/frontend/app_flowy/lib/user/presentation/welcome_screen.dart +++ b/frontend/app_flowy/lib/user/presentation/welcome_screen.dart @@ -6,22 +6,22 @@ import 'package:flowy_infra_ui/style_widget/scrolling/styled_list.dart'; import 'package:flowy_infra_ui/style_widget/button.dart'; import 'package:flowy_infra_ui/widget/error_page.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:app_flowy/generated/locale_keys.g.dart'; class WelcomeScreen extends StatelessWidget { - final UserRepo repo; + final UserProfile userProfile; const WelcomeScreen({ Key? key, - required this.repo, + required this.userProfile, }) : super(key: key); @override Widget build(BuildContext context) { return BlocProvider( - create: (_) => getIt(param1: repo.user)..add(const WelcomeEvent.initial()), + create: (_) => getIt(param1: userProfile)..add(const WelcomeEvent.initial()), child: BlocBuilder( builder: (context, state) { return Scaffold( diff --git a/frontend/app_flowy/lib/workspace/application/home/home_listen_bloc.dart b/frontend/app_flowy/lib/workspace/application/home/home_listen_bloc.dart index 5285c067df..f3da1af678 100644 --- a/frontend/app_flowy/lib/workspace/application/home/home_listen_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/home/home_listen_bloc.dart @@ -1,4 +1,4 @@ -import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; +import 'package:app_flowy/user/application/user_listener.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; diff --git a/frontend/app_flowy/lib/workspace/application/menu/menu_user_bloc.dart b/frontend/app_flowy/lib/workspace/application/menu/menu_user_bloc.dart index e8c5dfb0b7..5129612ecb 100644 --- a/frontend/app_flowy/lib/workspace/application/menu/menu_user_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/menu/menu_user_bloc.dart @@ -1,4 +1,5 @@ -import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; +import 'package:app_flowy/user/application/user_listener.dart'; +import 'package:app_flowy/user/application/user_service.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; @@ -10,16 +11,17 @@ import 'package:dartz/dartz.dart'; part 'menu_user_bloc.freezed.dart'; class MenuUserBloc extends Bloc { - final UserRepo repo; - final UserListener listener; + final UserService userService; + final UserListener userListener; + final UserProfile userProfile; - MenuUserBloc(this.repo, this.listener) : super(MenuUserState.initial(repo.user)) { + MenuUserBloc(this.userProfile, this.userService, this.userListener) : super(MenuUserState.initial(userProfile)) { on((event, emit) async { await event.map( initial: (_) async { - listener.profileUpdatedNotifier.addPublishListener(_profileUpdated); - listener.workspaceUpdatedNotifier.addPublishListener(_workspacesUpdated); - listener.start(); + userListener.profileUpdatedNotifier.addPublishListener(_profileUpdated); + userListener.workspaceUpdatedNotifier.addPublishListener(_workspacesUpdated); + userListener.start(); await _initUser(); }, fetchWorkspaces: (_FetchWorkspaces value) async {}, @@ -29,12 +31,12 @@ class MenuUserBloc extends Bloc { @override Future close() async { - await listener.stop(); + await userListener.stop(); super.close(); } Future _initUser() async { - final result = await repo.initUser(); + final result = await userService.initUser(); result.fold((l) => null, (error) => Log.error(error)); } diff --git a/frontend/app_flowy/lib/workspace/application/workspace/welcome_bloc.dart b/frontend/app_flowy/lib/workspace/application/workspace/welcome_bloc.dart index b613109f11..8276331d10 100644 --- a/frontend/app_flowy/lib/workspace/application/workspace/welcome_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/workspace/welcome_bloc.dart @@ -1,4 +1,5 @@ -import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; +import 'package:app_flowy/user/application/user_listener.dart'; +import 'package:app_flowy/user/application/user_service.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; @@ -9,14 +10,14 @@ import 'package:dartz/dartz.dart'; part 'welcome_bloc.freezed.dart'; class WelcomeBloc extends Bloc { - final UserRepo repo; - final UserListener listener; - WelcomeBloc({required this.repo, required this.listener}) : super(WelcomeState.initial()) { + final UserService userService; + final UserListener userListener; + WelcomeBloc({required this.userService, required this.userListener}) : super(WelcomeState.initial()) { on( (event, emit) async { await event.map(initial: (e) async { - listener.workspaceUpdatedNotifier.addPublishListener(_workspacesUpdated); - listener.start(); + userListener.workspaceUpdatedNotifier.addPublishListener(_workspacesUpdated); + userListener.start(); // await _fetchWorkspaces(emit); }, openWorkspace: (e) async { @@ -35,12 +36,12 @@ class WelcomeBloc extends Bloc { @override Future close() async { - await listener.stop(); + await userListener.stop(); super.close(); } Future _fetchWorkspaces(Emitter emit) async { - final workspacesOrFailed = await repo.getWorkspaces(); + final workspacesOrFailed = await userService.getWorkspaces(); emit(workspacesOrFailed.fold( (workspaces) => state.copyWith(workspaces: workspaces, successOrFailure: left(unit)), (error) { @@ -51,7 +52,7 @@ class WelcomeBloc extends Bloc { } Future _openWorkspace(Workspace workspace, Emitter emit) async { - final result = await repo.openWorkspace(workspace.id); + final result = await userService.openWorkspace(workspace.id); emit(result.fold( (workspaces) => state.copyWith(successOrFailure: left(unit)), (error) { @@ -62,7 +63,7 @@ class WelcomeBloc extends Bloc { } Future _createWorkspace(String name, String desc, Emitter emit) async { - final result = await repo.createWorkspace(name, desc); + final result = await userService.createWorkspace(name, desc); emit(result.fold( (workspace) { return state.copyWith(successOrFailure: left(unit)); diff --git a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart index bb35d26bbd..125a93f2cf 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart @@ -1,3 +1,5 @@ +import 'package:app_flowy/user/application/user_listener.dart'; +import 'package:app_flowy/user/application/user_service.dart'; import 'package:app_flowy/workspace/application/app/app_bloc.dart'; import 'package:app_flowy/workspace/application/app/app_listener.dart'; import 'package:app_flowy/workspace/application/app/app_service.dart'; @@ -17,7 +19,6 @@ import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart'; import 'package:app_flowy/workspace/application/workspace/workspace_listener.dart'; import 'package:app_flowy/workspace/application/workspace/workspace_service.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; @@ -38,8 +39,8 @@ class HomeDepsResolver { getIt.registerLazySingleton(() => HomeStackManager()); getIt.registerFactoryParam( (user, _) => WelcomeBloc( - repo: UserRepo(user: user), - listener: getIt(param1: user), + userService: UserService(), + userListener: getIt(param1: user), ), ); @@ -71,7 +72,8 @@ class HomeDepsResolver { getIt.registerFactoryParam( (user, _) => MenuUserBloc( - UserRepo(user: user), + user, + UserService(), getIt(param1: user), ), ); From 4180765dc6034740103b7e1dfbe43a036a0b52b6 Mon Sep 17 00:00:00 2001 From: MikeWallaceDev Date: Mon, 28 Feb 2022 23:45:17 -0500 Subject: [PATCH 7/9] refactor: Put DocShare business logic in a service --- .../lib/workspace/application/doc/share_bloc.dart | 8 ++++---- .../doc/share_service.dart} | 2 +- .../lib/workspace/infrastructure/deps_resolver.dart | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) rename frontend/app_flowy/lib/workspace/{infrastructure/repos/share_repo.dart => application/doc/share_service.dart} (97%) diff --git a/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart b/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart index 460a9986c7..0eb9ec43a5 100644 --- a/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart @@ -1,5 +1,5 @@ +import 'package:app_flowy/workspace/application/doc/share_service.dart'; import 'package:app_flowy/workspace/infrastructure/markdown/delta_markdown.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/share_repo.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/share.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; @@ -9,13 +9,13 @@ import 'package:dartz/dartz.dart'; part 'share_bloc.freezed.dart'; class DocShareBloc extends Bloc { - ShareRepo repo; + ShareService service; View view; - DocShareBloc({required this.view, required this.repo}) : super(const DocShareState.initial()) { + DocShareBloc({required this.view, required this.service}) : super(const DocShareState.initial()) { on((event, emit) async { await event.map( shareMarkdown: (ShareMarkdown value) async { - await repo.exportMarkdown(view.id).then((result) { + await service.exportMarkdown(view.id).then((result) { result.fold( (value) => emit(DocShareState.finish(left(_convertDeltaToMarkdown(value)))), (error) => emit(DocShareState.finish(right(error))), diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/share_repo.dart b/frontend/app_flowy/lib/workspace/application/doc/share_service.dart similarity index 97% rename from frontend/app_flowy/lib/workspace/infrastructure/repos/share_repo.dart rename to frontend/app_flowy/lib/workspace/application/doc/share_service.dart index ffd95d1e0b..a7d47cb064 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/share_repo.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/share_service.dart @@ -4,7 +4,7 @@ import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/protobuf.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -class ShareRepo { +class ShareService { Future> export(String docId, ExportType type) { final request = ExportPayload.create() ..docId = docId diff --git a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart index 125a93f2cf..bf1e892700 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart @@ -6,6 +6,7 @@ import 'package:app_flowy/workspace/application/app/app_service.dart'; import 'package:app_flowy/workspace/application/doc/doc_bloc.dart'; import 'package:app_flowy/workspace/application/doc/doc_service.dart'; import 'package:app_flowy/workspace/application/doc/share_bloc.dart'; +import 'package:app_flowy/workspace/application/doc/share_service.dart'; import 'package:app_flowy/workspace/application/home/home_listen_bloc.dart'; import 'package:app_flowy/workspace/application/menu/menu_bloc.dart'; import 'package:app_flowy/workspace/application/menu/menu_user_bloc.dart'; @@ -23,7 +24,6 @@ import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; import 'package:get_it/get_it.dart'; -import 'repos/share_repo.dart'; class HomeDepsResolver { static Future resolve(GetIt getIt) async { @@ -108,8 +108,8 @@ class HomeDepsResolver { ); // share - getIt.registerLazySingleton(() => ShareRepo()); + getIt.registerLazySingleton(() => ShareService()); getIt.registerFactoryParam( - (view, _) => DocShareBloc(view: view, repo: getIt())); + (view, _) => DocShareBloc(view: view, service: getIt())); } } From 64d651ab1340eb75a5f50d2703cb372783fcb401 Mon Sep 17 00:00:00 2001 From: MikeWallaceDev Date: Mon, 28 Feb 2022 23:56:41 -0500 Subject: [PATCH 8/9] refactor: move markdown to application created a core folder --- .../lib/{workspace/infrastructure/repos => core}/helper.dart | 0 .../{workspace/infrastructure => startup}/deps_resolver.dart | 0 frontend/app_flowy/lib/startup/startup.dart | 2 +- frontend/app_flowy/lib/user/application/user_listener.dart | 2 +- .../app_flowy/lib/workspace/application/app/app_listener.dart | 2 +- .../app_flowy/lib/workspace/application/doc/share_bloc.dart | 2 +- .../markdown/delta_markdown.dart | 0 .../{infrastructure => application}/markdown/src/ast.dart | 0 .../markdown/src/block_parser.dart | 0 .../markdown/src/delta_markdown_decoder.dart | 0 .../markdown/src/delta_markdown_encoder.dart | 0 .../{infrastructure => application}/markdown/src/document.dart | 0 .../{infrastructure => application}/markdown/src/emojis.dart | 0 .../markdown/src/extension_set.dart | 0 .../markdown/src/html_renderer.dart | 0 .../markdown/src/inline_parser.dart | 0 .../{infrastructure => application}/markdown/src/util.dart | 0 .../{infrastructure => application}/markdown/src/version.dart | 0 .../lib/workspace/application/trash/trash_listener.dart | 2 +- .../app_flowy/lib/workspace/application/view/view_listener.dart | 2 +- .../lib/workspace/application/workspace/workspace_listener.dart | 2 +- 21 files changed, 7 insertions(+), 7 deletions(-) rename frontend/app_flowy/lib/{workspace/infrastructure/repos => core}/helper.dart (100%) rename frontend/app_flowy/lib/{workspace/infrastructure => startup}/deps_resolver.dart (100%) rename frontend/app_flowy/lib/workspace/{infrastructure => application}/markdown/delta_markdown.dart (100%) rename frontend/app_flowy/lib/workspace/{infrastructure => application}/markdown/src/ast.dart (100%) rename frontend/app_flowy/lib/workspace/{infrastructure => application}/markdown/src/block_parser.dart (100%) rename frontend/app_flowy/lib/workspace/{infrastructure => application}/markdown/src/delta_markdown_decoder.dart (100%) rename frontend/app_flowy/lib/workspace/{infrastructure => application}/markdown/src/delta_markdown_encoder.dart (100%) rename frontend/app_flowy/lib/workspace/{infrastructure => application}/markdown/src/document.dart (100%) rename frontend/app_flowy/lib/workspace/{infrastructure => application}/markdown/src/emojis.dart (100%) rename frontend/app_flowy/lib/workspace/{infrastructure => application}/markdown/src/extension_set.dart (100%) rename frontend/app_flowy/lib/workspace/{infrastructure => application}/markdown/src/html_renderer.dart (100%) rename frontend/app_flowy/lib/workspace/{infrastructure => application}/markdown/src/inline_parser.dart (100%) rename frontend/app_flowy/lib/workspace/{infrastructure => application}/markdown/src/util.dart (100%) rename frontend/app_flowy/lib/workspace/{infrastructure => application}/markdown/src/version.dart (100%) diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/helper.dart b/frontend/app_flowy/lib/core/helper.dart similarity index 100% rename from frontend/app_flowy/lib/workspace/infrastructure/repos/helper.dart rename to frontend/app_flowy/lib/core/helper.dart diff --git a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/startup/deps_resolver.dart similarity index 100% rename from frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart rename to frontend/app_flowy/lib/startup/deps_resolver.dart diff --git a/frontend/app_flowy/lib/startup/startup.dart b/frontend/app_flowy/lib/startup/startup.dart index 283a751c75..0620ea03b9 100644 --- a/frontend/app_flowy/lib/startup/startup.dart +++ b/frontend/app_flowy/lib/startup/startup.dart @@ -4,7 +4,7 @@ import 'package:app_flowy/startup/tasks/prelude.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; -import 'package:app_flowy/workspace/infrastructure/deps_resolver.dart'; +import 'package:app_flowy/startup/deps_resolver.dart'; import 'package:app_flowy/user/infrastructure/deps_resolver.dart'; import 'package:flowy_sdk/flowy_sdk.dart'; diff --git a/frontend/app_flowy/lib/user/application/user_listener.dart b/frontend/app_flowy/lib/user/application/user_listener.dart index 93149b3caf..836b6c5dab 100644 --- a/frontend/app_flowy/lib/user/application/user_listener.dart +++ b/frontend/app_flowy/lib/user/application/user_listener.dart @@ -3,7 +3,7 @@ import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'dart:typed_data'; -import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; +import 'package:app_flowy/core/helper.dart'; import 'package:flowy_infra/notifier.dart'; import 'package:flowy_sdk/protobuf/dart-notify/protobuf.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; diff --git a/frontend/app_flowy/lib/workspace/application/app/app_listener.dart b/frontend/app_flowy/lib/workspace/application/app/app_listener.dart index b2970b931d..cad429eea6 100644 --- a/frontend/app_flowy/lib/workspace/application/app/app_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/app/app_listener.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'dart:typed_data'; import 'package:dartz/dartz.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; +import 'package:app_flowy/core/helper.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; diff --git a/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart b/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart index 0eb9ec43a5..fe4b2e7f5c 100644 --- a/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart @@ -1,5 +1,5 @@ import 'package:app_flowy/workspace/application/doc/share_service.dart'; -import 'package:app_flowy/workspace/infrastructure/markdown/delta_markdown.dart'; +import 'package:app_flowy/workspace/application/markdown/delta_markdown.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/share.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; diff --git a/frontend/app_flowy/lib/workspace/infrastructure/markdown/delta_markdown.dart b/frontend/app_flowy/lib/workspace/application/markdown/delta_markdown.dart similarity index 100% rename from frontend/app_flowy/lib/workspace/infrastructure/markdown/delta_markdown.dart rename to frontend/app_flowy/lib/workspace/application/markdown/delta_markdown.dart diff --git a/frontend/app_flowy/lib/workspace/infrastructure/markdown/src/ast.dart b/frontend/app_flowy/lib/workspace/application/markdown/src/ast.dart similarity index 100% rename from frontend/app_flowy/lib/workspace/infrastructure/markdown/src/ast.dart rename to frontend/app_flowy/lib/workspace/application/markdown/src/ast.dart diff --git a/frontend/app_flowy/lib/workspace/infrastructure/markdown/src/block_parser.dart b/frontend/app_flowy/lib/workspace/application/markdown/src/block_parser.dart similarity index 100% rename from frontend/app_flowy/lib/workspace/infrastructure/markdown/src/block_parser.dart rename to frontend/app_flowy/lib/workspace/application/markdown/src/block_parser.dart diff --git a/frontend/app_flowy/lib/workspace/infrastructure/markdown/src/delta_markdown_decoder.dart b/frontend/app_flowy/lib/workspace/application/markdown/src/delta_markdown_decoder.dart similarity index 100% rename from frontend/app_flowy/lib/workspace/infrastructure/markdown/src/delta_markdown_decoder.dart rename to frontend/app_flowy/lib/workspace/application/markdown/src/delta_markdown_decoder.dart diff --git a/frontend/app_flowy/lib/workspace/infrastructure/markdown/src/delta_markdown_encoder.dart b/frontend/app_flowy/lib/workspace/application/markdown/src/delta_markdown_encoder.dart similarity index 100% rename from frontend/app_flowy/lib/workspace/infrastructure/markdown/src/delta_markdown_encoder.dart rename to frontend/app_flowy/lib/workspace/application/markdown/src/delta_markdown_encoder.dart diff --git a/frontend/app_flowy/lib/workspace/infrastructure/markdown/src/document.dart b/frontend/app_flowy/lib/workspace/application/markdown/src/document.dart similarity index 100% rename from frontend/app_flowy/lib/workspace/infrastructure/markdown/src/document.dart rename to frontend/app_flowy/lib/workspace/application/markdown/src/document.dart diff --git a/frontend/app_flowy/lib/workspace/infrastructure/markdown/src/emojis.dart b/frontend/app_flowy/lib/workspace/application/markdown/src/emojis.dart similarity index 100% rename from frontend/app_flowy/lib/workspace/infrastructure/markdown/src/emojis.dart rename to frontend/app_flowy/lib/workspace/application/markdown/src/emojis.dart diff --git a/frontend/app_flowy/lib/workspace/infrastructure/markdown/src/extension_set.dart b/frontend/app_flowy/lib/workspace/application/markdown/src/extension_set.dart similarity index 100% rename from frontend/app_flowy/lib/workspace/infrastructure/markdown/src/extension_set.dart rename to frontend/app_flowy/lib/workspace/application/markdown/src/extension_set.dart diff --git a/frontend/app_flowy/lib/workspace/infrastructure/markdown/src/html_renderer.dart b/frontend/app_flowy/lib/workspace/application/markdown/src/html_renderer.dart similarity index 100% rename from frontend/app_flowy/lib/workspace/infrastructure/markdown/src/html_renderer.dart rename to frontend/app_flowy/lib/workspace/application/markdown/src/html_renderer.dart diff --git a/frontend/app_flowy/lib/workspace/infrastructure/markdown/src/inline_parser.dart b/frontend/app_flowy/lib/workspace/application/markdown/src/inline_parser.dart similarity index 100% rename from frontend/app_flowy/lib/workspace/infrastructure/markdown/src/inline_parser.dart rename to frontend/app_flowy/lib/workspace/application/markdown/src/inline_parser.dart diff --git a/frontend/app_flowy/lib/workspace/infrastructure/markdown/src/util.dart b/frontend/app_flowy/lib/workspace/application/markdown/src/util.dart similarity index 100% rename from frontend/app_flowy/lib/workspace/infrastructure/markdown/src/util.dart rename to frontend/app_flowy/lib/workspace/application/markdown/src/util.dart diff --git a/frontend/app_flowy/lib/workspace/infrastructure/markdown/src/version.dart b/frontend/app_flowy/lib/workspace/application/markdown/src/version.dart similarity index 100% rename from frontend/app_flowy/lib/workspace/infrastructure/markdown/src/version.dart rename to frontend/app_flowy/lib/workspace/application/markdown/src/version.dart diff --git a/frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart b/frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart index 3d558d1b4e..268c46339f 100644 --- a/frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'dart:typed_data'; import 'package:dartz/dartz.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; +import 'package:app_flowy/core/helper.dart'; import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; diff --git a/frontend/app_flowy/lib/workspace/application/view/view_listener.dart b/frontend/app_flowy/lib/workspace/application/view/view_listener.dart index e3c3142fcb..4486a44f66 100644 --- a/frontend/app_flowy/lib/workspace/application/view/view_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/view/view_listener.dart @@ -1,6 +1,6 @@ import 'dart:async'; import 'dart:typed_data'; -import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; +import 'package:app_flowy/core/helper.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; diff --git a/frontend/app_flowy/lib/workspace/application/workspace/workspace_listener.dart b/frontend/app_flowy/lib/workspace/application/workspace/workspace_listener.dart index 10d59f5db4..afc6bc0795 100644 --- a/frontend/app_flowy/lib/workspace/application/workspace/workspace_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/workspace/workspace_listener.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'dart:typed_data'; -import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; +import 'package:app_flowy/core/helper.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart'; From 65917da468f044283368cdae731b2b5cca93d0fe Mon Sep 17 00:00:00 2001 From: tsuiyuenhong Date: Tue, 1 Mar 2022 15:43:42 +0800 Subject: [PATCH 9/9] chore: use actions-cache to speed up dart & rust test. --- .github/workflows/ci.yaml | 5 ++-- .github/workflows/dart_test.yml | 49 ++++++++++++++++++++++++--------- .github/workflows/release.yml | 4 +-- .github/workflows/rust_lint.yml | 4 +-- .github/workflows/rust_test.yml | 42 ++++++++++++++++++++-------- 5 files changed, 73 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 933619de73..40f51c8132 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,7 +27,7 @@ jobs: - id: rust_toolchain uses: actions-rs/toolchain@v1 with: - toolchain: stable + toolchain: 'stable-2022-01-20' - id: flutter uses: subosito/flutter-action@v2 @@ -47,7 +47,8 @@ jobs: with: path: | frontend/rust-lib/target - key: ${{ runner.os }}-rust-${{ steps.rust_toolchain.outputs.rustc_hash }}-${{ hashFiles('./frontend/rust-lib/Cargo.toml') }} + shared-lib/target + key: ${{ runner.os }}-rust-rust-lib-share-lib-${{ steps.rust_toolchain.outputs.rustc_hash }}-${{ hashFiles('./frontend/rust-lib/Cargo.toml') }} - name: Setup Environment run: | diff --git a/.github/workflows/dart_test.yml b/.github/workflows/dart_test.yml index 370c0d6021..bc29ded018 100644 --- a/.github/workflows/dart_test.yml +++ b/.github/workflows/dart_test.yml @@ -2,9 +2,12 @@ name: Unit test(Flutter) on: push: - branches: [ main ] + branches: + - 'main' + pull_request: - branches: [ main ] + branches: + - 'main' env: CARGO_TERM_COLOR: always @@ -13,36 +16,56 @@ jobs: tests: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v2 - - uses: subosito/flutter-action@v1 - with: - channel: "stable" + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 with: - toolchain: stable + toolchain: 'stable-2022-01-20' + + - uses: subosito/flutter-action@v2 + with: + channel: 'stable' + cache: true + + - name: Cache Cargo + uses: actions/cache@v2 + with: + path: | + ~/.cargo + key: ${{ runner.os }}-cargo-${{ steps.rust_toolchain.outputs.rustc_hash }}-${{ hashFiles('./frontend/rust-lib/Cargo.toml') }} + + - name: Cache Rust + uses: actions/cache@v2 + with: + path: | + frontend/rust-lib/target + shared-lib/target + key: ${{ runner.os }}-rust-rust-lib-share-lib-${{ steps.rust_toolchain.outputs.rustc_hash }}-${{ hashFiles('./frontend/rust-lib/Cargo.toml') }} + - name: Deps Flutter + working-directory: frontend/app_flowy run: | flutter config --enable-linux-desktop - flutter doctor - working-directory: frontend/app_flowy + - name: Deps Rust working-directory: frontend run: | - cargo install --force cargo-make - cargo install --force duckscript_cli + cargo install cargo-make + cargo install duckscript_cli cargo make flowy_dev - echo PATH="$PATH":"$HOME/.pub-cache/bin" >> $GITHUB_PATH + - name: Code Generation working-directory: frontend/app_flowy run: | flutter packages pub get flutter packages pub run easy_localization:generate -S ./assets/translations -f keys -O lib/generated -o locale_keys.g.dart flutter packages pub run build_runner build --delete-conflicting-outputs + - name: Build FlowySDK working-directory: frontend run: | cargo make --profile development-linux-x86 flowy-sdk-dev + - name: Run bloc tests working-directory: frontend/app_flowy run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dbf5df0d49..69cf3ec788 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -44,7 +44,7 @@ jobs: - name: Setup environment - Rust and Cargo uses: actions-rs/toolchain@v1 with: - toolchain: stable + toolchain: 'stable-2022-01-20' - name: Setup environment - Flutter uses: subosito/flutter-action@v2 @@ -92,7 +92,7 @@ jobs: - name: Setup environment - Rust and Cargo uses: actions-rs/toolchain@v1 with: - toolchain: stable + toolchain: 'stable-2022-01-20' - name: Setup environment - Flutter uses: subosito/flutter-action@v2 diff --git a/.github/workflows/rust_lint.yml b/.github/workflows/rust_lint.yml index 63ef2e297b..9b39f28f2d 100644 --- a/.github/workflows/rust_lint.yml +++ b/.github/workflows/rust_lint.yml @@ -24,7 +24,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: stable + toolchain: 'stable-2022-01-20' override: true - run: rustup component add rustfmt working-directory: frontend/rust-lib @@ -39,7 +39,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: stable + toolchain: 'stable-2022-01-20' override: true - run: rustup component add clippy working-directory: frontend/rust-lib diff --git a/.github/workflows/rust_test.yml b/.github/workflows/rust_test.yml index 0321d5f9bc..e58db025b4 100644 --- a/.github/workflows/rust_test.yml +++ b/.github/workflows/rust_test.yml @@ -2,12 +2,14 @@ name: Unit test(Rust) on: push: - branches: [ main ] + branches: + - 'main' paths: - 'frontend/rust-lib' - 'shared-lib' pull_request: - branches: [ main ] + branches: + - 'main' paths: - 'frontend/rust-lib' - 'shared-lib' @@ -21,19 +23,35 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Install Rust - run: | - curl \ - --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - source $HOME/.cargo/env - rustup toolchain install stable - rustup default stable + + - id: rust_toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: 'stable-2022-01-20' + + - name: Cache Cargo + uses: actions/cache@v2 + with: + path: | + ~/.cargo + key: ${{ runner.os }}-cargo-${{ steps.rust_toolchain.outputs.rustc_hash }}-${{ hashFiles('./frontend/rust-lib/Cargo.toml') }} + + - name: Cache Rust + uses: actions/cache@v2 + with: + path: | + frontend/rust-lib/target + shared-lib/target + key: ${{ runner.os }}-rust-rust-lib-share-lib-${{ steps.rust_toolchain.outputs.rustc_hash }}-${{ hashFiles('./frontend/rust-lib/Cargo.toml') }} + - name: Install cargo-make - run: cargo install --force cargo-make working-directory: frontend + run: cargo install cargo-make + - name: Run rust-lib tests - run: cargo test --no-default-features working-directory: frontend/rust-lib - - name: Run shared-lib tests run: cargo test --no-default-features + + - name: Run shared-lib tests working-directory: shared-lib + run: cargo test --no-default-features \ No newline at end of file