From 5bd4bca9a5fec8964cd0a19e3e66fab8d5067b72 Mon Sep 17 00:00:00 2001 From: 0xZensh Date: Sun, 26 Nov 2023 00:08:46 +0800 Subject: [PATCH] fix: fix collection children api --- Cargo.lock | 62 +++++++++++++++++++++++----------------- Cargo.toml | 2 +- src/api/collection.rs | 2 ++ src/api/publication.rs | 5 ---- src/db/model_creation.rs | 14 +++++++-- src/router.rs | 6 ---- 6 files changed, 50 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index adc46a8..9eecae1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -351,9 +351,9 @@ dependencies = [ [[package]] name = "config" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d379af7f68bfc21714c6c7dea883544201741d2ce8274bb12fa54f89507f52a7" +checksum = "23738e11972c7643e4ec947840fc463b6a571afcd3e735bdfce7d03c7a784aca" dependencies = [ "async-trait", "json5", @@ -476,9 +476,9 @@ dependencies = [ [[package]] name = "data-encoding" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" +checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" [[package]] name = "deranged" @@ -593,9 +593,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "form_urlencoded" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ "percent-encoding", ] @@ -727,9 +727,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "h2" @@ -950,6 +950,16 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "if_chain" version = "1.0.2" @@ -1389,9 +1399,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.95" +version = "0.9.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40a4130519a360279579c2053038317e40eff64d13fd3f004f9e1b72b8a6aaf9" +checksum = "3812c071ba60da8b5677cc12bcb1d42989a65553772897a7e0355545a819838f" dependencies = [ "cc", "libc", @@ -1446,9 +1456,9 @@ checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" @@ -2000,9 +2010,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] @@ -2018,9 +2028,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", @@ -2621,7 +2631,7 @@ dependencies = [ "futures-channel", "futures-io", "futures-util", - "idna", + "idna 0.4.0", "ipnet", "once_cell", "rand", @@ -2723,20 +2733,20 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", - "idna", + "idna 0.5.0", "percent-encoding", ] [[package]] name = "uuid" -version = "1.5.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc" +checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" dependencies = [ "getrandom", "rand", @@ -2748,7 +2758,7 @@ version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b92f40481c04ff1f4f61f304d61793c7b56ff76ac1469f1beb199b1445b253bd" dependencies = [ - "idna", + "idna 0.4.0", "lazy_static", "regex", "serde", @@ -2941,9 +2951,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.25.2" +version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" +checksum = "1778a42e8b3b90bff8d0f5032bf22250792889a5cdc752aa0020c84abe3aaf10" [[package]] name = "widestring" @@ -3087,7 +3097,7 @@ dependencies = [ [[package]] name = "writing" -version = "1.3.12" +version = "1.3.13" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index e769008..a75163a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "writing" -version = "1.3.12" +version = "1.3.13" edition = "2021" rust-version = "1.64" description = "" diff --git a/src/api/collection.rs b/src/api/collection.rs index a750c67..182262e 100644 --- a/src/api/collection.rs +++ b/src/api/collection.rs @@ -1081,6 +1081,7 @@ pub async fn list_children( output.status = doc.status; output.updated_at = doc.updated_at; output.language = to.with(doc.language); + output.version = doc.version; output.title = doc.title; output.summary = doc.summary; output.kind = 1; @@ -1104,6 +1105,7 @@ pub async fn list_children( output.status = doc.status; output.updated_at = doc.updated_at; output.language = to.with(doc.language); + output.version = doc.version; output.title = doc.title; output.summary = doc.summary; output.kind = 0; diff --git a/src/api/publication.rs b/src/api/publication.rs index fab26fb..7c2f911 100644 --- a/src/api/publication.rs +++ b/src/api/publication.rs @@ -789,8 +789,6 @@ pub struct UpdatePublicationInput { #[validate(range(min = 1, max = 10000))] pub version: i16, pub updated_at: i64, - #[validate(length(min = 2, max = 16))] - pub model: Option, #[validate(length(min = 1, max = 256))] pub title: Option, #[validate(url)] @@ -804,9 +802,6 @@ pub struct UpdatePublicationInput { impl UpdatePublicationInput { fn into(self) -> anyhow::Result { let mut cols = ColumnsMap::new(); - if let Some(model) = self.model { - cols.set_as("model", &model); - } if let Some(title) = self.title { cols.set_as("title", &title); } diff --git a/src/db/model_creation.rs b/src/db/model_creation.rs index 5622a08..50b89d7 100644 --- a/src/db/model_creation.rs +++ b/src/db/model_creation.rs @@ -194,9 +194,17 @@ impl Creation { } let mut select_fields = select_fields; - let language = "language".to_string(); // language 字段在 meilisearch 中用作 PK,必须存在 - if !select_fields.contains(&language) { - select_fields.push(language); + let field = "language".to_string(); // language 字段在 meilisearch 中用作 PK,必须存在 + if !select_fields.contains(&field) { + select_fields.push(field); + } + let field = "version".to_string(); + if !select_fields.contains(&field) { + select_fields.push(field); + } + let field = "status".to_string(); + if !select_fields.contains(&field) { + select_fields.push(field); } if with_pk { diff --git a/src/router.rs b/src/router.rs index ff82b05..eaa6414 100644 --- a/src/router.rs +++ b/src/router.rs @@ -83,12 +83,6 @@ pub async fn new(cfg: conf::Conf) -> anyhow::Result<(Arc, Router) .nest( "/v1/publication", Router::new() - // .nest( - // "/comment", - // Router::new() - // .route("/", routing::post(todo).get(todo).patch(todo).delete(todo)) - // .route("/list", routing::post(todo)), - // ) .route( "/", routing::post(api::publication::create)