diff --git a/Cargo.lock b/Cargo.lock index 932b1b0..9e0edb4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -85,9 +85,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1" [[package]] name = "atty" @@ -1238,7 +1238,7 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "salvo-cli" -version = "0.1.44" +version = "0.1.45" dependencies = [ "ansi_term", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index ada7963..00f1cea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "salvo-cli" -version = "0.1.45" +version = "0.1.46" edition = "2021" authors = ["Fankai Liu liufankai137@outlook.com","mrxiaozhuox mrxzx.info@gmail.com"] keywords = ["salvo", "cli","template"] @@ -15,7 +15,7 @@ path = "src/main.rs" [dependencies] ansi_term = "0.12.1" -anyhow = "1.0.75" +anyhow = "1.0.80" clap = { version = "4.4.4", features = ["derive"] } dialoguer = "0.10.4" git2 = "0.18.1" diff --git a/locales/readme.yml b/locales/readme.yml index df23895..5889467 100644 --- a/locales/readme.yml +++ b/locales/readme.yml @@ -377,7 +377,7 @@ src_main_rs: th: จุดเริ่มต้นของแอปพลิเคชัน ตั้งค่าและเริ่มต้นบริการ el: Σημείο εισόδου της εφαρμογής, ρυθμίζει και εκκινεί τις υπηρεσίες da: Programmets indgangspunkt, opsætter og starter tjenester -src_app_response_rs: +src_app_writer_rs: en: Standardize response zh_CN: 规范化返回请求 zh_TW: 規範化返回請求 diff --git a/src/template/src/app_response.hbs b/src/template/src/app_writer.hbs similarity index 92% rename from src/template/src/app_response.hbs rename to src/template/src/app_writer.hbs index fae9ef9..0078bef 100644 --- a/src/template/src/app_response.hbs +++ b/src/template/src/app_writer.hbs @@ -6,10 +6,10 @@ use serde::Serialize; use crate::app_error::AppError; -pub struct AppResponse(pub AppResult); +pub struct AppWriter(pub AppResult); #[async_trait] -impl Writer for AppResponse { +impl Writer for AppWriter { async fn write(self, req: &mut Request, depot: &mut Depot, res: &mut Response) { match self.0 { Ok(data) => ResponseBuilder::with_data(data).into_response(res), @@ -18,7 +18,7 @@ impl Writer for AppResponse { } } -impl EndpointOutRegister for AppResponse { +impl EndpointOutRegister for AppWriter { fn register(_components: &mut salvo::oapi::Components, operation: &mut salvo::oapi::Operation) { operation .responses @@ -29,15 +29,15 @@ impl EndpointOutRegister for AppResponse { } } -impl From> for AppResponse { +impl From> for AppWriter { fn from(result: AppResult) -> Self { - AppResponse(result) + AppWriter(result) } } -impl From for AppResponse { +impl From for AppWriter { fn from(result: AppError) -> Self { - AppResponse(Err(result)) + AppWriter(Err(result)) } } diff --git a/src/template/src/main_template.hbs b/src/template/src/main_template.hbs index b9936cd..e3529d7 100644 --- a/src/template/src/main_template.hbs +++ b/src/template/src/main_template.hbs @@ -21,7 +21,7 @@ mod app_error; {{else}} #[allow(dead_code)] {{/if}} -mod app_response; +mod app_writer; mod config; {{#if need_db_conn}} mod db; diff --git a/src/template/src/routers/demo.hbs b/src/template/src/routers/demo.hbs index d8db368..7b47c66 100644 --- a/src/template/src/routers/demo.hbs +++ b/src/template/src/routers/demo.hbs @@ -6,7 +6,7 @@ use salvo::{oapi::endpoint, writing::Text, Request, Response}; {{else}} use salvo::oapi::endpoint; {{/if}} -use crate::app_response::AppResult; +use crate::app_writer::AppResult; {{#if is_web_site}} #[derive(Template)] diff --git a/src/template/src/routers/user.hbs b/src/template/src/routers/user.hbs index 029b7e0..b949e1d 100644 --- a/src/template/src/routers/user.hbs +++ b/src/template/src/routers/user.hbs @@ -1,6 +1,6 @@ {{#if is_web_site}} use crate::{ - app_response::{AppResponse, AppResult, ErrorResponseBuilder}, + app_writer::{AppWriter, AppResult, ErrorResponseBuilder}, dtos::user::{ UserAddRequest, UserLoginRequest, UserLoginResponse, UserResponse, UserUpdateRequest, }, @@ -78,37 +78,37 @@ pub async fn post_login(req: JsonBody, res: &mut Response) { } #[endpoint(tags("users"))] -pub async fn post_add_user(new_user: JsonBody) -> AppResponse { +pub async fn post_add_user(new_user: JsonBody) -> AppWriter { let result = user::add_user(new_user.0).await; - AppResponse(result) + AppWriter(result) } #[endpoint( tags("users"), parameters( ("id", description = "user id"), ))] -pub async fn put_update_user(req: &mut Request) -> AppResult> { +pub async fn put_update_user(req: &mut Request) -> AppResult> { let req: UserUpdateRequest = req.extract().await?; let result = user::update_user(req).await; - Ok(AppResponse(result)) + Ok(AppWriter(result)) } #[endpoint(tags("users"))] -pub async fn delete_user(id: PathParam) -> AppResponse<()> { +pub async fn delete_user(id: PathParam) -> AppWriter<()> { let result = user::delete_user(id.0).await; - AppResponse(result) + AppWriter(result) } #[endpoint(tags("users"))] -pub async fn get_users() -> AppResponse> { +pub async fn get_users() -> AppWriter> { let result = user::users().await; - AppResponse(result) + AppWriter(result) } {{else}} use crate::{ - app_response::ErrorResponseBuilder, - app_response::{AppResponse, AppResult}, + app_writer::ErrorResponseBuilder, + app_writer::{AppWriter, AppResult}, dtos::user::{ UserAddRequest, UserLoginRequest, UserLoginResponse, UserResponse, UserUpdateRequest, }, @@ -139,30 +139,30 @@ pub async fn post_login(req: JsonBody, res: &mut Response) { } #[endpoint(tags("users"))] -pub async fn post_add_user(new_user: JsonBody) -> AppResponse { +pub async fn post_add_user(new_user: JsonBody) -> AppWriter { let result = user::add_user(new_user.0).await; - AppResponse(result) + AppWriter(result) } #[endpoint( tags("users"), parameters( ("id", description = "user id"), ))] -pub async fn put_update_user(req: &mut Request) -> AppResult> { +pub async fn put_update_user(req: &mut Request) -> AppResult> { let req: UserUpdateRequest = req.extract().await?; let result = user::update_user(req).await; - Ok(AppResponse(result)) + Ok(AppWriter(result)) } #[endpoint(tags("users"))] -pub async fn delete_user(id: PathParam) -> AppResponse<()> { +pub async fn delete_user(id: PathParam) -> AppWriter<()> { let result = user::delete_user(id.0).await; - AppResponse(result) + AppWriter(result) } #[endpoint(tags("users"))] -pub async fn get_users() -> AppResponse> { +pub async fn get_users() -> AppWriter> { let result = user::users().await; - AppResponse(result) + AppWriter(result) } {{/if}} diff --git a/src/template/src/services/user.hbs b/src/template/src/services/user.hbs index a2fafde..1ac5a66 100644 --- a/src/template/src/services/user.hbs +++ b/src/template/src/services/user.hbs @@ -1,7 +1,7 @@ {{#if is_sea_orm_or_sqlx}} {{#if is_sqlx}} use crate::{ - app_response::AppResult, + app_writer::AppResult, db::DB, dtos::user::{ UserAddRequest, UserLoginRequest, UserLoginResponse, UserResponse, @@ -14,7 +14,7 @@ use crate::{ {{/if}} {{#if is_sea_orm}} use crate::{ - app_response::AppResult, + app_writer::AppResult, db::DB, dtos::user::{ UserAddRequest, UserLoginRequest, UserLoginResponse, UserResponse, @@ -223,7 +223,7 @@ use uuid::Uuid; use crate::schema::users::dsl::users as diesel_users; use crate::{ - app_response::AppResult, + app_writer::AppResult, db::establish_connection, dtos::user::{ UserAddRequest, UserLoginRequest, UserLoginResponse, UserResponse, UserUpdateRequest, @@ -355,7 +355,7 @@ pub async fn users() -> AppResult> { use uuid::Uuid; use crate::{ - app_response::AppResult, + app_writer::AppResult, dtos::user::{ UserAddRequest, UserLoginRequest, UserLoginResponse, UserResponse, UserUpdateRequest, }, @@ -437,7 +437,7 @@ pub async fn users() -> AppResult> { {{/if}} {{#if is_mongodb}} use crate::{ - app_response::AppResult, + app_writer::AppResult, db::{COLL_NAME, DB_NAME, MONGODB_CLIENT}, dtos::user::{ UserAddRequest, UserLoginRequest, UserLoginResponse, UserResponse, UserUpdateRequest, diff --git a/src/utils/create_project.rs b/src/utils/create_project.rs index f89743d..b528e6b 100644 --- a/src/utils/create_project.rs +++ b/src/utils/create_project.rs @@ -505,8 +505,8 @@ fn create_basic_file( include_str!("../template/src/app_error.hbs"), ), ( - "src/app_response.rs", - include_str!("../template/src/app_response.hbs"), + "src/app_writer.rs", + include_str!("../template/src/app_writer.hbs"), ), //src/middleware ( diff --git a/src/utils/directory2md.rs b/src/utils/directory2md.rs index 40ca1a3..7095683 100644 --- a/src/utils/directory2md.rs +++ b/src/utils/directory2md.rs @@ -21,7 +21,7 @@ static PATH_DESCRIPTIONS: Lazy> = Lazy::new(|| { m.insert("data".to_string(), t!("data")); m.insert("assets".to_string(), t!("assets")); m.insert("src".to_string(), t!("src")); - m.insert("src/app_response.rs".to_string(), t!("src_app_response_rs")); + m.insert("src/app_writer.rs".to_string(), t!("src_app_writer_rs")); m.insert("src/routers".to_string(), t!("src_routers")); m.insert("src/middleware".to_string(), t!("src_middleware")); m.insert("src/utils".to_string(), t!("src_utils"));