mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
refactor: replace object with object's revision entity
This commit is contained in:
@ -4,13 +4,14 @@ use crate::{
|
||||
};
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_folder_data_model::entities::{
|
||||
app::{App, AppId, CreateAppParams, UpdateAppParams},
|
||||
trash::{RepeatedTrash, RepeatedTrashId},
|
||||
view::{CreateViewParams, RepeatedViewId, UpdateViewParams, View, ViewId},
|
||||
workspace::{CreateWorkspaceParams, RepeatedWorkspace, UpdateWorkspaceParams, Workspace, WorkspaceId},
|
||||
trash::RepeatedTrashId,
|
||||
view::{CreateViewParams, RepeatedViewId, UpdateViewParams, ViewId},
|
||||
workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceId},
|
||||
{AppId, CreateAppParams, UpdateAppParams},
|
||||
};
|
||||
|
||||
use flowy_folder::event_map::FolderCouldServiceV1;
|
||||
use flowy_folder_data_model::revision::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
|
||||
use http_flowy::errors::ServerError;
|
||||
use http_flowy::response::FlowyResponse;
|
||||
use lazy_static::lazy_static;
|
||||
@ -31,7 +32,11 @@ impl FolderHttpCloudService {
|
||||
impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
fn init(&self) {}
|
||||
|
||||
fn create_workspace(&self, token: &str, params: CreateWorkspaceParams) -> FutureResult<Workspace, FlowyError> {
|
||||
fn create_workspace(
|
||||
&self,
|
||||
token: &str,
|
||||
params: CreateWorkspaceParams,
|
||||
) -> FutureResult<WorkspaceRevision, FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.workspace_url();
|
||||
FutureResult::new(async move {
|
||||
@ -40,12 +45,12 @@ impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn read_workspace(&self, token: &str, params: WorkspaceId) -> FutureResult<RepeatedWorkspace, FlowyError> {
|
||||
fn read_workspace(&self, token: &str, params: WorkspaceId) -> FutureResult<Vec<WorkspaceRevision>, FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.workspace_url();
|
||||
FutureResult::new(async move {
|
||||
let repeated_workspace = read_workspaces_request(&token, params, &url).await?;
|
||||
Ok(repeated_workspace)
|
||||
let workspace_revs = read_workspaces_request(&token, params, &url).await?;
|
||||
Ok(workspace_revs)
|
||||
})
|
||||
}
|
||||
|
||||
@ -67,7 +72,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn create_view(&self, token: &str, params: CreateViewParams) -> FutureResult<View, FlowyError> {
|
||||
fn create_view(&self, token: &str, params: CreateViewParams) -> FutureResult<ViewRevision, FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.view_url();
|
||||
FutureResult::new(async move {
|
||||
@ -76,12 +81,12 @@ impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn read_view(&self, token: &str, params: ViewId) -> FutureResult<Option<View>, FlowyError> {
|
||||
fn read_view(&self, token: &str, params: ViewId) -> FutureResult<Option<ViewRevision>, FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.view_url();
|
||||
FutureResult::new(async move {
|
||||
let view = read_view_request(&token, params, &url).await?;
|
||||
Ok(view)
|
||||
let view_rev = read_view_request(&token, params, &url).await?;
|
||||
Ok(view_rev)
|
||||
})
|
||||
}
|
||||
|
||||
@ -103,7 +108,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn create_app(&self, token: &str, params: CreateAppParams) -> FutureResult<App, FlowyError> {
|
||||
fn create_app(&self, token: &str, params: CreateAppParams) -> FutureResult<AppRevision, FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.app_url();
|
||||
FutureResult::new(async move {
|
||||
@ -112,12 +117,12 @@ impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn read_app(&self, token: &str, params: AppId) -> FutureResult<Option<App>, FlowyError> {
|
||||
fn read_app(&self, token: &str, params: AppId) -> FutureResult<Option<AppRevision>, FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.app_url();
|
||||
FutureResult::new(async move {
|
||||
let app = read_app_request(&token, params, &url).await?;
|
||||
Ok(app)
|
||||
let app_rev = read_app_request(&token, params, &url).await?;
|
||||
Ok(app_rev)
|
||||
})
|
||||
}
|
||||
|
||||
@ -157,7 +162,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn read_trash(&self, token: &str) -> FutureResult<RepeatedTrash, FlowyError> {
|
||||
fn read_trash(&self, token: &str) -> FutureResult<Vec<TrashRevision>, FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.trash_url();
|
||||
FutureResult::new(async move {
|
||||
@ -172,32 +177,34 @@ fn request_builder() -> HttpRequestBuilder {
|
||||
}
|
||||
|
||||
pub async fn create_workspace_request(
|
||||
token: &str,
|
||||
params: CreateWorkspaceParams,
|
||||
url: &str,
|
||||
) -> Result<Workspace, ServerError> {
|
||||
let workspace = request_builder()
|
||||
.post(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
.protobuf(params)?
|
||||
.response()
|
||||
.await?;
|
||||
Ok(workspace)
|
||||
_token: &str,
|
||||
_params: CreateWorkspaceParams,
|
||||
_url: &str,
|
||||
) -> Result<WorkspaceRevision, ServerError> {
|
||||
// let workspace = request_builder()
|
||||
// .post(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
// .protobuf(params)?
|
||||
// .response()
|
||||
// .await?;
|
||||
// Ok(workspace)
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub async fn read_workspaces_request(
|
||||
token: &str,
|
||||
params: WorkspaceId,
|
||||
url: &str,
|
||||
) -> Result<RepeatedWorkspace, ServerError> {
|
||||
let repeated_workspace = request_builder()
|
||||
.get(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
.protobuf(params)?
|
||||
.response::<RepeatedWorkspace>()
|
||||
.await?;
|
||||
|
||||
Ok(repeated_workspace)
|
||||
_token: &str,
|
||||
_params: WorkspaceId,
|
||||
_url: &str,
|
||||
) -> Result<Vec<WorkspaceRevision>, ServerError> {
|
||||
// let repeated_workspace = request_builder()
|
||||
// .get(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
// .protobuf(params)?
|
||||
// .response::<RepeatedWorkspace>()
|
||||
// .await?;
|
||||
//
|
||||
// Ok(repeated_workspace)
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub async fn update_workspace_request(
|
||||
@ -225,25 +232,31 @@ pub async fn delete_workspace_request(token: &str, params: WorkspaceId, url: &st
|
||||
}
|
||||
|
||||
// App
|
||||
pub async fn create_app_request(token: &str, params: CreateAppParams, url: &str) -> Result<App, ServerError> {
|
||||
let app = request_builder()
|
||||
.post(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
.protobuf(params)?
|
||||
.response()
|
||||
.await?;
|
||||
Ok(app)
|
||||
pub async fn create_app_request(
|
||||
_token: &str,
|
||||
_params: CreateAppParams,
|
||||
_url: &str,
|
||||
) -> Result<AppRevision, ServerError> {
|
||||
// let app = request_builder()
|
||||
// .post(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
// .protobuf(params)?
|
||||
// .response()
|
||||
// .await?;
|
||||
// Ok(app)
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub async fn read_app_request(token: &str, params: AppId, url: &str) -> Result<Option<App>, ServerError> {
|
||||
let app = request_builder()
|
||||
.get(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
.protobuf(params)?
|
||||
.option_response()
|
||||
.await?;
|
||||
pub async fn read_app_request(_token: &str, _params: AppId, _url: &str) -> Result<Option<AppRevision>, ServerError> {
|
||||
// let app = request_builder()
|
||||
// .get(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
// .protobuf(params)?
|
||||
// .option_response()
|
||||
// .await?;
|
||||
// Ok(app)
|
||||
|
||||
Ok(app)
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub async fn update_app_request(token: &str, params: UpdateAppParams, url: &str) -> Result<(), ServerError> {
|
||||
@ -267,25 +280,31 @@ pub async fn delete_app_request(token: &str, params: AppId, url: &str) -> Result
|
||||
}
|
||||
|
||||
// View
|
||||
pub async fn create_view_request(token: &str, params: CreateViewParams, url: &str) -> Result<View, ServerError> {
|
||||
let view = request_builder()
|
||||
.post(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
.protobuf(params)?
|
||||
.response()
|
||||
.await?;
|
||||
Ok(view)
|
||||
pub async fn create_view_request(
|
||||
_token: &str,
|
||||
_params: CreateViewParams,
|
||||
_url: &str,
|
||||
) -> Result<ViewRevision, ServerError> {
|
||||
// let view = request_builder()
|
||||
// .post(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
// .protobuf(params)?
|
||||
// .response()
|
||||
// .await?;
|
||||
// Ok(view)
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub async fn read_view_request(token: &str, params: ViewId, url: &str) -> Result<Option<View>, ServerError> {
|
||||
let view = request_builder()
|
||||
.get(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
.protobuf(params)?
|
||||
.option_response()
|
||||
.await?;
|
||||
|
||||
Ok(view)
|
||||
pub async fn read_view_request(_token: &str, _params: ViewId, _url: &str) -> Result<Option<ViewRevision>, ServerError> {
|
||||
// let view = request_builder()
|
||||
// .get(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
// .protobuf(params)?
|
||||
// .option_response()
|
||||
// .await?;
|
||||
//
|
||||
// Ok(view)
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub async fn update_view_request(token: &str, params: UpdateViewParams, url: &str) -> Result<(), ServerError> {
|
||||
@ -328,13 +347,14 @@ pub async fn delete_trash_request(token: &str, params: RepeatedTrashId, url: &st
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn read_trash_request(token: &str, url: &str) -> Result<RepeatedTrash, ServerError> {
|
||||
let repeated_trash = request_builder()
|
||||
.get(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
.response::<RepeatedTrash>()
|
||||
.await?;
|
||||
Ok(repeated_trash)
|
||||
pub async fn read_trash_request(_token: &str, _url: &str) -> Result<Vec<TrashRevision>, ServerError> {
|
||||
// let repeated_trash = request_builder()
|
||||
// .get(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
// .response::<RepeatedTrash>()
|
||||
// .await?;
|
||||
// Ok(repeated_trash)
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
|
@ -255,11 +255,12 @@ impl RevisionUser for LocalRevisionUser {
|
||||
use flowy_folder_data_model::entities::app::gen_app_id;
|
||||
use flowy_folder_data_model::entities::workspace::gen_workspace_id;
|
||||
use flowy_folder_data_model::entities::{
|
||||
app::{App, AppId, CreateAppParams, RepeatedApp, UpdateAppParams},
|
||||
trash::{RepeatedTrash, RepeatedTrashId},
|
||||
view::{CreateViewParams, RepeatedView, RepeatedViewId, UpdateViewParams, View, ViewId},
|
||||
workspace::{CreateWorkspaceParams, RepeatedWorkspace, UpdateWorkspaceParams, Workspace, WorkspaceId},
|
||||
app::{AppId, CreateAppParams, UpdateAppParams},
|
||||
trash::RepeatedTrashId,
|
||||
view::{CreateViewParams, RepeatedViewId, UpdateViewParams, ViewId},
|
||||
workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceId},
|
||||
};
|
||||
use flowy_folder_data_model::revision::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
|
||||
use flowy_text_block::BlockCloudService;
|
||||
use flowy_user::event_map::UserCloudService;
|
||||
use flowy_user_data_model::entities::{
|
||||
@ -270,13 +271,17 @@ use lib_infra::{future::FutureResult, util::timestamp};
|
||||
impl FolderCouldServiceV1 for LocalServer {
|
||||
fn init(&self) {}
|
||||
|
||||
fn create_workspace(&self, _token: &str, params: CreateWorkspaceParams) -> FutureResult<Workspace, FlowyError> {
|
||||
fn create_workspace(
|
||||
&self,
|
||||
_token: &str,
|
||||
params: CreateWorkspaceParams,
|
||||
) -> FutureResult<WorkspaceRevision, FlowyError> {
|
||||
let time = timestamp();
|
||||
let workspace = Workspace {
|
||||
let workspace = WorkspaceRevision {
|
||||
id: gen_workspace_id(),
|
||||
name: params.name,
|
||||
desc: params.desc,
|
||||
apps: RepeatedApp::default(),
|
||||
apps: vec![],
|
||||
modified_time: time,
|
||||
create_time: time,
|
||||
};
|
||||
@ -284,11 +289,8 @@ impl FolderCouldServiceV1 for LocalServer {
|
||||
FutureResult::new(async { Ok(workspace) })
|
||||
}
|
||||
|
||||
fn read_workspace(&self, _token: &str, _params: WorkspaceId) -> FutureResult<RepeatedWorkspace, FlowyError> {
|
||||
FutureResult::new(async {
|
||||
let repeated_workspace = RepeatedWorkspace { items: vec![] };
|
||||
Ok(repeated_workspace)
|
||||
})
|
||||
fn read_workspace(&self, _token: &str, _params: WorkspaceId) -> FutureResult<Vec<WorkspaceRevision>, FlowyError> {
|
||||
FutureResult::new(async { Ok(vec![]) })
|
||||
}
|
||||
|
||||
fn update_workspace(&self, _token: &str, _params: UpdateWorkspaceParams) -> FutureResult<(), FlowyError> {
|
||||
@ -299,16 +301,16 @@ impl FolderCouldServiceV1 for LocalServer {
|
||||
FutureResult::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
fn create_view(&self, _token: &str, params: CreateViewParams) -> FutureResult<View, FlowyError> {
|
||||
fn create_view(&self, _token: &str, params: CreateViewParams) -> FutureResult<ViewRevision, FlowyError> {
|
||||
let time = timestamp();
|
||||
let view = View {
|
||||
let view = ViewRevision {
|
||||
id: params.view_id,
|
||||
belong_to_id: params.belong_to_id,
|
||||
name: params.name,
|
||||
desc: params.desc,
|
||||
data_type: params.data_type,
|
||||
version: 0,
|
||||
belongings: RepeatedView::default(),
|
||||
belongings: vec![],
|
||||
modified_time: time,
|
||||
create_time: time,
|
||||
ext_data: "".to_string(),
|
||||
@ -318,7 +320,7 @@ impl FolderCouldServiceV1 for LocalServer {
|
||||
FutureResult::new(async { Ok(view) })
|
||||
}
|
||||
|
||||
fn read_view(&self, _token: &str, _params: ViewId) -> FutureResult<Option<View>, FlowyError> {
|
||||
fn read_view(&self, _token: &str, _params: ViewId) -> FutureResult<Option<ViewRevision>, FlowyError> {
|
||||
FutureResult::new(async { Ok(None) })
|
||||
}
|
||||
|
||||
@ -330,14 +332,14 @@ impl FolderCouldServiceV1 for LocalServer {
|
||||
FutureResult::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
fn create_app(&self, _token: &str, params: CreateAppParams) -> FutureResult<App, FlowyError> {
|
||||
fn create_app(&self, _token: &str, params: CreateAppParams) -> FutureResult<AppRevision, FlowyError> {
|
||||
let time = timestamp();
|
||||
let app = App {
|
||||
let app = AppRevision {
|
||||
id: gen_app_id(),
|
||||
workspace_id: params.workspace_id,
|
||||
name: params.name,
|
||||
desc: params.desc,
|
||||
belongings: RepeatedView::default(),
|
||||
belongings: vec![],
|
||||
version: 0,
|
||||
modified_time: time,
|
||||
create_time: time,
|
||||
@ -345,7 +347,7 @@ impl FolderCouldServiceV1 for LocalServer {
|
||||
FutureResult::new(async { Ok(app) })
|
||||
}
|
||||
|
||||
fn read_app(&self, _token: &str, _params: AppId) -> FutureResult<Option<App>, FlowyError> {
|
||||
fn read_app(&self, _token: &str, _params: AppId) -> FutureResult<Option<AppRevision>, FlowyError> {
|
||||
FutureResult::new(async { Ok(None) })
|
||||
}
|
||||
|
||||
@ -365,17 +367,14 @@ impl FolderCouldServiceV1 for LocalServer {
|
||||
FutureResult::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
fn read_trash(&self, _token: &str) -> FutureResult<RepeatedTrash, FlowyError> {
|
||||
FutureResult::new(async {
|
||||
let repeated_trash = RepeatedTrash { items: vec![] };
|
||||
Ok(repeated_trash)
|
||||
})
|
||||
fn read_trash(&self, _token: &str) -> FutureResult<Vec<TrashRevision>, FlowyError> {
|
||||
FutureResult::new(async { Ok(vec![]) })
|
||||
}
|
||||
}
|
||||
|
||||
impl UserCloudService for LocalServer {
|
||||
fn sign_up(&self, params: SignUpParams) -> FutureResult<SignUpResponse, FlowyError> {
|
||||
let uid = nanoid!(10);
|
||||
let uid = nanoid!(20);
|
||||
FutureResult::new(async move {
|
||||
Ok(SignUpResponse {
|
||||
user_id: uid.clone(),
|
||||
@ -387,7 +386,7 @@ impl UserCloudService for LocalServer {
|
||||
}
|
||||
|
||||
fn sign_in(&self, params: SignInParams) -> FutureResult<SignInResponse, FlowyError> {
|
||||
let user_id = nanoid!(10);
|
||||
let user_id = nanoid!(20);
|
||||
FutureResult::new(async {
|
||||
Ok(SignInResponse {
|
||||
user_id: user_id.clone(),
|
||||
|
Reference in New Issue
Block a user