Compare commits
1 Commits
6a2c35a74a
...
1dc8ca742b
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1dc8ca742b |
@ -45,10 +45,7 @@ impl PostController for PostControllerImpl {
|
||||
&self,
|
||||
is_published_only: bool,
|
||||
) -> Result<Vec<PostInfoResponseDto>, PostError> {
|
||||
let result = self
|
||||
.get_all_post_info_use_case
|
||||
.execute(is_published_only)
|
||||
.await;
|
||||
let result = self.get_all_post_info_use_case.execute(is_published_only).await;
|
||||
|
||||
result.map(|post_info_list| {
|
||||
let post_info_response_dto_list: Vec<PostInfoResponseDto> = post_info_list
|
||||
|
@ -25,8 +25,6 @@ impl GetAllPostInfoUseCaseImpl {
|
||||
#[async_trait]
|
||||
impl GetAllPostInfoUseCase for GetAllPostInfoUseCaseImpl {
|
||||
async fn execute(&self, is_published_only: bool) -> Result<Vec<PostInfo>, PostError> {
|
||||
self.post_repository
|
||||
.get_all_post_info(is_published_only)
|
||||
.await
|
||||
self.post_repository.get_all_post_info(is_published_only).await
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,8 @@
|
||||
use actix_web::{HttpResponse, Responder, web};
|
||||
|
||||
use crate::{
|
||||
adapter::delivery::{
|
||||
post_controller::{PostController, PostControllerImpl},
|
||||
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,
|
||||
},
|
||||
},
|
||||
adapter::delivery::{post_controller::PostController, post_info_query_dto::PostQueryDto},
|
||||
application::error::post_error::PostError,
|
||||
};
|
||||
|
||||
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(
|
||||
get_all_post_info_use_case: web::Data<dyn GetAllPostInfoUseCase>,
|
||||
get_full_post_use_case: web::Data<dyn GetFullPostUseCase>,
|
||||
post_controller: web::Data<dyn PostController>,
|
||||
query: web::Query<PostQueryDto>,
|
||||
) -> 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 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(
|
||||
get_all_post_info_use_case: web::Data<dyn GetAllPostInfoUseCase>,
|
||||
get_full_post_use_case: web::Data<dyn GetFullPostUseCase>,
|
||||
post_controller: web::Data<dyn PostController>,
|
||||
path: web::Path<i32>,
|
||||
) -> 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 result = post_controller.get_full_post(id).await;
|
||||
|
||||
|
@ -1,18 +1,20 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use post::{
|
||||
adapter::gateway::post_repository_impl::PostRepositoryImpl,
|
||||
adapter::{
|
||||
delivery::post_controller::{PostController, PostControllerImpl},
|
||||
gateway::post_repository_impl::PostRepositoryImpl,
|
||||
},
|
||||
application::use_case::{
|
||||
get_all_post_info_use_case::{GetAllPostInfoUseCase, GetAllPostInfoUseCaseImpl},
|
||||
get_full_post_use_case::{GetFullPostUseCase, GetFullPostUseCaseImpl},
|
||||
get_all_post_info_use_case::GetAllPostInfoUseCaseImpl,
|
||||
get_full_post_use_case::GetFullPostUseCaseImpl,
|
||||
},
|
||||
framework::db::post_db_service_impl::PostDbServiceImpl,
|
||||
};
|
||||
use sqlx::{Pool, Postgres};
|
||||
|
||||
pub struct Container {
|
||||
pub get_all_post_info_use_case: Arc<dyn GetAllPostInfoUseCase>,
|
||||
pub get_full_post_use_case: Arc<dyn GetFullPostUseCase>,
|
||||
pub post_controller: Arc<dyn PostController>,
|
||||
}
|
||||
|
||||
impl Container {
|
||||
@ -25,9 +27,11 @@ impl Container {
|
||||
Arc::new(GetAllPostInfoUseCaseImpl::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_full_post_use_case,
|
||||
}
|
||||
));
|
||||
|
||||
Self { post_controller }
|
||||
}
|
||||
}
|
||||
|
@ -51,10 +51,10 @@ fn create_app(
|
||||
Error = Error,
|
||||
>,
|
||||
> {
|
||||
let container = Container::new(db_pool);
|
||||
let container = Container::new(db_pool.clone());
|
||||
|
||||
App::new()
|
||||
.app_data(web::Data::from(container.get_all_post_info_use_case))
|
||||
.app_data(web::Data::from(container.get_full_post_use_case))
|
||||
.app_data(web::Data::new(db_pool))
|
||||
.app_data(web::Data::from(container.post_controller))
|
||||
.configure(configure_post_routes)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user