Skip to content

Commit

Permalink
Make compatible with EdgeDB v5
Browse files Browse the repository at this point in the history
  • Loading branch information
hongquan committed Sep 23, 2024
1 parent 0f14cd3 commit e9daf19
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 265 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quanweb"
version = "1.3.0"
version = "1.4.0"
edition = "2021"
rust-version = "1.76"
default-run = "quanweb"
Expand Down Expand Up @@ -59,6 +59,7 @@ serde-value = "0.7.0"
serde_json = "1.0.127"
serde_json5 = "0.1.0"
serde_with = "3.9.0"
smallvec = "1.13.2"
smart-default = "0.7.1"
str-macro = "1.0.0"
strum = { version = "0.26.3", features = ["derive", "strum_macros"] }
Expand Down
2 changes: 1 addition & 1 deletion src/api/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum ApiError {

impl IntoResponse for ApiError {
fn into_response(self) -> axum::response::Response {
tracing::debug!("To convert ApiError: {:?}", self);
tracing::debug!("To convert ApiError: {:#?}", self);
let (status, message) = match self {
Self::PathRejection(path_rejection) => {
(StatusCode::NOT_FOUND, path_rejection.body_text())
Expand Down
8 changes: 4 additions & 4 deletions src/api/minors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub async fn update_presentation_partial(
serde_json::from_value(value).map_err(ApiError::JsonExtractionError)?;
let submitted_fields: Vec<&String> = jdata.keys().collect();
let set_clause = patch_data.gen_set_clause(&submitted_fields);
let args = patch_data.make_edgedb_object(id, &submitted_fields);
let args = patch_data.make_edgedb_args(id, &submitted_fields);
let q = format!(
"SELECT (
UPDATE Presentation FILTER .id = <uuid>$id SET {{ {set_clause} }}
Expand Down Expand Up @@ -118,7 +118,7 @@ pub async fn create_presentation(
serde_json::from_value(value).map_err(ApiError::JsonExtractionError)?;
post_data.validify().map_err(ApiError::ValidationErrors)?;
let set_clause = post_data.gen_set_clause();
let args = post_data.make_edgedb_object();
let args = post_data.make_edgedb_args();
let q = format!(
"
SELECT (
Expand Down Expand Up @@ -329,7 +329,7 @@ pub async fn update_book_partial(
patch_data.validify().map_err(ApiError::ValidationErrors)?;
let submitted_fields: Vec<&String> = jdata.keys().collect();
let set_clause = patch_data.gen_set_clause(&submitted_fields);
let args = patch_data.make_edgedb_object(id, &submitted_fields);
let args = patch_data.make_edgedb_args(id, &submitted_fields);
let q = format!(
"SELECT (
UPDATE Book FILTER .id = <uuid>$id SET {{ {set_clause} }}
Expand Down Expand Up @@ -367,7 +367,7 @@ pub async fn create_book(
serde_json::from_value(value).map_err(ApiError::JsonExtractionError)?;
post_data.validify().map_err(ApiError::ValidationErrors)?;
let set_clause = post_data.gen_set_clause();
let args = post_data.make_edgedb_object();
let args = post_data.make_edgedb_args();
let q = format!(
"
SELECT (
Expand Down
15 changes: 8 additions & 7 deletions src/api/posts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use axum::{http::StatusCode, response::Result as AxumResult, Json};
use axum_extra::extract::WithRejection;
use edgedb_tokio::Client as EdgeClient;
use serde_json::{Map as JMap, Value};
use tracing::debug;
use uuid::Uuid;
use validify::Validify;

Expand Down Expand Up @@ -35,13 +36,13 @@ pub async fn list_posts(
let search_tokens = split_search_query(other_query.q.as_deref());
let lower_search_tokens: Option<Vec<String>> =
search_tokens.map(|v| v.into_iter().map(|s| s.to_lowercase()).collect());
let count = stores::blog::count_search_result_posts(lower_search_tokens.as_ref(), &db)
.await
.map_err(ApiError::EdgeDBQueryError)?;
let posts =
stores::blog::get_blogposts(lower_search_tokens.as_ref(), Some(offset), Some(limit), &db)
.await
.map_err(ApiError::EdgeDBQueryError)?;
let count = stores::blog::count_search_result_posts(lower_search_tokens.as_ref(), &db)
.await
.map_err(ApiError::EdgeDBQueryError)?;
let total_pages =
NonZeroU16::new((count as f64 / per_page as f64).ceil() as u16).unwrap_or(NonZeroU16::MIN);
let links = gen_pagination_links(&paging, count, original_uri);
Expand Down Expand Up @@ -105,7 +106,7 @@ pub async fn update_post_partial(
let submitted_fields: Vec<&String> = jdata.keys().collect();
let set_clause = patch_data.gen_set_clause(&submitted_fields);
let fields = DetailedBlogPost::fields_as_shape();
let args = patch_data.make_edgedb_object(post_id, &submitted_fields);
let args = patch_data.make_edgedb_args(post_id, &submitted_fields);
let q = format!(
"SELECT (
UPDATE BlogPost
Expand All @@ -115,8 +116,8 @@ pub async fn update_post_partial(
}}
) {fields}"
);
tracing::debug!("To query: {}", q);
tracing::debug!("Query with params: {:#?}", args);
debug!("To query: {q}");
debug!("Query with params: {args:#?}");
let updated_post: Option<DetailedBlogPost> = db
.query_single(&q, &args)
.await
Expand Down Expand Up @@ -146,7 +147,7 @@ pub async fn create_post(
let submitted_fields: Vec<&String> = jdata.keys().collect();
let set_clause = post_data.gen_set_clause(&submitted_fields);
let fields = DetailedBlogPost::fields_as_shape();
let args = post_data.make_edgedb_object(&submitted_fields);
let args = post_data.make_edgedb_args(&submitted_fields);
let q = format!(
"
SELECT (
Expand Down
Loading

0 comments on commit e9daf19

Please sign in to comment.