RustX Document Help

GenerateDTO

Generate dto model

If you are using Entity generated by sea orm data, you can quickly generate dto entities.

Generated naming method: Table names with underscores will be automatically named in camel case.

tag_post-> TagPost

1.gif

Example

data model

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] #[sea_orm(table_name = "post")] pub struct Model { #[sea_orm(primary_key)] pub id: i32, pub title: String, pub content: String, pub category_id: i32, }

generated content

#[derive(Deserialize, Debug, Validate, ToSchema, Default)] pub struct PostAddRequest { #[salvo(schema(example = "test"), parameter(description = "标题"))] pub title: String, #[salvo(schema(example = "test content"))] pub content: String, #[salvo(schema(example = 1))] pub category_id: i32, } #[derive(Debug, Deserialize, Extractible, ToSchema, Default)] #[salvo(extract(default_source(from = "body", parse = "json")))] pub struct PostUpdateRequest { #[salvo(extract(source(from = "param")))] pub id: i32, pub title: String, pub content: String, pub category_id: i32, } #[derive(Debug, Serialize, ToSchema, Default)] pub struct PostResponse { pub id: i32, pub title: String, pub content: String, pub category_id: i32, pub category: Option<CategoryResponse>, }
Last modified: 03 August 2024