diff --git a/src/template/src/entities/mod.hbs b/src/template/src/entities/mod.hbs index 4e48854..50cc60b 100644 --- a/src/template/src/entities/mod.hbs +++ b/src/template/src/entities/mod.hbs @@ -2,11 +2,11 @@ pub mod user; {{/if}} {{#if is_sea_orm}} -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3 pub mod prelude; -pub mod user; +pub mod users; {{/if}} {{#if is_rbatis}} pub mod user; diff --git a/src/template/src/entities/prelude.hbs b/src/template/src/entities/prelude.hbs index 7c8fdd7..aad81b7 100644 --- a/src/template/src/entities/prelude.hbs +++ b/src/template/src/entities/prelude.hbs @@ -1,3 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3 + +pub use super::users::Entity as Users; -pub use super::user::Entity as User; diff --git a/src/template/src/entities/user.hbs b/src/template/src/entities/users.hbs similarity index 82% rename from src/template/src/entities/user.hbs rename to src/template/src/entities/users.hbs index c3a79ba..db038f7 100644 --- a/src/template/src/entities/user.hbs +++ b/src/template/src/entities/users.hbs @@ -10,13 +10,12 @@ pub struct User { } {{/if}} {{#if is_sea_orm}} -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3 use sea_orm::entity::prelude::*; -use serde::{Deserialize, Serialize}; -#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] -#[sea_orm(table_name = "user")] +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "users")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/src/template/src/services/user.hbs b/src/template/src/services/user.hbs index 57ae11f..1b5714a 100644 --- a/src/template/src/services/user.hbs +++ b/src/template/src/services/user.hbs @@ -21,7 +21,7 @@ use crate::{ UserUpdateRequest, }, middleware::jwt::get_token, - entities::{prelude::User,user}, + entities::{prelude::Users,users}, utils::rand_utils, }; use sea_orm::{EntityTrait, Set, ActiveModelTrait, QueryFilter, ColumnTrait}; @@ -142,12 +142,12 @@ pub async fn users() -> AppResult> { {{#if is_sea_orm}} pub async fn add_user(req: UserAddRequest) -> AppResult { let db = DB.get().ok_or(anyhow::anyhow!("{{database_connection_failed}}"))?; - let model =user::ActiveModel { + let model =users::ActiveModel { id: Set(Uuid::new_v4().to_string()), username: Set(req.username.clone()), password: Set(rand_utils::hash_password(req.password).await?), }; - let user = User::insert(model).exec(db).await?; + let user = Users::insert(model).exec(db).await?; Ok(UserResponse { id: user.last_insert_id, username: req.username, @@ -156,7 +156,7 @@ pub async fn add_user(req: UserAddRequest) -> AppResult { pub async fn login(req: UserLoginRequest) -> AppResult { let db = DB.get().ok_or(anyhow::anyhow!("{{database_connection_failed}}"))?; - let user = User::find().filter(user::Column::Username.eq(req.username)).one(db).await?; + let user = Users::find().filter(users::Column::Username.eq(req.username)).one(db).await?; if user.is_none() { return Err(anyhow::anyhow!("{{user_does_not_exist}}").into()); } @@ -180,16 +180,16 @@ pub async fn login(req: UserLoginRequest) -> AppResult { pub async fn update_user(req: UserUpdateRequest) -> AppResult { let db = DB.get().ok_or(anyhow::anyhow!("{{database_connection_failed}}"))?; - let user = User::find_by_id(req.id).one(db).await?; + let user = Users::find_by_id(req.id).one(db).await?; if user.is_none() { return Err(anyhow::anyhow!("{{user_does_not_exist}}").into()); } - let mut user: user::ActiveModel = user.unwrap().into(); + let mut user: users::ActiveModel = user.unwrap().into(); user.username = Set(req.username.to_owned()); user.password = Set(rand_utils::hash_password(req.password).await?); - let user: user::Model = user.update(db).await?; + let user: users::Model = user.update(db).await?; Ok(UserResponse { id: user.id, @@ -199,13 +199,13 @@ pub async fn update_user(req: UserUpdateRequest) -> AppResult { pub async fn delete_user(id: String) -> AppResult<()> { let db = DB.get().ok_or(anyhow::anyhow!("{{database_connection_failed}}"))?; - User::delete_by_id(id).exec(db).await?; + Users::delete_by_id(id).exec(db).await?; Ok(()) } pub async fn users() -> AppResult> { let db = DB.get().ok_or(anyhow::anyhow!("{{database_connection_failed}}"))?; - let users = User::find().all(db).await?; + let users = Users::find().all(db).await?; let res = users .into_iter() .map(|user| UserResponse { diff --git a/src/utils/create_project.rs b/src/utils/create_project.rs index a355b58..4832347 100644 --- a/src/utils/create_project.rs +++ b/src/utils/create_project.rs @@ -284,8 +284,8 @@ pub fn write_project_file( include_str!("../template/src/entities/mod.hbs"), ), ( - "src/entities/user.rs", - include_str!("../template/src/entities/user.hbs"), + "src/entities/users.rs", + include_str!("../template/src/entities/users.hbs"), ), (".env", include_str!("../template/.env.hbs")), ] @@ -411,7 +411,7 @@ pub fn write_project_file( ), ( "src/entities/user.rs", - include_str!("../template/src/entities/user.hbs"), + include_str!("../template/src/entities/users.hbs"), ), ] .as_mut(), @@ -453,7 +453,7 @@ pub fn write_project_file( ), ( "src/entities/user.rs", - include_str!("../template/src/entities/user.hbs"), + include_str!("../template/src/entities/users.hbs"), ), ] .as_mut(),