Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: insert database row into selected database #1029

Merged
merged 39 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b7de5e9
feat: insert database row into selected database
speed2exe Nov 28, 2024
1600baf
feat: inserting database row
speed2exe Nov 28, 2024
739fef0
Merge branch 'main' into feat/insert-database-row
speed2exe Nov 28, 2024
fc0698d
feat: add impl for cell
speed2exe Nov 29, 2024
e2d68ae
feat: insert row selection and mulitselection
speed2exe Nov 30, 2024
7a3edeb
feat: support datetime field type
speed2exe Dec 2, 2024
6d5e4ed
fix: other fields like rich text
speed2exe Dec 2, 2024
d4986b4
feat: add database field server impl
speed2exe Dec 2, 2024
5c2ac03
feat: add client api and tests
speed2exe Dec 3, 2024
7122bfc
Merge branch 'main' into feat/insert-database-row
speed2exe Dec 3, 2024
b8e09c1
Merge branch 'main' into feat/insert-database-row
speed2exe Dec 4, 2024
99c0be5
Merge branch 'main' into feat/insert-database-row
speed2exe Dec 4, 2024
5d24f6f
feat: use to json value impl from collab
speed2exe Dec 4, 2024
6f1ba48
feat: use add database cell impl from collab
speed2exe Dec 4, 2024
67737cf
feat: update to latest collab
speed2exe Dec 5, 2024
84c0444
Merge branch 'main' into feat/insert-database-row
speed2exe Dec 5, 2024
f681279
chore: upgrade collab and fix tests
speed2exe Dec 5, 2024
c6b3981
chore: review issues
speed2exe Dec 6, 2024
879e5c7
chore: merge with main
speed2exe Dec 6, 2024
058e940
fix: code review feedback
speed2exe Dec 6, 2024
9cb8ea1
feat: filter only allow supported field types
speed2exe Dec 6, 2024
11743f7
feat: support more field types
speed2exe Dec 7, 2024
edb4769
feat: support created at and last modified
speed2exe Dec 9, 2024
4092301
chore: merge with main
speed2exe Dec 9, 2024
974b697
feat: add timestamp cell for created at and modified at fields
speed2exe Dec 9, 2024
26d80b9
Merge branch 'main' into feat/insert-database-row
speed2exe Dec 9, 2024
a9d0619
chore: linting and formatting
speed2exe Dec 9, 2024
fdb87d2
fix: add created at and last modified
speed2exe Dec 9, 2024
1c767ea
fix: ci add service dependency of appflowy cloud on admin frontend
speed2exe Dec 9, 2024
a85afa1
chore: trigger ci
speed2exe Dec 9, 2024
85ea7eb
feat: add logging for admin frontend client signin
speed2exe Dec 9, 2024
dca6345
fix: server logs if error
speed2exe Dec 9, 2024
2a5b643
fix: create admin confirmation without email
speed2exe Dec 9, 2024
fd015ee
fix: ci add service dependency of appflowy cloud on admin frontend
speed2exe Dec 9, 2024
ad733c2
fix: server logs if error
speed2exe Dec 9, 2024
e7739e4
Merge branch 'main' into feat/insert-database-row
speed2exe Dec 10, 2024
166d239
chore: update collab
speed2exe Dec 10, 2024
59a865c
chore: merge with main
speed2exe Dec 10, 2024
fa644cd
Merge branch 'main' into feat/insert-database-row
speed2exe Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,13 @@ lto = false # Disable Link-Time Optimization
[patch.crates-io]
# It's diffcult to resovle different version with the same crate used in AppFlowy Frontend and the Client-API crate.
# So using patch to workaround this issue.
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-importer = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bd61aebe485c2c15328c008154021a286c6da8c3" }
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bd61aebe485c2c15328c008154021a286c6da8c3" }
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bd61aebe485c2c15328c008154021a286c6da8c3" }
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bd61aebe485c2c15328c008154021a286c6da8c3" }
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bd61aebe485c2c15328c008154021a286c6da8c3" }
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bd61aebe485c2c15328c008154021a286c6da8c3" }
collab-importer = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bd61aebe485c2c15328c008154021a286c6da8c3" }

