Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
refactor: put document business logic into service
MikeWallaceDev6509247fbda4
diff --git a/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart b/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dartindex 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<DocumentEvent, DocumentState> {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<DocumentEvent, DocumentState> {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<DocumentEvent, DocumentState> {await _subscription?.cancel();}- repo.closeDocument();+ service.closeDocument(docId: view.id);return super.close();}@@ -82,7 +82,7 @@ class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {});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<DocumentEvent, DocumentState> {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.dartsimilarity index 74%rename from frontend/app_flowy/lib/workspace/infrastructure/repos/document_repo.dartrename to frontend/app_flowy/lib/workspace/application/doc/doc_service.dartindex 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<Either<DocumentDelta, FlowyError>> openDocument() {+class DocumentService {+ Future<Either<DocumentDelta, FlowyError>> openDocument({required String docId}) {final request = ViewId(value: docId);return FolderEventOpenView(request).send();}- Future<Either<DocumentDelta, FlowyError>> composeDelta({required String data}) {+ Future<Either<DocumentDelta, FlowyError>> composeDelta({required String docId, required String data}) {final request = DocumentDelta.create()..docId = docId..deltaJson = data;return FolderEventApplyDocDelta(request).send();}- Future<Either<Unit, FlowyError>> closeDocument() {+ Future<Either<Unit, FlowyError>> 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.dartindex 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<DocumentBloc, View, void>((view, _) => DocumentBloc(view: view,- repo: DocumentRepository(docId: view.id),+ service: DocumentService(),listener: getIt<ViewListener>(param1: view),trashRepo: getIt<TrashRepo>(),),