Skip to content

Commit

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

增加 tool_link 的 crud
  • Loading branch information
Goodjooy authored Aug 25, 2024
2 parents 5c5c1aa + 872d6bf commit 848282a
Show file tree
Hide file tree
Showing 38 changed files with 736 additions and 87 deletions.
83 changes: 43 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,41 +132,43 @@
| `I` | 0002 | 500 | `core::fmt::Error`|
- 类型转换异常

| 前缀 | 异常码 | httpCode | 说明 |
| :--: | :----: | :------: | :---------------------- |
| `P` | 0001 | 400 | Url 转化异常 |
| `P` | 0002 | 400 | 数字转换异常 |
| `P` | 0003 | 400 | jwt 转换异常 |
| `P` | 0004 | 400 | 日期转换异常 |
| `P` | 0005 | 500 | 字符串编码异常 |
| `P` | 0006 | 400 | http 请求头内容解析异常 |
| `P` | 0007 | 500 | 非法 Http 请求头内容 |
| 前缀 | 异常码 | httpCode | 说明 |
| :--: |:----:| :------: |:---------------|
| `P` | 0001 | 400 | Url 转化异常 |
| `P` | 0002 | 400 | 数字转换异常 |
| `P` | 0003 | 400 | jwt 转换异常 |
| `P` | 0004 | 400 | 日期转换异常 |
| `P` | 0005 | 500 | 字符串编码异常 |
| `P` | 0006 | 400 | http 请求头内容解析异常 |
| `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 对象不符合预期 |
| 前缀 | 异常码 | 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 序列化异常 |

- 数据库异常(SeaOrm)

Expand Down Expand Up @@ -235,14 +237,15 @@

- 资源查找异常

| 前缀 | 异常码 | httpCode | 说明 |
| :--: | :----: | :------: | :--------------------------- |
| `S` | 0001 | 404 | 指定饼学大厦未找到 |
| `S` | 0002 | 404 | 不存在的路由 |
| `S` | 0003 | 500 | 发起请求时出现异常 |
| `S` | 0004 | 404 | 版本号不存在 |
| `S` | 0005 | 404 | 暂没有版本信息 |
| `S` | 0006 | 500 | 不存在可用的资源全可用的记录 |
| 前缀 | 异常码 | httpCode | 说明 |
| :--: |:----:|:--------:| :--------------------------- |
| `S` | 0001 | 404 | 指定饼学大厦未找到 |
| `S` | 0002 | 404 | 不存在的路由 |
| `S` | 0003 | 500 | 发起请求时出现异常 |
| `S` | 0004 | 404 | 版本号不存在 |
| `S` | 0005 | 404 | 暂没有版本信息 |
| `S` | 0006 | 500 | 不存在可用的资源全可用的记录 |
- | `S` | 000A | 404 | 不存在可用的资源全可用的记录 |

- 权限认证异常

Expand Down
20 changes: 20 additions & 0 deletions libs/page_size/src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,23 @@ impl<E: EntityTrait> WithPagination for Select<E> {
.limit(*size.deref() as u64)
}
}
#[derive(Debug, Clone, Copy)]
pub struct Paginate {
pub offset: u64,
pub limit: u64,
}

impl Paginator {
pub fn offset(&self) -> u64 {
((self.page.deref() - 1) * self.size.deref()) as u64
}

pub fn limit(&self) -> u64 { *self.size.deref() as u64 }

pub fn to_paginate(&self) -> Paginate {
Paginate {
offset: self.offset(),
limit: self.limit(),
}
}
}
14 changes: 14 additions & 0 deletions libs/status-err/src/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,17 @@ status_error!(
0x0002
]->"格式化文本异常"
);

status_error!(
bson::uuid::Error[
ErrPrefix::PARSE,
0x008
]->"bson UUID解析异常"
);

status_error!(
bson::ser::Error[
ErrPrefix::CHECKER,
0x0016
]-> "Bson 序列化异常"
);
5 changes: 5 additions & 0 deletions logic/ceobe_operation_logic/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use persistence::ceobe_operate::{
models::tool_link::CheckError,
resource::OperateError as ResourceOperateError,
tool_link::OperateError as ToolLinkIOperateError,
tool_link_mongodb::OperateError,
video::OperateError as VideoOperateError,
};
use request_clients::error::ChannelClose;
Expand Down Expand Up @@ -52,6 +53,10 @@ pub enum LogicError {
#[error(transparent)]
#[status_err(err = "transparent")]
TcCloudError(#[from] TcCloudError),

#[error(transparent)]
#[status_err(err = "transparent")]
MongoError(#[from] OperateError),
}

impl From<Infallible> for LogicError {
Expand Down
88 changes: 86 additions & 2 deletions logic/ceobe_operation_logic/src/impletements/tool_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@ use page_size::{
use persistence::{
ceobe_operate::{
models::tool_link::checkers::tool_link_data::CeobeOperationToolLink,
ToCeobeOperation,
tool_link_mongodb::models::ToolLink, ToCeobeOperation,
},
ceobe_user::ToCeobe,
mongodb::{mongodb::bson, MongoDatabaseOperate},
mysql::SqlDatabaseOperate,
};
use tencent_cloud_server::{
cdn::purge_urls_cache::PurgeCachePath, cloud_manager::TencentCloudManager,
};

use super::CeobeOperateLogic;
use crate::{error::LogicResult, view::ToolLinkResp};
use crate::{
error::LogicResult,
view::{
OperationTcCdnPath, ToolLinkCreateMongoReq, ToolLinkResp,
ToolLinkUpdateMongoReq,
},
};

impl CeobeOperateLogic {
pub async fn create_tool_link(
Expand Down Expand Up @@ -89,4 +99,78 @@ impl CeobeOperateLogic {

Ok(tool_links)
}

pub async fn create_tool_link_mongo(
mongo: MongoDatabaseOperate, tc_cloud: TencentCloudManager,
tool_link: ToolLinkCreateMongoReq,
) -> LogicResult<()> {
mongo
.ceobe()
.operation()
.tool_link()
.create(tool_link.into())
.await
.unwrap();

const PATHS: [PurgeCachePath; 1] =
[OperationTcCdnPath::TOOL_LINK_LIST];
tc_cloud.purge_urls_cache(&PATHS).await?;

Ok(())
}

pub async fn update_tool_link_mongo(
mongo: MongoDatabaseOperate, tc_cloud: TencentCloudManager,
tool_link: ToolLinkUpdateMongoReq,
) -> LogicResult<()> {
mongo
.ceobe()
.operation()
.tool_link()
.update(tool_link)
.await?;

const PATHS: [PurgeCachePath; 1] =
[OperationTcCdnPath::TOOL_LINK_LIST];
tc_cloud.purge_urls_cache(&PATHS).await?;

Ok(())
}

pub async fn delete_tool_link_mongo(
mongo: MongoDatabaseOperate, tc_cloud: TencentCloudManager,
id: bson::Uuid,
) -> LogicResult<()> {
mongo.ceobe().operation().tool_link().delete(id).await?;

const PATHS: [PurgeCachePath; 1] =
[OperationTcCdnPath::TOOL_LINK_LIST];
tc_cloud.purge_urls_cache(&PATHS).await?;

Ok(())
}

pub async fn page_tool_link_mongo(
mongo: MongoDatabaseOperate, page_size: Paginator,
) -> LogicResult<ListWithPageInfo<ToolLink>> {
let tool_link_list = mongo
.ceobe()
.operation()
.tool_link()
.all_with_paginator(page_size)
.await?;

let count = mongo.ceobe().operation().tool_link().count().await?;

Ok(tool_link_list.with_page_info(page_size, count))
}

pub async fn list_tool_link_mongo(
mongo: MongoDatabaseOperate,
) -> LogicResult<Vec<ToolLink>> {
let tool_link_list =
mongo.ceobe().operation().tool_link().all().await?;

Ok(tool_link_list)
}
}
16 changes: 16 additions & 0 deletions logic/ceobe_operation_logic/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ use persistence::{
self, all_available,
countdown::{self, CountdownType},
},
tool_link_mongodb::models::{Link, ToolLink, ToolLinkUpdate},
video,
},
help_crates::naive_date_time_format,
mongodb::mongodb::bson,
};
use serde::{Deserialize, Serialize};
use tencent_cloud_server::cdn::purge_urls_cache::PurgeCachePath;
Expand Down Expand Up @@ -224,7 +226,21 @@ impl OperationTcCdnPath {
/// 资源列表
pub const RESOURCE_LIST_PATH: PurgeCachePath =
PurgeCachePath::new("/cdn/operate/resource/get");
/// 友联列表
pub const TOOL_LINK_LIST: PurgeCachePath =
PurgeCachePath::new("/cdn/operate/toolLink/list");
/// 视频列表
pub const VIDEO_LIST_PATH: PurgeCachePath =
PurgeCachePath::new("/cdn/operate/video/list");
}

pub type ToolLinkCreateMongoReq = ToolLinkUpdate;

pub type ToolLinkUpdateMongoReq = ToolLink;

#[derive(Debug, Clone, Deserialize)]
pub struct ToolLinkDeleteMongoReq {
pub id: bson::Uuid,
}

pub type LinkMongoReq = Link;
1 change: 1 addition & 0 deletions persistence/dao/ceobe-operate/src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod tool_link;
25 changes: 25 additions & 0 deletions persistence/dao/ceobe-operate/src/common/tool_link.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::ops::Deref;

use db_ops_prelude::database_operates::sub_operate::{
SubOperate, SuperOperate,
};

use crate::OperationDatabaseOperate;

pub struct ToolLinkOperate<'c, C>(&'c C);

impl<'c, C> Deref for ToolLinkOperate<'c, C> {
type Target = C;

fn deref(&self) -> &Self::Target { self.0 }
}

impl<'c, C> SubOperate<'c> for ToolLinkOperate<'c, C> {
type Parent = OperationDatabaseOperate<'c, C>;

fn from_parent(parent: &'c Self::Parent) -> Self { Self(parent) }
}

impl<'db, Conn> OperationDatabaseOperate<'db, Conn> {
pub fn tool_link(&self) -> ToolLinkOperate<'_, Conn> { self.child() }
}
4 changes: 4 additions & 0 deletions persistence/dao/ceobe-operate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ use db_ops_prelude::database_operates::sub_operate::{

#[path = "sql/announcement/mod.rs"] pub mod announcement;
#[path = "sql/app_version/mod.rs"] pub mod app_version;
mod common;
#[path = "sql/desktop_version/mod.rs"]
pub mod desktop_version;
#[path = "mongo/plugin_version/mod.rs"]
pub mod plugin_version;
#[path = "sql/resource/mod.rs"] pub mod resource;
#[path = "sql/tool_link/mod.rs"] pub mod tool_link;
#[path = "mongo/tool_link/mod.rs"]
pub mod tool_link_mongodb;
#[path = "sql/video/mod.rs"] pub mod video;

pub struct OperationDatabaseOperate<'db, Conn>(&'db Conn);

impl<'db, Conn> Deref for OperationDatabaseOperate<'db, Conn> {
Expand Down
20 changes: 20 additions & 0 deletions persistence/dao/ceobe-operate/src/mongo/tool_link/create.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use db_ops_prelude::mongo_connection::MongoDbCollectionTrait;
use tracing::instrument;

use super::{OperateResult, ToolLinkOperate};
use crate::tool_link_mongodb::models::ToolLink;

impl<'db, Conn> ToolLinkOperate<'db, Conn>
where
Conn: MongoDbCollectionTrait<'db, ToolLink>,
{
#[instrument(skip(self))]
pub async fn create(&'db self, tool_link: ToolLink) -> OperateResult<()> {
let db = self.get_collection()?;

db.doing(|collection| collection.insert_one(tool_link, None))
.await?;

Ok(())
}
}
23 changes: 23 additions & 0 deletions persistence/dao/ceobe-operate/src/mongo/tool_link/delete.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use db_ops_prelude::{
mongo_connection::MongoDbCollectionTrait,
mongodb::bson::{doc, Uuid},
};
use tracing::instrument;

use super::{OperateResult, ToolLinkOperate};
use crate::tool_link_mongodb::models::ToolLink;

impl<'db, Conn> ToolLinkOperate<'db, Conn>
where
Conn: MongoDbCollectionTrait<'db, ToolLink>,
{
#[instrument(skip(self))]
pub async fn delete(&'db self, id: Uuid) -> OperateResult<()> {
let db = self.get_collection()?;

db.doing(|collection| collection.delete_one(doc! {"id": id}, None))
.await?;

Ok(())
}
}
Loading

0 comments on commit 848282a

Please sign in to comment.