[features]
history = []
Expand Down
52 changes: 50 additions & 2 deletions libs/client-api/src/http_collab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use app_error::AppError;
use bytes::Bytes;
use chrono::{DateTime, Utc};
use client_api_entity::workspace_dto::{
AFDatabase, AFDatabaseField, AFDatabaseRow, AFDatabaseRowDetail, DatabaseRowUpdatedItem,
ListDatabaseRowDetailParam, ListDatabaseRowUpdatedParam,
AFDatabase, AFDatabaseField, AFDatabaseRow, AFDatabaseRowDetail, AFInsertDatabaseField,
DatabaseRowUpdatedItem, ListDatabaseRowDetailParam, ListDatabaseRowUpdatedParam,
};
use client_api_entity::{
BatchQueryCollabParams, BatchQueryCollabResult, CollabParams, CreateCollabParams,
Expand Down Expand Up @@ -210,6 +210,28 @@ impl Client {
AppResponse::from_response(resp).await?.into_data()
}

// Adds a database field to the specified database.
// Returns the field id of the newly created field.
pub async fn add_database_field(
&self,
workspace_id: &str,
database_id: &str,
insert_field: &AFInsertDatabaseField,
) -> Result<String, AppResponseError> {
let url = format!(
"{}/api/workspace/{}/database/{}/fields",
self.base_url, workspace_id, database_id
);
let resp = self
.http_client_with_auth(Method::POST, &url)
.await?
.json(insert_field)
.send()
.await?;
log_request_id(&resp);
AppResponse::from_response(resp).await?.into_data()
}

pub async fn list_database_row_ids_updated(
&self,
workspace_id: &str,
Expand Down Expand Up @@ -250,6 +272,32 @@ impl Client {
AppResponse::from_response(resp).await?.into_data()
}

/// Example payload:
/// {
/// "Name": "some_data", # using column name
/// "_pIkG": "some other data" # using field_id (can be obtained from [get_database_fields])
/// }
/// Upon success, returns the row id for the newly created row.
pub async fn add_database_item(
&self,
workspace_id: &str,
database_id: &str,
payload: &serde_json::Value,
) -> Result<String, AppResponseError> {
let url = format!(
"{}/api/workspace/{}/database/{}/row",
self.base_url, workspace_id, database_id
);
let resp = self
.http_client_with_auth(Method::POST, &url)
.await?
.json(&payload)
.send()
.await?;
log_request_id(&resp);
AppResponse::from_response(resp).await?.into_data()
}

#[instrument(level = "debug", skip_all, err)]
pub async fn post_realtime_msg(
&self,
Expand Down
7 changes: 7 additions & 0 deletions libs/shared-entity/src/dto/workspace_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,10 @@ pub struct AFDatabaseField {
pub type_option: HashMap<String, serde_json::Value>,
pub is_primary: bool,
}

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct AFInsertDatabaseField {
pub name: String,
pub field_type: i64, // FieldType ID
pub type_option_data: Option<serde_json::Value>, // TypeOptionData
}
2 changes: 1 addition & 1 deletion services/appflowy-collaborate/src/group/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ where
)
.await?,
);
self.state.insert_group(object_id, group.clone()).await;
self.state.insert_group(object_id, group).await;
Ok(())
}
}
Expand Down
58 changes: 56 additions & 2 deletions src/api/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use futures_util::future::try_join_all;
use prost::Message as ProstMessage;
use rayon::prelude::*;
use sqlx::types::uuid;
use std::collections::HashMap;
use std::time::Instant;

use tokio_stream::StreamExt;
Expand Down Expand Up @@ -259,11 +260,13 @@ pub fn workspace_scope() -> Scope {
.service(web::resource("/{workspace_id}/database").route(web::get().to(list_database_handler)))
.service(
web::resource("/{workspace_id}/database/{database_id}/row")
.route(web::get().to(list_database_row_id_handler)),
.route(web::get().to(list_database_row_id_handler))
.route(web::post().to(post_database_row_handler)),
)
.service(
web::resource("/{workspace_id}/database/{database_id}/fields")
.route(web::get().to(get_database_fields_handler)),
.route(web::get().to(get_database_fields_handler))
.route(web::post().to(post_database_fields_handler)),
)
.service(
web::resource("/{workspace_id}/database/{database_id}/row/updated")
Expand Down Expand Up @@ -1919,6 +1922,31 @@ async fn list_database_row_id_handler(
Ok(Json(AppResponse::Ok().with_data(db_rows)))
}

async fn post_database_row_handler(
user_uuid: UserUuid,
path_param: web::Path<(String, String)>,
state: Data<AppState>,
cells_by_id: Json<HashMap<String, serde_json::Value>>,
) -> Result<Json<AppResponse<String>>> {
let (workspace_id, db_id) = path_param.into_inner();
let uid = state.user_cache.get_user_uid(&user_uuid).await?;
state
.workspace_access_control
.enforce_action(&uid, &workspace_id, Action::Write)
.await?;

let new_db_row_id = biz::collab::ops::insert_database_row(
&state.collab_access_control_storage,
&state.pg_pool,
&workspace_id,
&db_id,
uid,
cells_by_id.into_inner(),
)
.await?;
Ok(Json(AppResponse::Ok().with_data(new_db_row_id)))
}

async fn get_database_fields_handler(
user_uuid: UserUuid,
path_param: web::Path<(String, String)>,
Expand All @@ -1941,6 +1969,32 @@ async fn get_database_fields_handler(
Ok(Json(AppResponse::Ok().with_data(db_fields)))
}

async fn post_database_fields_handler(
user_uuid: UserUuid,
path_param: web::Path<(String, String)>,
state: Data<AppState>,
field: Json<AFInsertDatabaseField>,
) -> Result<Json<AppResponse<String>>> {
let (workspace_id, db_id) = path_param.into_inner();
let uid = state.user_cache.get_user_uid(&user_uuid).await?;
state
.workspace_access_control
.enforce_action(&uid, &workspace_id, Action::Write)
.await?;

let field_id = biz::collab::ops::add_database_field(
uid,
&state.collab_access_control_storage,
&state.pg_pool,
&workspace_id,
&db_id,
field.into_inner(),
)
.await?;

Ok(Json(AppResponse::Ok().with_data(field_id)))
}

async fn list_database_row_id_updated_handler(
user_uuid: UserUuid,
path_param: web::Path<(String, String)>,
Expand Down
1 change: 1 addition & 0 deletions src/biz/collab/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod folder_view;
pub mod ops;
pub mod publish_outline;
pub mod utils;
Loading
Loading