Compare commits

..

1 Commits

Author SHA1 Message Date
Yu Squire[ Yu, Tsung-Ying ]
1dc8ca742b BLOG-56 refactor: remove adoundence Arc
Some checks failed
Frontend CI / build (push) Successful in 1m28s
PR Title Check / pr-title-check (pull_request) Failing after 16s
2025-07-01 12:28:25 +08:00
5 changed files with 20 additions and 42 deletions

View File

@ -45,10 +45,7 @@ impl PostController for PostControllerImpl {
&self, &self,
is_published_only: bool, is_published_only: bool,
) -> Result<Vec<PostInfoResponseDto>, PostError> { ) -> Result<Vec<PostInfoResponseDto>, PostError> {
let result = self let result = self.get_all_post_info_use_case.execute(is_published_only).await;
.get_all_post_info_use_case
.execute(is_published_only)
.await;
result.map(|post_info_list| { result.map(|post_info_list| {
let post_info_response_dto_list: Vec<PostInfoResponseDto> = post_info_list let post_info_response_dto_list: Vec<PostInfoResponseDto> = post_info_list

View File

@ -25,8 +25,6 @@ impl GetAllPostInfoUseCaseImpl {
#[async_trait] #[async_trait]
impl GetAllPostInfoUseCase for GetAllPostInfoUseCaseImpl { impl GetAllPostInfoUseCase for GetAllPostInfoUseCaseImpl {
async fn execute(&self, is_published_only: bool) -> Result<Vec<PostInfo>, PostError> { async fn execute(&self, is_published_only: bool) -> Result<Vec<PostInfo>, PostError> {
self.post_repository self.post_repository.get_all_post_info(is_published_only).await
.get_all_post_info(is_published_only)
.await
} }
} }

View File

@ -1,17 +1,8 @@
use actix_web::{HttpResponse, Responder, web}; use actix_web::{HttpResponse, Responder, web};
use crate::{ use crate::{
adapter::delivery::{ adapter::delivery::{post_controller::PostController, post_info_query_dto::PostQueryDto},
post_controller::{PostController, PostControllerImpl}, application::error::post_error::PostError,
post_info_query_dto::PostQueryDto,
},
application::{
error::post_error::PostError,
use_case::{
get_all_post_info_use_case::GetAllPostInfoUseCase,
get_full_post_use_case::GetFullPostUseCase,
},
},
}; };
pub fn configure_post_routes(cfg: &mut web::ServiceConfig) { pub fn configure_post_routes(cfg: &mut web::ServiceConfig) {
@ -23,15 +14,9 @@ pub fn configure_post_routes(cfg: &mut web::ServiceConfig) {
} }
async fn get_all_post_info_handler( async fn get_all_post_info_handler(
get_all_post_info_use_case: web::Data<dyn GetAllPostInfoUseCase>, post_controller: web::Data<dyn PostController>,
get_full_post_use_case: web::Data<dyn GetFullPostUseCase>,
query: web::Query<PostQueryDto>, query: web::Query<PostQueryDto>,
) -> impl Responder { ) -> impl Responder {
let post_controller = PostControllerImpl::new(
get_all_post_info_use_case.into_inner(),
get_full_post_use_case.into_inner(),
);
let is_published_only = query.is_published_only.unwrap_or_else(|| true); let is_published_only = query.is_published_only.unwrap_or_else(|| true);
let result = post_controller.get_all_post_info(is_published_only).await; let result = post_controller.get_all_post_info(is_published_only).await;
@ -45,15 +30,9 @@ async fn get_all_post_info_handler(
} }
async fn get_full_post_handler( async fn get_full_post_handler(
get_all_post_info_use_case: web::Data<dyn GetAllPostInfoUseCase>, post_controller: web::Data<dyn PostController>,
get_full_post_use_case: web::Data<dyn GetFullPostUseCase>,
path: web::Path<i32>, path: web::Path<i32>,
) -> impl Responder { ) -> impl Responder {
let post_controller = PostControllerImpl::new(
get_all_post_info_use_case.into_inner(),
get_full_post_use_case.into_inner(),
);
let id = path.into_inner(); let id = path.into_inner();
let result = post_controller.get_full_post(id).await; let result = post_controller.get_full_post(id).await;

View File

@ -1,18 +1,20 @@
use std::sync::Arc; use std::sync::Arc;
use post::{ use post::{
adapter::gateway::post_repository_impl::PostRepositoryImpl, adapter::{
delivery::post_controller::{PostController, PostControllerImpl},
gateway::post_repository_impl::PostRepositoryImpl,
},
application::use_case::{ application::use_case::{
get_all_post_info_use_case::{GetAllPostInfoUseCase, GetAllPostInfoUseCaseImpl}, get_all_post_info_use_case::GetAllPostInfoUseCaseImpl,
get_full_post_use_case::{GetFullPostUseCase, GetFullPostUseCaseImpl}, get_full_post_use_case::GetFullPostUseCaseImpl,
}, },
framework::db::post_db_service_impl::PostDbServiceImpl, framework::db::post_db_service_impl::PostDbServiceImpl,
}; };
use sqlx::{Pool, Postgres}; use sqlx::{Pool, Postgres};
pub struct Container { pub struct Container {
pub get_all_post_info_use_case: Arc<dyn GetAllPostInfoUseCase>, pub post_controller: Arc<dyn PostController>,
pub get_full_post_use_case: Arc<dyn GetFullPostUseCase>,
} }
impl Container { impl Container {
@ -25,9 +27,11 @@ impl Container {
Arc::new(GetAllPostInfoUseCaseImpl::new(post_repository.clone())); Arc::new(GetAllPostInfoUseCaseImpl::new(post_repository.clone()));
let get_full_post_use_case = Arc::new(GetFullPostUseCaseImpl::new(post_repository.clone())); let get_full_post_use_case = Arc::new(GetFullPostUseCaseImpl::new(post_repository.clone()));
Self { let post_controller = Arc::new(PostControllerImpl::new(
get_all_post_info_use_case, get_all_post_info_use_case,
get_full_post_use_case, get_full_post_use_case,
} ));
Self { post_controller }
} }
} }

View File

@ -51,10 +51,10 @@ fn create_app(
Error = Error, Error = Error,
>, >,
> { > {
let container = Container::new(db_pool); let container = Container::new(db_pool.clone());
App::new() App::new()
.app_data(web::Data::from(container.get_all_post_info_use_case)) .app_data(web::Data::new(db_pool))
.app_data(web::Data::from(container.get_full_post_use_case)) .app_data(web::Data::from(container.post_controller))
.configure(configure_post_routes) .configure(configure_post_routes)
} }