[server]: trash table and create params

This commit is contained in:
appflowy
2021-10-15 15:52:08 +08:00
parent dfd6046214
commit 8e40ae60e6
43 changed files with 666 additions and 345 deletions

View File

@ -0,0 +1,6 @@
-- Add migration script here
CREATE TABLE IF NOT EXISTS trash_table(
id uuid NOT NULL,
PRIMARY KEY (id),
ty INTEGER NOT NULL DEFAULT 0
);

View File

@ -16,6 +16,7 @@ use crate::{
service::{
app::router as app,
doc::router as doc,
trash::router as trash,
user::router as user,
view::router as view,
workspace::router as workspace,
@ -118,6 +119,11 @@ fn user_scope() -> Scope {
.route(web::get().to(doc::read_handler))
.route(web::patch().to(doc::update_handler))
)
.service(web::resource("/trash")
.route(web::post().to(trash::create_handler))
.route(web::delete().to(trash::delete_handler))
.route(web::get().to(trash::read_handler))
)
// password
.service(web::resource("/password_change")
.route(web::post().to(user::change_password))

View File

@ -3,7 +3,7 @@ use crate::{
sqlx_ext::{map_sqlx_error, DBTransaction, SqlBuilder},
};
use anyhow::Context;
use flowy_document::protobuf::{CreateDocParams, Doc, QueryDocParams, UpdateDocParams};
use flowy_document::protobuf::{CreateDocParams, Doc, DocIdentifier, UpdateDocParams};
use flowy_net::errors::ServerError;
use sqlx::{postgres::PgArguments, PgPool, Postgres};
use uuid::Uuid;
@ -24,7 +24,7 @@ pub(crate) async fn create_doc(
}
#[tracing::instrument(level = "debug", skip(pool), err)]
pub(crate) async fn read_doc(pool: &PgPool, params: QueryDocParams) -> Result<Doc, ServerError> {
pub(crate) async fn read_doc(pool: &PgPool, params: DocIdentifier) -> Result<Doc, ServerError> {
let doc_id = Uuid::parse_str(&params.doc_id)?;
let mut transaction = pool
.begin()

View File

@ -8,7 +8,7 @@ use crate::service::{
};
use actix_web::web::Data;
use dashmap::DashMap;
use flowy_document::protobuf::QueryDocParams;
use flowy_document::protobuf::DocIdentifier;
use flowy_net::errors::{internal_error, ServerError};
use sqlx::PgPool;
use std::sync::Arc;
@ -71,7 +71,7 @@ impl DocManager {
pub async fn get(&self, doc_id: &str, pg_pool: Data<PgPool>) -> Result<Option<Arc<DocHandle>>, ServerError> {
match self.docs_map.get(doc_id) {
None => {
let params = QueryDocParams {
let params = DocIdentifier {
doc_id: doc_id.to_string(),
..Default::default()
};

View File

@ -7,7 +7,7 @@ use actix_web::{
HttpResponse,
};
use anyhow::Context;
use flowy_document::protobuf::{CreateDocParams, QueryDocParams, UpdateDocParams};
use flowy_document::protobuf::{CreateDocParams, DocIdentifier, UpdateDocParams};
use flowy_net::{errors::ServerError, response::FlowyResponse};
use sqlx::PgPool;
@ -31,7 +31,7 @@ pub async fn create_handler(payload: Payload, pool: Data<PgPool>) -> Result<Http
#[tracing::instrument(level = "debug", skip(payload, pool), err)]
pub async fn read_handler(payload: Payload, pool: Data<PgPool>) -> Result<HttpResponse, ServerError> {
let params: QueryDocParams = parse_from_payload(payload).await?;
let params: DocIdentifier = parse_from_payload(payload).await?;
let doc = read_doc(pool.get_ref(), params).await?;
let response = FlowyResponse::success().pb(doc)?;
Ok(response.into())

View File

@ -1,6 +1,7 @@
pub mod app;
pub mod doc;
pub(crate) mod log;
pub mod trash;
pub mod user;
pub(crate) mod util;
pub mod view;

View File

@ -0,0 +1,4 @@
pub mod router;
mod trash;
pub(crate) use trash::*;

View File

@ -0,0 +1,23 @@
use crate::service::util::parse_from_payload;
use actix_web::{
web::{Data, Payload},
HttpResponse,
};
use flowy_net::errors::ServerError;
use flowy_workspace::protobuf::{Trash, TrashIdentifiers};
use sqlx::PgPool;
pub async fn create_handler(payload: Payload, _pool: Data<PgPool>) -> Result<HttpResponse, ServerError> {
let _params: Trash = parse_from_payload(payload).await?;
unimplemented!()
}
pub async fn delete_handler(payload: Payload, _pool: Data<PgPool>) -> Result<HttpResponse, ServerError> {
let _params: TrashIdentifiers = parse_from_payload(payload).await?;
unimplemented!()
}
pub async fn read_handler(payload: Payload, _pool: Data<PgPool>) -> Result<HttpResponse, ServerError> {
let _params: TrashIdentifiers = parse_from_payload(payload).await?;
unimplemented!()
}

View File

@ -0,0 +1,18 @@
use anyhow::Context;
use flowy_net::{errors::ServerError, response::FlowyResponse};
use flowy_workspace::protobuf::Trash;
use sqlx::PgPool;
pub(crate) async fn create_trash(pool: &PgPool, _params: Trash) -> Result<FlowyResponse, ServerError> {
let transaction = pool
.begin()
.await
.context("Failed to acquire a Postgres connection to create trash")?;
transaction
.commit()
.await
.context("Failed to commit SQL transaction to trash view.")?;
Ok(FlowyResponse::success())
}

View File

@ -2,10 +2,9 @@ use actix_web::{
web::{Data, Payload},
HttpResponse,
};
use sqlx::PgPool;
use flowy_net::errors::ServerError;
use flowy_workspace::protobuf::{CreateViewParams, DeleteViewParams, QueryViewParams, UpdateViewParams};
use sqlx::PgPool;
use crate::service::{
doc::doc::DocBiz,

View File

@ -1,12 +1,12 @@
use crate::helper::ViewTest;
use flowy_document::entities::doc::QueryDocParams;
use flowy_document::entities::doc::DocIdentifier;
use flowy_workspace::entities::view::DeleteViewParams;
#[actix_rt::test]
async fn doc_read() {
let test = ViewTest::new().await;
let params = QueryDocParams {
let params = DocIdentifier {
doc_id: test.view.id.clone(),
};
@ -22,7 +22,7 @@ async fn doc_delete() {
};
test.server.delete_view(delete_params).await;
let params = QueryDocParams {
let params = DocIdentifier {
doc_id: test.view.id.clone(),
};
let doc = test.server.read_doc(params).await;

View File

@ -6,7 +6,7 @@ use sqlx::PgPool;
use tokio::time::{sleep, Duration};
use backend::service::doc::{crud::update_doc, doc::DocManager};
use flowy_document::{entities::doc::QueryDocParams, services::doc::edit::ClientEditDoc as ClientEditDocContext};
use flowy_document::{entities::doc::DocIdentifier, services::doc::edit::ClientEditDoc as ClientEditDocContext};
use flowy_net::config::ServerConfig;
use flowy_test::{workspace::ViewTest, FlowyTest};
use flowy_user::services::user::UserSession;
@ -80,7 +80,7 @@ impl ScriptContext {
let pool = self.client_user_session.db_pool().unwrap();
let doc_id = self.doc_id.clone();
let edit_context = flowy_document.open(QueryDocParams { doc_id }, pool).await.unwrap();
let edit_context = flowy_document.open(DocIdentifier { doc_id }, pool).await.unwrap();
self.client_edit_context = Some(edit_context);
}

View File

@ -6,7 +6,7 @@ use backend::{
use backend::application::init_app_context;
use flowy_document::{
entities::doc::{Doc, QueryDocParams},
entities::doc::{Doc, DocIdentifier},
prelude::*,
};
use flowy_user::{errors::UserError, prelude::*};
@ -122,7 +122,7 @@ impl TestUserServer {
delete_view_request(self.user_token(), params, &url).await.unwrap();
}
pub async fn read_doc(&self, params: QueryDocParams) -> Option<Doc> {
pub async fn read_doc(&self, params: DocIdentifier) -> Option<Doc> {
let url = format!("{}/api/doc", self.http_addr());
let doc = read_doc_request(self.user_token(), params, &url).await.unwrap();
doc