mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
rename moduleData to unit
This commit is contained in:
parent
c27f616ddb
commit
984e912542
@ -5,18 +5,18 @@ use crate::{
|
||||
};
|
||||
use std::{any::type_name, ops::Deref, sync::Arc};
|
||||
|
||||
pub struct ModuleData<T: ?Sized + Send + Sync>(Arc<T>);
|
||||
pub struct Unit<T: ?Sized + Send + Sync>(Arc<T>);
|
||||
|
||||
impl<T> ModuleData<T>
|
||||
impl<T> Unit<T>
|
||||
where
|
||||
T: Send + Sync,
|
||||
{
|
||||
pub fn new(data: T) -> Self { ModuleData(Arc::new(data)) }
|
||||
pub fn new(data: T) -> Self { Unit(Arc::new(data)) }
|
||||
|
||||
pub fn get_ref(&self) -> &T { self.0.as_ref() }
|
||||
}
|
||||
|
||||
impl<T> Deref for ModuleData<T>
|
||||
impl<T> Deref for Unit<T>
|
||||
where
|
||||
T: ?Sized + Send + Sync,
|
||||
{
|
||||
@ -25,21 +25,21 @@ where
|
||||
fn deref(&self) -> &Arc<T> { &self.0 }
|
||||
}
|
||||
|
||||
impl<T> Clone for ModuleData<T>
|
||||
impl<T> Clone for Unit<T>
|
||||
where
|
||||
T: ?Sized + Send + Sync,
|
||||
{
|
||||
fn clone(&self) -> ModuleData<T> { ModuleData(self.0.clone()) }
|
||||
fn clone(&self) -> Unit<T> { Unit(self.0.clone()) }
|
||||
}
|
||||
|
||||
impl<T> From<Arc<T>> for ModuleData<T>
|
||||
impl<T> From<Arc<T>> for Unit<T>
|
||||
where
|
||||
T: ?Sized + Send + Sync,
|
||||
{
|
||||
fn from(arc: Arc<T>) -> Self { ModuleData(arc) }
|
||||
fn from(arc: Arc<T>) -> Self { Unit(arc) }
|
||||
}
|
||||
|
||||
impl<T> FromRequest for ModuleData<T>
|
||||
impl<T> FromRequest for Unit<T>
|
||||
where
|
||||
T: ?Sized + Send + Sync + 'static,
|
||||
{
|
||||
@ -48,7 +48,7 @@ where
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &EventRequest, _: &mut Payload) -> Self::Future {
|
||||
if let Some(data) = req.module_data::<ModuleData<T>>() {
|
||||
if let Some(data) = req.module_data::<Unit<T>>() {
|
||||
ready(Ok(data.clone()))
|
||||
} else {
|
||||
let msg = format!(
|
||||
|
@ -13,7 +13,7 @@ use pin_project::pin_project;
|
||||
|
||||
use crate::{
|
||||
errors::{DispatchError, InternalError},
|
||||
module::{container::ModuleDataMap, ModuleData},
|
||||
module::{container::ModuleDataMap, Unit},
|
||||
request::{payload::Payload, EventRequest, FromRequest},
|
||||
response::{EventResponse, Responder},
|
||||
service::{
|
||||
@ -77,7 +77,7 @@ impl Module {
|
||||
pub fn data<D: 'static + Send + Sync>(mut self, data: D) -> Self {
|
||||
Arc::get_mut(&mut self.module_data)
|
||||
.unwrap()
|
||||
.insert(ModuleData::new(data));
|
||||
.insert(Unit::new(data));
|
||||
|
||||
self
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ use std::{
|
||||
|
||||
pub async fn create_doc(
|
||||
data: Data<CreateDocRequest>,
|
||||
controller: ModuleData<DocController>,
|
||||
manager: ModuleData<RwLock<FileManager>>,
|
||||
controller: Unit<DocController>,
|
||||
manager: Unit<RwLock<FileManager>>,
|
||||
) -> ResponseResult<DocDescription, EditorError> {
|
||||
let params: CreateDocParams = data.into_inner().try_into()?;
|
||||
let path = manager.read().unwrap().make_file_path(¶ms.id);
|
||||
@ -25,8 +25,8 @@ pub async fn create_doc(
|
||||
|
||||
pub async fn read_doc(
|
||||
data: Data<QueryDocRequest>,
|
||||
controller: ModuleData<DocController>,
|
||||
manager: ModuleData<RwLock<FileManager>>,
|
||||
controller: Unit<DocController>,
|
||||
manager: Unit<RwLock<FileManager>>,
|
||||
) -> ResponseResult<Doc, EditorError> {
|
||||
let params: QueryDocParams = data.into_inner().try_into()?;
|
||||
let desc = controller.read_doc(¶ms.doc_id).await?;
|
||||
@ -42,8 +42,8 @@ pub async fn read_doc(
|
||||
|
||||
pub async fn update_doc(
|
||||
data: Data<UpdateDocRequest>,
|
||||
controller: ModuleData<DocController>,
|
||||
manager: ModuleData<RwLock<FileManager>>,
|
||||
controller: Unit<DocController>,
|
||||
manager: Unit<RwLock<FileManager>>,
|
||||
) -> Result<(), EditorError> {
|
||||
let mut params: UpdateDocParams = data.into_inner().try_into()?;
|
||||
match params.content.take() {
|
||||
|
@ -12,7 +12,7 @@ use std::{convert::TryInto, sync::Arc};
|
||||
)]
|
||||
pub async fn user_sign_in_handler(
|
||||
data: Data<SignInRequest>,
|
||||
session: ModuleData<Arc<UserSession>>,
|
||||
session: Unit<Arc<UserSession>>,
|
||||
) -> ResponseResult<UserDetail, UserError> {
|
||||
let params: SignInParams = data.into_inner().try_into()?;
|
||||
let user = session.sign_in(params).await?;
|
||||
@ -30,7 +30,7 @@ pub async fn user_sign_in_handler(
|
||||
)]
|
||||
pub async fn user_sign_up_handler(
|
||||
data: Data<SignUpRequest>,
|
||||
session: ModuleData<Arc<UserSession>>,
|
||||
session: Unit<Arc<UserSession>>,
|
||||
) -> ResponseResult<UserDetail, UserError> {
|
||||
let params: SignUpParams = data.into_inner().try_into()?;
|
||||
let user = session.sign_up(params).await?;
|
||||
|
@ -3,20 +3,20 @@ use flowy_dispatch::prelude::*;
|
||||
use std::{convert::TryInto, sync::Arc};
|
||||
|
||||
pub async fn user_get_status_handler(
|
||||
session: ModuleData<Arc<UserSession>>,
|
||||
session: Unit<Arc<UserSession>>,
|
||||
) -> ResponseResult<UserDetail, UserError> {
|
||||
let user_detail = session.user_detail()?;
|
||||
response_ok(user_detail)
|
||||
}
|
||||
|
||||
pub async fn sign_out_handler(session: ModuleData<Arc<UserSession>>) -> Result<(), UserError> {
|
||||
pub async fn sign_out_handler(session: Unit<Arc<UserSession>>) -> Result<(), UserError> {
|
||||
let _ = session.sign_out()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn update_user_handler(
|
||||
data: Data<UpdateUserRequest>,
|
||||
session: ModuleData<Arc<UserSession>>,
|
||||
session: Unit<Arc<UserSession>>,
|
||||
) -> ResponseResult<UserDetail, UserError> {
|
||||
let params: UpdateUserParams = data.into_inner().try_into()?;
|
||||
let user_detail = session.update_user(params)?;
|
||||
|
@ -6,13 +6,13 @@ use crate::{
|
||||
errors::WorkspaceError,
|
||||
services::AppController,
|
||||
};
|
||||
use flowy_dispatch::prelude::{response_ok, Data, ModuleData, ResponseResult};
|
||||
use flowy_dispatch::prelude::{response_ok, Data, ResponseResult, Unit};
|
||||
use std::{convert::TryInto, sync::Arc};
|
||||
|
||||
#[tracing::instrument(name = "create_app", skip(data, controller))]
|
||||
pub async fn create_app(
|
||||
data: Data<CreateAppRequest>,
|
||||
controller: ModuleData<Arc<AppController>>,
|
||||
controller: Unit<Arc<AppController>>,
|
||||
) -> ResponseResult<App, WorkspaceError> {
|
||||
let params: CreateAppParams = data.into_inner().try_into()?;
|
||||
let detail = controller.create_app(params)?;
|
||||
@ -22,7 +22,7 @@ pub async fn create_app(
|
||||
#[tracing::instrument(name = "get_app", skip(data, controller))]
|
||||
pub async fn get_app(
|
||||
data: Data<QueryAppRequest>,
|
||||
controller: ModuleData<Arc<AppController>>,
|
||||
controller: Unit<Arc<AppController>>,
|
||||
) -> ResponseResult<App, WorkspaceError> {
|
||||
let params: QueryAppParams = data.into_inner().try_into()?;
|
||||
let mut app = controller.read_app(¶ms.app_id).await?;
|
||||
|
@ -3,12 +3,12 @@ use crate::{
|
||||
errors::WorkspaceError,
|
||||
services::ViewController,
|
||||
};
|
||||
use flowy_dispatch::prelude::{response_ok, Data, ModuleData, ResponseResult};
|
||||
use flowy_dispatch::prelude::{response_ok, Data, ResponseResult, Unit};
|
||||
use std::{convert::TryInto, sync::Arc};
|
||||
|
||||
pub async fn create_view(
|
||||
data: Data<CreateViewRequest>,
|
||||
controller: ModuleData<Arc<ViewController>>,
|
||||
controller: Unit<Arc<ViewController>>,
|
||||
) -> ResponseResult<View, WorkspaceError> {
|
||||
let params: CreateViewParams = data.into_inner().try_into()?;
|
||||
let view = controller.create_view(params).await?;
|
||||
|
@ -3,13 +3,13 @@ use crate::{
|
||||
errors::WorkspaceError,
|
||||
services::WorkspaceController,
|
||||
};
|
||||
use flowy_dispatch::prelude::{response_ok, Data, ModuleData, ResponseResult};
|
||||
use flowy_dispatch::prelude::{response_ok, Data, ResponseResult, Unit};
|
||||
use std::{convert::TryInto, sync::Arc};
|
||||
|
||||
#[tracing::instrument(name = "create_workspace", skip(data, controller))]
|
||||
pub async fn create_workspace(
|
||||
data: Data<CreateWorkspaceRequest>,
|
||||
controller: ModuleData<Arc<WorkspaceController>>,
|
||||
controller: Unit<Arc<WorkspaceController>>,
|
||||
) -> ResponseResult<Workspace, WorkspaceError> {
|
||||
let controller = controller.get_ref().clone();
|
||||
let params: CreateWorkspaceParams = data.into_inner().try_into()?;
|
||||
@ -19,7 +19,7 @@ pub async fn create_workspace(
|
||||
|
||||
#[tracing::instrument(name = "get_cur_workspace", skip(controller))]
|
||||
pub async fn get_cur_workspace(
|
||||
controller: ModuleData<Arc<WorkspaceController>>,
|
||||
controller: Unit<Arc<WorkspaceController>>,
|
||||
) -> ResponseResult<Workspace, WorkspaceError> {
|
||||
let workspace = controller.read_cur_workspace().await?;
|
||||
response_ok(workspace)
|
||||
@ -28,7 +28,7 @@ pub async fn get_cur_workspace(
|
||||
#[tracing::instrument(name = "get_workspace", skip(data, controller))]
|
||||
pub async fn get_workspace(
|
||||
data: Data<QueryWorkspaceRequest>,
|
||||
controller: ModuleData<Arc<WorkspaceController>>,
|
||||
controller: Unit<Arc<WorkspaceController>>,
|
||||
) -> ResponseResult<Workspace, WorkspaceError> {
|
||||
let params: QueryWorkspaceParams = data.into_inner().try_into()?;
|
||||
let mut workspace = controller.read_workspace(¶ms.workspace_id).await?;
|
||||
|
Loading…
Reference in New Issue
Block a user