2021-07-23 08:14:45 +08:00
|
|
|
use crate::{
|
2021-07-31 10:50:56 +08:00
|
|
|
errors::DocError,
|
2021-07-23 08:14:45 +08:00
|
|
|
event::EditorEvent,
|
|
|
|
handlers::*,
|
2021-07-25 08:13:59 +08:00
|
|
|
services::{doc_controller::DocController, file_manager::FileManager},
|
2021-07-23 08:14:45 +08:00
|
|
|
};
|
|
|
|
use flowy_database::DBConnection;
|
2021-07-22 22:26:38 +08:00
|
|
|
use flowy_dispatch::prelude::*;
|
2021-07-23 15:00:13 +08:00
|
|
|
use std::sync::Arc;
|
|
|
|
use tokio::sync::RwLock;
|
2021-07-22 22:26:38 +08:00
|
|
|
|
2021-07-31 10:50:56 +08:00
|
|
|
pub trait DocumentDatabase: Send + Sync {
|
|
|
|
fn db_connection(&self) -> Result<DBConnection, DocError>;
|
2021-07-23 08:14:45 +08:00
|
|
|
}
|
|
|
|
|
2021-07-31 10:50:56 +08:00
|
|
|
pub trait DocumentUser: Send + Sync {
|
|
|
|
fn user_doc_dir(&self) -> Result<String, DocError>;
|
2021-07-23 14:37:18 +08:00
|
|
|
}
|
|
|
|
|
2021-07-31 10:50:56 +08:00
|
|
|
pub fn create(database: Arc<dyn DocumentDatabase>, user: Arc<dyn DocumentUser>) -> Module {
|
2021-07-23 17:30:33 +08:00
|
|
|
let file_manager = RwLock::new(FileManager::new(user.clone()));
|
2021-07-23 14:37:18 +08:00
|
|
|
let doc_controller = DocController::new(database);
|
2021-07-22 22:26:38 +08:00
|
|
|
|
|
|
|
Module::new()
|
2021-07-31 10:50:56 +08:00
|
|
|
.name("flowy-document")
|
2021-07-22 22:26:38 +08:00
|
|
|
.data(file_manager)
|
2021-07-23 14:37:18 +08:00
|
|
|
.data(doc_controller)
|
2021-07-22 22:26:38 +08:00
|
|
|
.event(EditorEvent::CreateDoc, create_doc)
|
2021-07-23 14:37:18 +08:00
|
|
|
.event(EditorEvent::UpdateDoc, update_doc)
|
2021-07-24 14:05:49 +08:00
|
|
|
.event(EditorEvent::ReadDocInfo, read_doc)
|
|
|
|
.event(EditorEvent::ReadDocData, read_doc_data)
|
2021-07-22 22:26:38 +08:00
|
|
|
}
|