BLOG-56 refactor: make use cases stateless
Some checks failed
Frontend CI / build (push) Successful in 1m27s
PR Title Check / pr-title-check (pull_request) Failing after 16s

This commit is contained in:
Yu Squire[ Yu, Tsung-Ying ] 2025-07-01 11:39:42 +08:00
parent 9dcefe90c5
commit 5ea5879ad7
3 changed files with 13 additions and 10 deletions

View File

@ -1,5 +1,3 @@
use std::sync::Arc;
use async_trait::async_trait;
use crate::application::{
@ -23,14 +21,14 @@ pub trait PostController: Send + Sync {
}
pub struct PostControllerImpl {
get_all_post_info_use_case: Arc<dyn GetAllPostInfoUseCase>,
get_full_post_use_case: Arc<dyn GetFullPostUseCase>,
get_all_post_info_use_case: Box<dyn GetAllPostInfoUseCase>,
get_full_post_use_case: Box<dyn GetFullPostUseCase>,
}
impl PostControllerImpl {
pub fn new(
get_all_post_info_use_case: Arc<dyn GetAllPostInfoUseCase>,
get_full_post_use_case: Arc<dyn GetFullPostUseCase>,
get_all_post_info_use_case: Box<dyn GetAllPostInfoUseCase>,
get_full_post_use_case: Box<dyn GetFullPostUseCase>,
) -> Self {
Self {
get_all_post_info_use_case,
@ -45,7 +43,10 @@ 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

View File

@ -25,6 +25,8 @@ 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
}
}

View File

@ -24,8 +24,8 @@ impl Container {
let post_repository = Arc::new(PostRepositoryImpl::new(post_db_service.clone()));
let get_all_post_info_use_case =
Arc::new(GetAllPostInfoUseCaseImpl::new(post_repository.clone()));
let get_full_post_use_case = Arc::new(GetFullPostUseCaseImpl::new(post_repository.clone()));
Box::new(GetAllPostInfoUseCaseImpl::new(post_repository.clone()));
let get_full_post_use_case = Box::new(GetFullPostUseCaseImpl::new(post_repository.clone()));
let post_controller = Arc::new(PostControllerImpl::new(
get_all_post_info_use_case,