BLOG-56 refactor: make use cases stateless
This commit is contained in:
parent
9dcefe90c5
commit
5ea5879ad7
@ -1,5 +1,3 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
||||||
use crate::application::{
|
use crate::application::{
|
||||||
@ -23,14 +21,14 @@ pub trait PostController: Send + Sync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct PostControllerImpl {
|
pub struct PostControllerImpl {
|
||||||
get_all_post_info_use_case: Arc<dyn GetAllPostInfoUseCase>,
|
get_all_post_info_use_case: Box<dyn GetAllPostInfoUseCase>,
|
||||||
get_full_post_use_case: Arc<dyn GetFullPostUseCase>,
|
get_full_post_use_case: Box<dyn GetFullPostUseCase>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PostControllerImpl {
|
impl PostControllerImpl {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
get_all_post_info_use_case: Arc<dyn GetAllPostInfoUseCase>,
|
get_all_post_info_use_case: Box<dyn GetAllPostInfoUseCase>,
|
||||||
get_full_post_use_case: Arc<dyn GetFullPostUseCase>,
|
get_full_post_use_case: Box<dyn GetFullPostUseCase>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
get_all_post_info_use_case,
|
get_all_post_info_use_case,
|
||||||
@ -45,7 +43,10 @@ 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.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| {
|
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
|
||||||
|
@ -25,6 +25,8 @@ 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.get_all_post_info(is_published_only).await
|
self.post_repository
|
||||||
|
.get_all_post_info(is_published_only)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,8 @@ impl Container {
|
|||||||
let post_repository = Arc::new(PostRepositoryImpl::new(post_db_service.clone()));
|
let post_repository = Arc::new(PostRepositoryImpl::new(post_db_service.clone()));
|
||||||
|
|
||||||
let get_all_post_info_use_case =
|
let get_all_post_info_use_case =
|
||||||
Arc::new(GetAllPostInfoUseCaseImpl::new(post_repository.clone()));
|
Box::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 = Box::new(GetFullPostUseCaseImpl::new(post_repository.clone()));
|
||||||
|
|
||||||
let post_controller = Arc::new(PostControllerImpl::new(
|
let post_controller = Arc::new(PostControllerImpl::new(
|
||||||
get_all_post_info_use_case,
|
get_all_post_info_use_case,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user