From df683d50414956f0c1a18da16ec3fbb98d6a7d90 Mon Sep 17 00:00:00 2001 From: Zokhoi <20432565+Zokhoi@users.noreply.github.com> Date: Wed, 25 Sep 2024 04:20:20 +0800 Subject: [PATCH] Fix: consistency and other minor things --- deepwell/src/api.rs | 2 +- deepwell/src/endpoints/page.rs | 4 ++-- deepwell/src/endpoints/parent.rs | 20 +++++++++---------- deepwell/src/services/page/structs.rs | 2 +- deepwell/src/services/parent/structs.rs | 4 ++-- framerail/src/lib/server/deepwell/page.ts | 4 ++-- .../src/routes/[slug]/[...extra]/+server.ts | 4 ++-- .../src/routes/[slug]/[...extra]/page.svelte | 6 +++--- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/deepwell/src/api.rs b/deepwell/src/api.rs index cd8c229c408..556f7580b1c 100644 --- a/deepwell/src/api.rs +++ b/deepwell/src/api.rs @@ -254,7 +254,7 @@ async fn build_module(app_state: ServerState) -> anyhow::Result = PageService::get_pages(ctx, site_id, parents.as_slice()) .await? - .iter() - .map(|p| p.slug.clone()) + .into_iter() + .map(|p| p.slug) .collect(); Ok(pages) } -pub async fn parent_modify( +pub async fn parent_update( ctx: &ServiceContext<'_>, params: Params<'static>, -) -> Result { - let input: ParentModifyDescription = params.parse()?; +) -> Result { + let input: UpdateParents = params.parse()?; info!( - "Modifying multiple parental relationship for child {:?} in site ID {}", + "Updating multiple parental relationships for child {:?} in site ID {}", input.child, input.site_id, ); @@ -134,7 +134,7 @@ pub async fn parent_modify( ctx, ParentDescription { site_id: input.site_id, - parent: parent.clone(), + parent: parent.to_owned(), child: input.child.clone(), }, ) @@ -170,7 +170,7 @@ pub async fn parent_modify( None => None, }; - Ok(ModifyParentOutput { + Ok(UpdateParentsOutput { added: creation, removed: removal, }) diff --git a/deepwell/src/services/page/structs.rs b/deepwell/src/services/page/structs.rs index bb495303541..ab4c165b500 100644 --- a/deepwell/src/services/page/structs.rs +++ b/deepwell/src/services/page/structs.rs @@ -116,7 +116,7 @@ pub struct GetPageOutput { #[derive(Serialize, Debug, Clone)] pub struct GetPageScoreOutput { pub page_id: i64, - pub rating: ScoreValue, + pub score: ScoreValue, } #[derive(Deserialize, Debug, Clone)] diff --git a/deepwell/src/services/parent/structs.rs b/deepwell/src/services/parent/structs.rs index e8cc9eda88a..5f494af7967 100644 --- a/deepwell/src/services/parent/structs.rs +++ b/deepwell/src/services/parent/structs.rs @@ -30,7 +30,7 @@ pub struct ParentDescription<'a> { } #[derive(Deserialize, Debug, Clone)] -pub struct ParentModifyDescription<'a> { +pub struct UpdateParents<'a> { pub site_id: i64, pub child: Reference<'a>, pub add: Option>>, @@ -80,7 +80,7 @@ pub struct RemoveParentOutput { } #[derive(Serialize, Debug, Clone)] -pub struct ModifyParentOutput { +pub struct UpdateParentsOutput { pub added: Option>, pub removed: Option>, } diff --git a/framerail/src/lib/server/deepwell/page.ts b/framerail/src/lib/server/deepwell/page.ts index 8233788b610..44b6bfc9d11 100644 --- a/framerail/src/lib/server/deepwell/page.ts +++ b/framerail/src/lib/server/deepwell/page.ts @@ -166,14 +166,14 @@ export async function pageLayout( }) } -export async function pageParentModify( +export async function pageParentUpdate( siteId: number, pageId: number, userId: number, add: string[], remove: string[] ): Promise { - return client.request("parent_modify", { + return client.request("parent_update", { site_id: siteId, child: pageId, user_id: userId, diff --git a/framerail/src/routes/[slug]/[...extra]/+server.ts b/framerail/src/routes/[slug]/[...extra]/+server.ts index 55de96b4eb1..cc01128645b 100644 --- a/framerail/src/routes/[slug]/[...extra]/+server.ts +++ b/framerail/src/routes/[slug]/[...extra]/+server.ts @@ -99,7 +99,7 @@ export async function POST(event) { let layout = data.get("layout")?.toString().trim() ?? null res = await page.pageLayout(siteId, pageId, session?.user_id, layout) - } else if (extra.includes("parentset")) { + } else if (extra.includes("parent-set")) { let oldParentStr = data.get("old-parents")?.toString().trim() ?? "" let oldParent = oldParentStr.split(" ") let newParentStr = data.get("new-parents")?.toString().trim() ?? "" @@ -116,7 +116,7 @@ export async function POST(event) { } res = await page.pageParentModify(siteId, pageId, session?.user_id, added, removed) - } else if (extra.includes("parentget")) { + } else if (extra.includes("parent-get")) { res = await page.pageParentGet(siteId, pageId, slug) } else if (extra.includes("score")) { res = await page.pageScore(siteId, pageId, slug) diff --git a/framerail/src/routes/[slug]/[...extra]/page.svelte b/framerail/src/routes/[slug]/[...extra]/page.svelte index b164db1cc69..f0fba5cc595 100644 --- a/framerail/src/routes/[slug]/[...extra]/page.svelte +++ b/framerail/src/routes/[slug]/[...extra]/page.svelte @@ -130,7 +130,7 @@ let fdata = new FormData() fdata.set("site-id", $page.data.site.site_id) fdata.set("page-id", $page.data.page.page_id) - let res = await fetch(`/${$page.data.page.slug}/parentget`, { + let res = await fetch(`/${$page.data.page.slug}/parent-get`, { method: "POST", body: fdata }).then((res) => res.json()) @@ -151,7 +151,7 @@ fdata.set("site-id", $page.data.site.site_id) fdata.set("page-id", $page.data.page.page_id) fdata.set("old-parents", parents) - let res = await fetch(`/${$page.data.page.slug}/parentset`, { + let res = await fetch(`/${$page.data.page.slug}/parent-set`, { method: "POST", body: fdata }).then((res) => res.json()) @@ -262,7 +262,7 @@ message: res.message }) } else { - voteRating = res.rating ?? 0 + voteRating = res.score ?? 0 showVote = true } }