Skip to content

Commit

Permalink
Merge pull request #200 from Enraged-Dun-Cookie-Development-Team/feat…
Browse files Browse the repository at this point in the history
…/union-version

统一版本接口
  • Loading branch information
phidiaLam authored Nov 5, 2024
2 parents 45349aa + d141914 commit 7eb660a
Show file tree
Hide file tree
Showing 173 changed files with 3,024 additions and 240 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Rust toolchain Stable
uses: actions-rs/toolchain@v1
with:
toolchain: 1.78.0
toolchain: 1.80.1
components: clippy
default: true
- name: Rust toolchain Nightly
Expand Down
21 changes: 17 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ debug = 1
members = [
"libs/*",
"persistence/persistence",
"persistence/dao/*",
"persistence/database/*",
"persistence/migrate/*",
"persistence/models/*",
"./macros/*",
"./middle-server/*",
"./logic/*",
"./global/*",
"./service/*",
"http_service/ceobe_operation/*",
]

[workspace.dependencies]
Expand All @@ -48,7 +53,8 @@ once_cell = "1"
reqwest = { version = "0.12", default-features = false, features = [
"rustls-tls",
] }
resp-result = { version = "0.7", package = "axum-resp-result"}
axum-resp-result = { version = "0.7.1"}

sea-orm = { version = "0.12", default-features = false, features = [
"sqlx-mysql",
"runtime-tokio-rustls",
Expand Down Expand Up @@ -103,6 +109,10 @@ hex = "0.4"
serde_qs = "0.13.0"
request-clients = { version = "0.1.0", path = "middle-server/request-clients" }
mime = "0.3.16"
serve-utils = {version = "0.1.0", path="libs/serve_utils"}
tower = { version = "0.4", features = ["limit"] }
status-err={path = "./libs/status-err"}


[dependencies]

Expand Down Expand Up @@ -134,7 +144,7 @@ reqwest = { workspace = true }
sha2 = { workspace = true }
tap = { workspace = true }
thiserror = { workspace = true }
tower = { version = "0.4", features = ["limit"] }
tower.workspace = true
tower-http = { version = "0.5", features = ["trace", "catch-panic", "set-header", "compression-full", "auth", "add-extension", "cors"] }
typed-builder = { workspace = true }
url = { workspace = true }
Expand All @@ -156,6 +166,9 @@ bitmap-convert.workspace = true
bitmaps.workspace = true
persistence = { workspace = true, features = ["prelude", "migrate"] }
tencent-cloud-server.workspace = true
semver = { version = "1.0.23", features = ["serde"] }
release_version_service = { version = "0.1.0", path = "http_service/ceobe_operation/release_version_service" }
serve_utils = { version = "0.1.0", path = "libs/serve_utils" }
mimalloc = "0.1.43"


Expand All @@ -179,9 +192,9 @@ path = "./libs/range-limit"
path = "./libs/logger"

[dependencies.status-err]
path = "./libs/status-err"
workspace = true

[dependencies.resp-result]
[dependencies.axum-resp-result]
workspace = true

[dependencies.checker]
Expand Down
87 changes: 46 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
| `database`/`db` | `logger` || `bool` | 是否开始数据库操作日志 | 默认关闭 |
| `logger`/`log` | `to_stdout` || `bool` | 同时将日志输出到 Stdout | 默认为 true |
| `logger`/`log` | `to_file` || `String` | 同时将日志输出的文件 | 有值将会同时将日志输出到指定文件 |
| `logger`/`log` | `level` || `off` 或者</br>`error`或者</br>`warm` 或者</br>`info` 或者</br>`debug` 或者</br>`trace` | 日志输出过滤等级 ||
| `logger`/`log` | `level` | 是 | `off` 或者</br>`error`或者</br>`warm` 或者</br>`info` 或者</br>`debug`
或者</br>`trace` | 日志输出过滤等级 | 无 |
| `resp_result`/ `rresult` | `body` || `String` | 响应成功时的响应体字段名称 ||
| `resp_result`/ `rresult` | `err-msg` || `String` | 响应失败时异常字段名称 ||
| `resp_result`/ `rresult` | `fix-field` || `bool` | 响应体固定字段 | 如果无需该字段值将为`null` |
| `resp_result`/ `rresult` | `bool-status` || `Option<String>` | 使用一个 `bool` 类型标记响应成功与否 | 该字段缺省表示不使用 |
| `resp_result`/ `rresult` | `body-extra-err` || `Option<String>` | 额外的异常信息在响应体中字段 | 该字段缺省表示不使用 |
| `resp_result`/ `rresult` | `header-extra-err` || `Option<String>` | 额外的异常信息在响应头中的字段名称 | 该字段缺省表示不使用 |
| `resp_result`/ `rresult` | `bool-status` || `Option<String>` | 使用一个 `bool` 类型标记响应成功与否 |
该字段缺省表示不使用 |
| `resp_result`/ `rresult` | `body-extra-err` || `Option<String>` | 额外的异常信息在响应体中字段 |
该字段缺省表示不使用 |
| `resp_result`/ `rresult` | `header-extra-err` || `Option<String>` | 额外的异常信息在响应头中的字段名称 |
该字段缺省表示不使用 |
| `mongodb`/ `mongo` | `username` || `String` | Mongodb 进行数据库连接使用的用户 | 该用户需要完整 Admin 权限 |
| `mongodb`/ `mongo` | `password` || `String` | Mongodb 进行数据库连接使用的用户密码 ||
| `mongodb`/ `mongo` | `host` || `String` | Mongodb 进行数据库连接使用的 host | 默认为`localhost` |
Expand Down Expand Up @@ -117,20 +121,20 @@
| `M` | 数据未变更 |
| `A` | 权限认证异常 |
| `Q` | 七牛云上传异常 |
| `L` | 日志报告异常 |
| `L` | 日志报告异常 |
- 服务异常

| 前缀 | 异常码 | httpCode | 说明 |
| :--: | :----: | :------: | :--------------------- |
| :--: | :----: | :------: | :--------------------- |
| `F` | 0001 | 500 | 服务器发生未预期 Panic |
| `F` | 0002 | 500 | 管道发生未预期关闭 |

- Io 异常

| 前缀 | 异常码 | httpCode | 说明 |
| :--: |:----:| :------: |:------------------|
| :--: |:----:| :------: |:------------------|
| `I` | 0001 | 500 | `std::io::Error` |
| `I` | 0002 | 500 | `core::fmt::Error`|
| `I` | 0002 | 500 | `core::fmt::Error`|
- 类型转换异常

| 前缀 | 异常码 | httpCode | 说明 |
Expand All @@ -144,37 +148,38 @@
| `P` | 0007 | 500 | 非法 Http 请求头内容 |
| `P` | 0008 | 500 | UUID解析异常 |

- 数据校验异常

| 前缀 | 异常码 | httpCode | 说明 |
| :--: |:----:| :------: |:------------------------------------|
| `C` | 0001 | 400 | 范围检查未通过 |
| `C` | 0002 | 400 | 饼学大厦 id 格式不是 {int}.{int} |
| `C` | 0003 | 400 | 错误的 Fraction 值范围(0~5) |
| `C` | 0004 | 400 | `Json` 序列化/反序列化异常 |
| `C` | 0005 | 400 | `Path` 数据加载异常 |
| `C` | 0006 | 400 | 未知的预期确信度等级 |
| `C` | 0007 | 400 | `Query` 加载异常 |
| `C` | 0008 | 409 | 饼学大厦的 Id 已经存在 |
| `C` | 0009 | 400 | BV 号格式错误 |
| `C` | 000A | 400 | 版本号格式错误 |
| `C` | 000B | 409 | 版本号已经被使用 |
| `C` | 000C | 400 | `Bincode` 序列化/反序列化异常 |
| `C` | 000D | 500 | 存在多个可用的资源全可用的记录 |
| `C` | 000E | 400 | 预期为 0 值取得非 0 值 |
| `C` | 000F | 400 | 获取`MultiPart`异常 |
| `C` | 0010 | 400 | 解析`MultiPart`异常 |
| `C` | 0011 | 400 | `MultiPart` Field 不存在 |
| `C` | 0012 | 500 | 平台下存在数据源,无法删除平台 |
| `C` | 0013 | 400 | 未找到平台 |
| `C` | 0014 | 400 | `{origin}` 无法被 `{RHS}` 整除,余数`{rem}` |
| `C` | 0015 | 400 | Json 对象不符合预期 |
- | `C` | 0016 | 400 | Bson 序列化异常 |
数据校验异常

| 前缀 | 异常码 | httpCode | 说明 |
|:-----:|:----:|:--------:|:------------------------------------|
| `C` | 0001 | 400 | 范围检查未通过 |
| `C` | 0002 | 400 | 饼学大厦 id 格式不是 {int}.{int} |
| `C` | 0003 | 400 | 错误的 Fraction 值范围(0~5) |
| `C` | 0004 | 400 | `Json` 序列化/反序列化异常 |
| `C` | 0005 | 400 | `Path` 数据加载异常 |
| `C` | 0006 | 400 | 未知的预期确信度等级 |
| `C` | 0007 | 400 | `Query` 加载异常 |
| `C` | 0008 | 409 | 饼学大厦的 Id 已经存在 |
| `C` | 0009 | 400 | BV 号格式错误 |
| `C` | 000A | 400 | 版本号格式错误 |
| `C` | 000B | 409 | 版本号已经被使用 |
| `C` | 000C | 400 | `Bincode` 序列化/反序列化异常 |
| `C` | 000D | 500 | 存在多个可用的资源全可用的记录 |
| `C` | 000E | 400 | 预期为 0 值取得非 0 值 |
| `C` | 000F | 400 | 获取`MultiPart`异常 |
| `C` | 0010 | 400 | 解析`MultiPart`异常 |
| `C` | 0011 | 400 | `MultiPart` Field 不存在 |
| `C` | 0012 | 500 | 平台下存在数据源,无法删除平台 |
| `C` | 0013 | 400 | 未找到平台 |
| `C` | 0014 | 400 | `{origin}` 无法被 `{RHS}` 整除,余数`{rem}` |
| `C` | 0015 | 400 | Json 对象不符合预期 |
| `C` | 0016 | 400 | Bson 序列化异常 |
| `C` | 0017 | 409 | 版本号过旧 |

- 数据库异常(SeaOrm)

| 前缀 | 异常码 | httpCode | 说明 |
| :--: | :----: | :------: | :------------------- |
| :--: | :----: | :------: | :------------------- |
| `D` | 0001 | 500 | 数据库连接失败 |
| `D` | 0002 | 500 | 数据库请求操作失败 |
| `D` | 0003 | 500 | 数据库查询失败 |
Expand All @@ -187,7 +192,7 @@
- 数据库异常(MongoDb)

| 前缀 | 异常码 | httpCode | 说明 |
| :--: | :----: | :------: | :----------------------- |
| :--: | :----: | :------: | :----------------------- |
| `G` | 0001 | 500 | 非法参数 |
| `G` | 0002 | 500 | 权限不足 |
| `G` | 0003 | 500 | `Bson`反序列化失败 |
Expand All @@ -211,7 +216,7 @@
- Redis 异常

| 前缀 | 异常码 | httpCode | 说明 |
| :--: | :----: | :------: | :------------------------------- |
| :--: | :----: | :------: | :------------------------------- |
| `R` | 0001 | 500 | 无效响应 |
| `R` | 0002 | 500 | 权限不足 |
| `R` | 0003 | 500 | 类型不匹配 |
Expand All @@ -233,7 +238,7 @@
- 数据未变更

| 前缀 | 异常码 | httpCode | 说明 |
| :--: | :----: | :------: | :----------------------------- |
| :--: | :----: | :------: | :----------------------------- |
| `M` | 0001 | 304 | Ceobe 在当前提供时间戳下无更新 |

- 资源查找异常
Expand All @@ -251,7 +256,7 @@
- 权限认证异常

| 前缀 | 异常码 | httpCode | 说明 |
| :--: | :----: | :------: | :------------------- |
| :--: | :----: | :------: | :------------------- |
| `A` | 0001 | 401 | 缺少 Token 字段 |
| `A` | 0002 | 401 | 权限不足 |
| `A` | 0003 | 404 | Token 对应信息不存在 |
Expand All @@ -266,13 +271,13 @@
- 七牛云上传异常

| 前缀 | 异常码 | httpCode | 说明 |
| :--: | :----: | :------: | :------------------- |
| :--: | :----: | :------: | :------------------- |
| `Q` | 0001 | 500 | 上传七牛云时出现异常 |

- 日志报告异常

|前缀 | 异常码 | httpCode | 说明|
| :--: | :----: | :------: | :------------------- |
| :--: | :----: | :------: | :------------------- |
| `L` | 0001 | 500 | 与Grpc服务端建立连接失败 |
| `L` | 0002 | 500 | Grpc service 返回异常响应 |
| `L` | 0003 | 500 | 发送日志时收到失败响应 |
8 changes: 3 additions & 5 deletions global/redis_global/src/type_bind/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ where
self.redis.hexists(&*self.key, field).await
}

pub async fn set<'arg, RV, F>(
pub async fn set<'arg, F>(
&mut self, field: F, value: T::Input,
) -> RedisResult<RV>
) -> RedisResult<()>
where
F: ToRedisArgs + Send + Sync + 'arg,
RV: FromRedisValue,
{
self.redis.hset(&*self.key, field, value).await
}
Expand Down Expand Up @@ -97,10 +96,9 @@ where
///
/// ## 参考
/// - [`AsyncCommands::hdel`]
pub async fn remove<'arg, RV, F>(&mut self, field: F) -> RedisResult<RV>
pub async fn remove<'arg, F>(&mut self, field: F) -> RedisResult<()>
where
F: ToRedisArgs + Send + Sync + 'arg,
RV: FromRedisValue,
{
self.redis.hdel(&*self.key, field).await
}
Expand Down
15 changes: 5 additions & 10 deletions global/redis_global/src/type_bind/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,20 @@ where
///
/// ## 参考
/// - [`AsyncCommands::set_nx`]
pub async fn set_if_not_exist<RV>(
pub async fn set_if_not_exist(
&mut self, value: T::Input,
) -> RedisResult<RV>
where
RV: FromRedisValue,
{
) -> RedisResult<()>
where {
self.redis.set_nx(&*self.key, value).await
}

/// 写入值并添加超时时间
///
/// ## 参考
/// - [`AsyncCommands::set_ex`]
pub async fn set_with_expire<RV>(
pub async fn set_with_expire(
&mut self, value: T::Input, duration: Duration,
) -> RedisResult<RV>
where
RV: FromRedisValue,
{
) -> RedisResult<()> {
self.redis
.set_ex(&*self.key, value, duration.as_secs() as _)
.await
Expand Down
20 changes: 20 additions & 0 deletions http_service/ceobe_operation/release_version_service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "release_version_service"
version = "0.1.0"
edition = "2021"

[dependencies]
persistence = { workspace = true, features = ["model-ceobe-operate", "help-crates"] }
semver = "1.0.23"
serve_utils = { version = "0.1.0", path = "../../../libs/serve_utils" }
serde = { version = "1.0.201", features = ["derive"] }
thiserror.workspace = true
status-err.workspace = true
http.workspace = true
axum-resp-result.workspace = true
tracing.workspace = true
serde_json.workspace = true
tencent-cloud-server.workspace = true
checker = { version = "0.1.0", path = "../../../libs/checker" }
page_size.workspace = true
ceobe_operation_logic = { version = "0.1.0", path = "../../../logic/ceobe_operation_logic" }
23 changes: 23 additions & 0 deletions http_service/ceobe_operation/release_version_service/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use checker::prefabs::num_check::NonZeroUnsignedError;
use serve_utils::{
axum::extract::rejection::{JsonRejection, QueryRejection},
status_err::StatusErr,
ControllerError, ThisError,
};

#[derive(Debug, ThisError, StatusErr)]
#[status_err(resp_err)]
pub enum Error {
#[error(transparent)]
Query(#[from] QueryRejection),
#[error(transparent)]
Json(#[from] JsonRejection),
#[error(transparent)]
InvalidPaginator(#[from] NonZeroUnsignedError),
#[error(transparent)]
Logic(#[from] ceobe_operation_logic::release_version::Error),
}

impl ControllerError for crate::ReleaseVersionController {
type Error = Error;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use persistence::operate::FromRef;
use serve_utils::{
axum::{
routing::{get, post},
Router,
},
endpoint::{AdminEnd, CDN},
ControllerRoute, HandlerMapReject, HandlerResult,
};
use tencent_cloud_server::axum_starter::{
PartTencentCloudManagerState, RequestClient,
};

mod admin_end;
mod cdn;

pub(crate) type Result<T> = HandlerResult<T, crate::ReleaseVersionController>;
pub(crate) type MapRejecter<T> =
HandlerMapReject<T, crate::ReleaseVersionController>;

impl<S> ControllerRoute<S, CDN> for crate::ReleaseVersionController
where
S: Send + Clone + Sync + 'static,
PartTencentCloudManagerState: FromRef<S>,
RequestClient: FromRef<S>,
{
const BASE_URI: &'static str = "/version";

fn route(self) -> Router<S> {
Router::new().route("/fetch", get(Self::fetch_version))
}
}

impl<S> ControllerRoute<S, AdminEnd> for crate::ReleaseVersionController
where
S: Send + Clone + Sync + 'static,
PartTencentCloudManagerState: FromRef<S>,
RequestClient: FromRef<S>,
{
const BASE_URI: &'static str = "/releaseVersion";

fn route(self) -> Router<S> {
Router::new()
.route("/markDelete", post(Self::make_delete_version))
.route("/create", post(Self::new_version))
.route("/all", get(Self::all_version))
.route("/modify", post(Self::modify_description))
}
}
Loading

0 comments on commit 7eb660a

Please sign in to comment.