From 6509247fbda4fcab4b78f5b85c9d5f105167aa88 Mon Sep 17 00:00:00 2001 From: MikeWallaceDev Date: Mon, 28 Feb 2022 21:02:46 -0500 Subject: [PATCH] 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(), ),