-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from Enraged-Dun-Cookie-Development-Team/feat…
…-工具友链新增 工具友链新增
- Loading branch information
Showing
20 changed files
with
309 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,56 @@ | ||
use persistence::ceobe_operate::models::tool_link::{ | ||
self, models::model_tool_link::FrontendToolLink, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
use typed_builder::TypedBuilder; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)] | ||
use crate::error::LogicError; | ||
|
||
#[derive(Debug, Clone, Deserialize, TypedBuilder)] | ||
pub struct DeleteOneToolLinkReq { | ||
pub id: i32, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, TypedBuilder)] | ||
pub struct ToolLinkResp { | ||
#[builder(default)] | ||
#[serde(default, skip_serializing_if = "Option::is_none")] | ||
pub id: Option<i32>, | ||
pub nickname: String, | ||
pub avatar: String, | ||
pub jump_url: String, | ||
pub slogan: String, | ||
pub description: String, | ||
pub tags: Vec<String>, | ||
} | ||
|
||
impl TryInto<ToolLinkResp> for tool_link::Model { | ||
type Error = LogicError; | ||
|
||
fn try_into(self) -> Result<ToolLinkResp, Self::Error> { | ||
Ok(ToolLinkResp::builder() | ||
.id(Some(self.id)) | ||
.avatar(self.avatar) | ||
.nickname(self.nickname) | ||
.jump_url(self.jump_url) | ||
.slogan(self.slogan) | ||
.description(self.description) | ||
.tags(serde_json::from_str::<Vec<String>>(&self.tags)?) | ||
.build()) | ||
} | ||
} | ||
|
||
impl TryInto<ToolLinkResp> for FrontendToolLink { | ||
type Error = LogicError; | ||
|
||
fn try_into(self) -> Result<ToolLinkResp, Self::Error> { | ||
Ok(ToolLinkResp::builder() | ||
.avatar(self.avatar) | ||
.nickname(self.nickname) | ||
.jump_url(self.jump_url) | ||
.slogan(self.slogan) | ||
.description(self.description) | ||
.tags(serde_json::from_str::<Vec<String>>(&self.tags)?) | ||
.build()) | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
persistence/migrate/sql-migration/src/admin/m20240519_011405_alter_auth.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use sea_orm_migration::{ | ||
prelude::*, | ||
sea_orm::{DeriveActiveEnum, EnumIter}, | ||
}; | ||
use sql_models::admin_user::{AuthLevel, Column::Auth}; | ||
|
||
use super::m20220722_082735_change_user_table_name::AdminUser; | ||
|
||
pub struct Migration; | ||
impl MigrationName for Migration { | ||
fn name(&self) -> &str { "m20240519_011405_admin_alter_auth" } | ||
} | ||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
let mut al = sea_query::Table::alter(); | ||
al.table(AdminUser::Table).modify_column( | ||
ColumnDef::new_with_type(Auth, AuthLevel::column_type()) | ||
.not_null(), | ||
); | ||
manager.alter_table(al).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
// 这边回滚需要删除一下authlevel中的Outsourcing | ||
let mut al = sea_query::Table::alter(); | ||
al.table(AdminUser::Table).modify_column( | ||
ColumnDef::new_with_type(Auth, OldAuthLevel::column_type()) | ||
.not_null(), | ||
); | ||
manager.alter_table(al).await?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(EnumIter, DeriveActiveEnum)] | ||
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "auth")] | ||
pub enum OldAuthLevel { | ||
#[sea_orm(string_value = "chef")] | ||
Chef, | ||
#[sea_orm(string_value = "cooker")] | ||
Cooker, | ||
#[sea_orm(string_value = "architect")] | ||
Architect, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...istence/migrate/sql-migration/src/ceobe_operation_tool_link/m20240519_004238_add_infos.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use sea_orm_migration::prelude::*; | ||
|
||
use super::CeobeOperationToolLink; | ||
|
||
pub struct Migration; | ||
impl MigrationName for Migration { | ||
fn name(&self) -> &str { | ||
"m20240519_004238_ceobe_operation_tool_link_add_infos" | ||
} | ||
} | ||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
let mut al = sea_query::Table::alter(); | ||
al.table(CeobeOperationToolLink::Table) | ||
.add_column( | ||
ColumnDef::new(CeobeOperationToolLink::Slogan) | ||
.string_len(16) | ||
.not_null() | ||
.default(""), | ||
) | ||
.add_column( | ||
ColumnDef::new(CeobeOperationToolLink::Description) | ||
.string_len(128) | ||
.not_null() | ||
.default(""), | ||
) | ||
.add_column( | ||
ColumnDef::new(CeobeOperationToolLink::Tags) | ||
.string_len(128) | ||
.not_null() | ||
.default("[]"), | ||
); | ||
manager.alter_table(al).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
let mut al = sea_query::Table::alter(); | ||
al.table(CeobeOperationToolLink::Table) | ||
.drop_column(CeobeOperationToolLink::Slogan) | ||
.drop_column(CeobeOperationToolLink::Description) | ||
.drop_column(CeobeOperationToolLink::Tags); | ||
manager.alter_table(al).await?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
persistence/models/sql-models/src/ceobe_operation/tool_link/checkers/tags.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use checker::Checker; | ||
use futures::future::{ready, Ready}; | ||
|
||
use super::CheckError; | ||
|
||
pub struct TagSerializeChecker; | ||
|
||
impl Checker for TagSerializeChecker { | ||
type Args = (); | ||
type Checked = String; | ||
type Err = CheckError; | ||
type Fut = Ready<Result<String, Self::Err>>; | ||
type Unchecked = Vec<String>; | ||
|
||
fn check(_: Self::Args, uncheck: Self::Unchecked) -> Self::Fut { | ||
ready(serde_json::to_string(&uncheck).map_err(Into::into)) | ||
} | ||
} |
Oops, something went wrong.