Skip to content

Commit

Permalink
!2 feat
Browse files Browse the repository at this point in the history
* feat: Id<xxx>Result 类型添加 new 构造函数
* feat: ulid
* chore: update libraries version
  • Loading branch information
yangbajing committed Aug 9, 2024
1 parent 518feb3 commit 3cbe2db
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 14 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ultimate = { version = "0.1", path = "ultimates/ultimate" }
ultimate-db = { version = "0.1", path = "ultimates/ultimate-db" }
ultimate-web = { version = "0.1", path = "ultimates/ultimate-web" }
# -- projects end
derive_more = { version = "1.0.0-beta", features = ["from", "display"] }
derive_more = { version = "1.0", features = ["from", "display"] }
toml = "0.8"
config = { version = "0.14", default-features = false, features = [
"toml",
Expand All @@ -35,6 +35,7 @@ itertools = "0.13"
regex = "1"
rand = "0.8"
bytes = "1"
ulid = { version = "1", features = ["serde", "uuid"] }
uuid = { version = "1", features = [
"v4",
"v7",
Expand All @@ -50,7 +51,7 @@ chrono = { version = "0.4", default-features = false, features = [
"serde",
] }
typed-builder = "0.19"
derive-getters = "0.4"
derive-getters = "0.5"
clap = { version = "4.5.7", features = ["derive"] }
# -- Helpful macros for working with enums and strings
strum = { version = "0.26", features = ["derive"] }
Expand Down
4 changes: 3 additions & 1 deletion ultimates/ultimate-common/src/string.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::{Error, Result};
use base64ct::{Base64UrlUnpadded, Encoding};
use rand::{distributions::Alphanumeric, thread_rng, Rng};
use serde::{de::Visitor, Deserializer, Serializer};

use crate::{Error, Result};

pub fn repeat_str(s: &str, n: usize) -> String {
let mut v = String::with_capacity(s.len() * n);
for _ in 0..n {
Expand Down Expand Up @@ -76,6 +77,7 @@ where
{
s.serialize_str(v)
}

pub fn ser_opt_str_secret<S>(v: Option<String>, s: S) -> core::result::Result<S::Ok, S::Error>
where
S: Serializer,
Expand Down
2 changes: 1 addition & 1 deletion ultimates/ultimate-db/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::borrow::Cow;

use sqlx::error::DatabaseError;
use thiserror::Error;
use ultimate::error::DataError;
use ultimate::DataError;

use crate::Id;

Expand Down
2 changes: 1 addition & 1 deletion ultimates/ultimate-db/src/store/dbx/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use thiserror::Error;
use ultimate::error::DataError;
use ultimate::DataError;

pub type Result<T> = core::result::Result<T, Error>;

Expand Down
2 changes: 1 addition & 1 deletion ultimates/ultimate-web/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use axum::response::IntoResponse;
use axum::Json;
use serde::Serialize;
use serde_json::Value;
use ultimate::error::DataError;
use ultimate::security;
use ultimate::DataError;
use uuid::Uuid;

pub type AppResult<T> = core::result::Result<Json<T>, AppError>;
Expand Down
2 changes: 1 addition & 1 deletion ultimates/ultimate-web/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use axum_extra::headers::{Authorization, HeaderMapExt};
use serde::de::DeserializeOwned;
use ultimate::configuration::model::SecruityConfig;
use ultimate::ctx::Ctx;
use ultimate::error::DataError;
use ultimate::security::{AccessToken, SecurityUtils};
use ultimate::DataError;
use ultimate_common::time;

use crate::error::AppError;
Expand Down
4 changes: 3 additions & 1 deletion ultimates/ultimate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ async-trait.workspace = true
toml.workspace = true
config.workspace = true
strum_macros.workspace = true
uuid.workspace = true
uuid = { workspace = true, optional = true }
ulid = { workspace = true, optional = true }
log.workspace = true
tracing.workspace = true
# tracing-log.workspace = true
Expand All @@ -37,6 +38,7 @@ serde_json.workspace = true
serde_with.workspace = true
derive_more.workspace = true
tonic = { workspace = true, optional = true }
utoipa = { workspace = true, optional = true }

[dev-dependencies]
dotenvy.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion ultimates/ultimate/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use josekit::jwt::JwtPayload;

use ultimate_common::time::{self, DateTime, Duration, Utc, UtcDateTime};

use crate::error::DataError;
use crate::DataError;

/// 会话上下文。
/// 此处 clone 的成本很低,若后续数据多的话可以使用 Arc 加 Wrapper 模式来降低数据复制的成本
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions ultimates/ultimate/src/error/mod.rs

This file was deleted.

7 changes: 5 additions & 2 deletions ultimates/ultimate/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
pub mod configuration;
pub mod ctx;
pub mod error;
mod data_error;
pub mod metas;
mod model;
mod run_mode;
pub mod security;
pub mod signal;
pub mod starter;
pub mod trace;

pub use data_error::*;
pub use model::*;
pub use run_mode::*;

pub type Result<T> = core::result::Result<T, error::DataError>;
pub type Result<T> = core::result::Result<T, DataError>;
38 changes: 38 additions & 0 deletions ultimates/ultimate/src/model.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct IdI64Result {
pub id: i64,
}
impl IdI64Result {
pub fn new(id: i64) -> Self {
Self { id }
}
}

#[cfg(feature = "uuid")]
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct IdUuidResult {
pub id: uuid::Uuid,
}
#[cfg(feature = "uuid")]
impl IdUuidResult {
pub fn new(id: uuid::Uuid) -> Self {
Self { id }
}
}

#[cfg(feature = "ulid")]
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct IdUlidResult {
pub id: ulid::Ulid,
}
#[cfg(feature = "ulid")]
impl IdUlidResult {
pub fn new(id: ulid::Ulid) -> Self {
Self { id }
}
}

0 comments on commit 3cbe2db

Please sign in to comment.