From bb54a67908c4d22523d2fd9e309c5c28a5a52dc5 Mon Sep 17 00:00:00 2001 From: mrasheduzzaman Date: Tue, 21 Nov 2023 18:29:22 +0600 Subject: [PATCH] Fix rust build --- src/controllers/user_controller.rs | 6 +---- src/main.rs | 6 ++--- src/models/user.rs | 4 +-- src/services/user_service.rs | 41 +++++++++++++++--------------- 4 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/controllers/user_controller.rs b/src/controllers/user_controller.rs index 820b696..fd026ca 100644 --- a/src/controllers/user_controller.rs +++ b/src/controllers/user_controller.rs @@ -4,11 +4,7 @@ use salvo::prelude::*; use crate::common::database::Database; #[handler] -pub async fn all_users( - req: &mut Request, - depot: &mut Depot, - res: &mut Response, -) { +pub async fn all_users(_req: &mut Request, _depot: &mut Depot, res: &mut Response) { let mut connection = Database::new().get_connection(); let users = UserService::list(&mut connection).await; res.render(Json(users)); diff --git a/src/main.rs b/src/main.rs index 4548302..629f8fb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,8 @@ mod common; mod controllers; mod models; -mod services; mod schema; +mod services; use controllers::user_controller; use dotenv::dotenv; @@ -21,13 +21,11 @@ async fn main() { dotenv().ok(); - let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is not set in .env file"); let host = env::var("HOST").expect("HOST is not set in .env file"); let port = env::var("PORT").expect("PORT is not set in .env file"); let server_url = format!("{host}:{port}"); - let router = Router::new() - .get(user_controller::all_users); + let router = Router::new().get(user_controller::all_users); let acceptor = TcpListener::new(server_url).bind().await; Server::new(acceptor).serve(router).await; diff --git a/src/models/user.rs b/src/models/user.rs index 2ec9b79..0d73e7f 100644 --- a/src/models/user.rs +++ b/src/models/user.rs @@ -1,11 +1,11 @@ -use serde::{Deserialize, Serialize}; use diesel::prelude::*; +use serde::{Deserialize, Serialize}; use uuid::Uuid; use crate::schema::users; #[derive(Serialize, Deserialize, Queryable, Insertable)] -#[table_name = "users"] +#[diesel(table_name = users)] pub struct User { pub id: Uuid, pub name: String, diff --git a/src/services/user_service.rs b/src/services/user_service.rs index b3bd328..5967d11 100644 --- a/src/services/user_service.rs +++ b/src/services/user_service.rs @@ -1,13 +1,12 @@ use diesel; use diesel::prelude::*; -use uuid::Uuid; +// use uuid::Uuid; use crate::common::database::Connection; use crate::models::user::User; use crate::schema::users; -use crate::schema::users::dsl::users as all_users; - +// use crate::schema::users::dsl::users as all_users; pub struct UserService; @@ -16,26 +15,26 @@ impl UserService { users::table.load::(connection).unwrap() } - pub async fn create(connection: &mut Connection, new_user: &User) -> User { - let data = User { - id: Uuid::new_v4(), - name: new_user.name.clone(), - age: new_user.age.clone() - }; + // pub async fn create(connection: &mut Connection, new_user: &User) -> User { + // let data = User { + // id: Uuid::new_v4(), + // name: new_user.name.clone(), + // age: new_user.age.clone() + // }; - let _result = diesel::insert_into(users::table).values(&data).execute(connection); + // let _result = diesel::insert_into(users::table).values(&data).execute(connection); - users::table - .order(users::id.desc()) - .first(connection) - .unwrap() - } + // users::table + // .order(users::id.desc()) + // .first(connection) + // .unwrap() + // } - pub async fn delete(connection: &mut Connection, user_id: Uuid) -> bool { - diesel::delete(users::table.find(user_id)).execute(connection).is_ok() - } + // pub async fn delete(connection: &mut Connection, user_id: Uuid) -> bool { + // diesel::delete(users::table.find(user_id)).execute(connection).is_ok() + // } - pub async fn delete_all(connection: &mut Connection) -> bool { - diesel::delete(all_users).execute(connection).is_ok() - } + // pub async fn delete_all(connection: &mut Connection) -> bool { + // diesel::delete(all_users).execute(connection).is_ok() + // } }