diff --git a/backend/feature/post/src/framework/db/post_db_service_impl.rs b/backend/feature/post/src/framework/db/post_db_service_impl.rs index b854d6b..bacbcc2 100644 --- a/backend/feature/post/src/framework/db/post_db_service_impl.rs +++ b/backend/feature/post/src/framework/db/post_db_service_impl.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, sync::Arc}; +use std::collections::HashMap; use async_trait::async_trait; use chrono::{DateTime, Utc}; @@ -16,11 +16,11 @@ use super::{ }; pub struct PostDbServiceImpl { - db_pool: Arc>, + db_pool: Pool, } impl PostDbServiceImpl { - pub fn new(db_pool: Arc>) -> Self { + pub fn new(db_pool: Pool) -> Self { Self { db_pool } } } @@ -58,7 +58,7 @@ impl PostDbService for PostDbServiceImpl { let records = query_builder .build_query_as::() - .fetch_all(&*self.db_pool) + .fetch_all(&self.db_pool) .await .map_err(|err| PostError::DatabaseError(err.to_string()))?; @@ -121,7 +121,7 @@ impl PostDbService for PostDbServiceImpl { let records = query_builder .build_query_as::() - .fetch_all(&*self.db_pool) + .fetch_all(&self.db_pool) .await .map_err(|err| PostError::DatabaseError(err.to_string()))?; diff --git a/backend/server/src/container.rs b/backend/server/src/container.rs index b1558a0..05a88fe 100644 --- a/backend/server/src/container.rs +++ b/backend/server/src/container.rs @@ -18,8 +18,8 @@ pub struct Container { } impl Container { - pub fn new(db_pool: Arc>) -> Self { - let post_db_service = Arc::new(PostDbServiceImpl::new(db_pool)); + pub fn new(db_pool: Pool) -> Self { + let post_db_service = Arc::new(PostDbServiceImpl::new(db_pool.clone())); let post_repository = Arc::new(PostRepositoryImpl::new(post_db_service.clone())); diff --git a/backend/server/src/main.rs b/backend/server/src/main.rs index ad6be51..42d7c02 100644 --- a/backend/server/src/main.rs +++ b/backend/server/src/main.rs @@ -7,7 +7,7 @@ use actix_web::{ use post::framework::web::post_web_routes::configure_post_routes; use server::container::Container; use sqlx::{Pool, Postgres, postgres::PgPoolOptions}; -use std::{env, sync::Arc}; +use std::env; #[actix_web::main] async fn main() -> std::io::Result<()> { @@ -22,7 +22,7 @@ async fn main() -> std::io::Result<()> { .await } -async fn init_database() -> Arc> { +async fn init_database() -> Pool { let database_url = env::var("DATABASE_URL") .unwrap_or_else(|_| "postgres://postgres@localhost:5432/postgres".to_string()); @@ -37,11 +37,11 @@ async fn init_database() -> Arc> { .await .expect("Failed to run database migrations"); - Arc::new(db_pool) + db_pool } fn create_app( - db_pool: Arc>, + db_pool: Pool, ) -> App< impl ServiceFactory< ServiceRequest, @@ -51,10 +51,9 @@ fn create_app( Error = Error, >, > { - let container = Container::new(db_pool.clone()); + let container = Container::new(db_pool); App::new() - .app_data(web::Data::new(db_pool)) .app_data(web::Data::from(container.post_controller)) .configure(configure_post_routes) }