From cd55d09934374c21be80e6a96b13c502543e878f Mon Sep 17 00:00:00 2001 From: Yang Jing Date: Tue, 13 Aug 2024 23:24:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20ultimate-web=20=E4=BD=BF=E7=94=A8=20Uli?= =?UTF-8?q?d=20=E6=9B=BF=E6=8D=A2=20Uuid=20=E6=9D=A5=E7=94=9F=E6=88=90?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E7=9A=84=20err=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 2 +- ultimates/ultimate-db/src/model_manager.rs | 6 +++--- ultimates/ultimate-web/Cargo.toml | 2 +- ultimates/ultimate-web/src/error.rs | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9377934..0457cd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ resolver = "2" [workspace.package] version = "0.1.0" edition = "2021" -rust-version = "1.78" +rust-version = "1.79" description = "Rust libraries" license-file = "LICENSE" repository = "https://gitee.com/yangbajing/ultimate-common" diff --git a/ultimates/ultimate-db/src/model_manager.rs b/ultimates/ultimate-db/src/model_manager.rs index e7f5ad6..a1583d8 100644 --- a/ultimates/ultimate-db/src/model_manager.rs +++ b/ultimates/ultimate-db/src/model_manager.rs @@ -20,16 +20,16 @@ impl ModelManager { Ok(ModelManager { dbx, ctx: None }) } - pub fn new_with_txn(&self) -> Result { + pub fn clone_with_txn(&self) -> Result { let dbx = Dbx::new(self.dbx.db().clone(), true)?; Ok(ModelManager { dbx, ctx: self.ctx.clone() }) } - pub fn get_or_new_with_txn(&self) -> Result { + pub fn get_or_clone_with_txn(&self) -> Result { if self.dbx().is_txn() { Ok(self.clone()) } else { - Ok(self.new_with_txn()?) + Ok(self.clone_with_txn()?) } } diff --git a/ultimates/ultimate-web/Cargo.toml b/ultimates/ultimate-web/Cargo.toml index f0ce905..f9335a6 100644 --- a/ultimates/ultimate-web/Cargo.toml +++ b/ultimates/ultimate-web/Cargo.toml @@ -26,6 +26,6 @@ axum-extra.workspace = true serde.workspace = true serde_json.workspace = true serde_with.workspace = true -uuid.workspace = true +ulid.workspace = true tonic = { workspace = true, optional = true } utoipa = { workspace = true, optional = true } diff --git a/ultimates/ultimate-web/src/error.rs b/ultimates/ultimate-web/src/error.rs index 5061294..9770292 100644 --- a/ultimates/ultimate-web/src/error.rs +++ b/ultimates/ultimate-web/src/error.rs @@ -3,9 +3,9 @@ use axum::response::IntoResponse; use axum::Json; use serde::Serialize; use serde_json::Value; +use ulid::Ulid; use ultimate::security; use ultimate::DataError; -use uuid::Uuid; pub type AppResult = core::result::Result, AppError>; @@ -14,7 +14,7 @@ pub type AppResult = core::result::Result, AppError>; #[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))] pub struct AppError { /// A unique error ID. - pub err_id: Uuid, + pub err_id: Ulid, pub err_code: i32, @@ -28,11 +28,11 @@ pub struct AppError { impl AppError { pub fn new(error: impl Into) -> Self { - Self { err_id: Uuid::now_v7(), err_code: 500, err_msg: error.into(), err_msg_detail: None } + Self { err_id: Ulid::new(), err_code: 500, err_msg: error.into(), err_msg_detail: None } } pub fn new_with_code(err_code: i32, err_msg: impl Into) -> Self { - Self { err_id: Uuid::now_v7(), err_code, err_msg: err_msg.into(), err_msg_detail: None } + Self { err_id: Ulid::new(), err_code, err_msg: err_msg.into(), err_msg_detail: None } } pub fn with_err_code(mut self, err_code: i32) -> Self {