Skip to content

Commit

Permalink
feat: ultimate-web 使用 Ulid 替换 Uuid 来生成默认的 err_id
Browse files Browse the repository at this point in the history
  • Loading branch information
yangjing committed Aug 13, 2024
1 parent b3aeea8 commit cd55d09
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions ultimates/ultimate-db/src/model_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ impl ModelManager {
Ok(ModelManager { dbx, ctx: None })
}

pub fn new_with_txn(&self) -> Result<ModelManager> {
pub fn clone_with_txn(&self) -> Result<ModelManager> {
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<ModelManager> {
pub fn get_or_clone_with_txn(&self) -> Result<ModelManager> {
if self.dbx().is_txn() {
Ok(self.clone())
} else {
Ok(self.new_with_txn()?)
Ok(self.clone_with_txn()?)
}
}

Expand Down
2 changes: 1 addition & 1 deletion ultimates/ultimate-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
8 changes: 4 additions & 4 deletions ultimates/ultimate-web/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = core::result::Result<Json<T>, AppError>;

Expand All @@ -14,7 +14,7 @@ pub type AppResult<T> = core::result::Result<Json<T>, 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,

Expand All @@ -28,11 +28,11 @@ pub struct AppError {

impl AppError {
pub fn new(error: impl Into<String>) -> 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<String>) -> 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 {
Expand Down

0 comments on commit cd55d09

Please sign in to comment.