From 7415b5a1350c92e5926763d871e16407cf8d1497 Mon Sep 17 00:00:00 2001 From: Arata Date: Tue, 2 Apr 2024 20:32:15 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=94=B3=E8=AB=8B=E3=81=AE=E5=9B=9E?= =?UTF-8?q?=E7=AD=94=E5=8F=96=E5=BE=97=E6=99=82=E3=81=AB=E5=9B=9E=E7=AD=94?= =?UTF-8?q?=E3=81=97=E3=81=9F=E4=BC=81=E7=94=BB=E3=81=A8=E7=94=B3=E8=AB=8B?= =?UTF-8?q?=E3=82=92=E8=BF=94=E3=81=99=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/model/form_answer.rs | 4 +++ crates/sos24-use-case/src/dto/form_answer.rs | 21 ++++++++---- .../interactor/form_answer/find_by_form_id.rs | 24 +++++++++++--- .../src/interactor/form_answer/find_by_id.rs | 27 +++++++++++++-- .../form_answer/find_by_project_id.rs | 22 ++++++++++--- .../src/interactor/form_answer/list.rs | 33 ++++++++++++++++--- 6 files changed, 109 insertions(+), 22 deletions(-) diff --git a/crates/sos24-presentation/src/model/form_answer.rs b/crates/sos24-presentation/src/model/form_answer.rs index 37827520..fb4575c0 100644 --- a/crates/sos24-presentation/src/model/form_answer.rs +++ b/crates/sos24-presentation/src/model/form_answer.rs @@ -62,7 +62,9 @@ pub struct FormAnswerQuery { pub struct FormAnswer { id: String, project_id: String, + project_title: String, form_id: String, + form_title: String, items: Vec, created_at: String, updated_at: String, @@ -74,7 +76,9 @@ impl From for FormAnswer { FormAnswer { id: form_answer_dto.id, project_id: form_answer_dto.project_id, + project_title: form_answer_dto.project_title, form_id: form_answer_dto.form_id, + form_title: form_answer_dto.form_title, items: form_answer_dto .items .into_iter() diff --git a/crates/sos24-use-case/src/dto/form_answer.rs b/crates/sos24-use-case/src/dto/form_answer.rs index f59bc9cf..366382b5 100644 --- a/crates/sos24-use-case/src/dto/form_answer.rs +++ b/crates/sos24-use-case/src/dto/form_answer.rs @@ -1,4 +1,6 @@ use sos24_domain::entity::file_data::FileId; +use sos24_domain::entity::form::Form; +use sos24_domain::entity::project::Project; use sos24_domain::entity::{ common::date::WithDate, form::{FormId, FormItemId}, @@ -57,7 +59,9 @@ impl UpdateFormAnswerDto { pub struct FormAnswerDto { pub id: String, pub project_id: String, + pub project_title: String, pub form_id: String, + pub form_title: String, pub items: Vec, pub created_at: chrono::DateTime, pub updated_at: chrono::DateTime, @@ -65,21 +69,26 @@ pub struct FormAnswerDto { } impl FromEntity for FormAnswerDto { - type Entity = WithDate; - fn from_entity(entity: Self::Entity) -> Self { - let form_answer = entity.value.destruct(); + type Entity = (WithDate, WithDate, WithDate
); + fn from_entity((form_answer_entity, project_entity, form_entity): Self::Entity) -> Self { + let form_answer = form_answer_entity.value.destruct(); + let project = project_entity.value.destruct(); + let form = form_entity.value.destruct(); + Self { id: form_answer.id.value().to_string(), project_id: form_answer.project_id.value().to_string(), + project_title: project.title.value().to_string(), form_id: form_answer.form_id.value().to_string(), + form_title: form.title.value().to_string(), items: form_answer .items .into_iter() .map(FormAnswerItemDto::from_entity) .collect(), - created_at: entity.created_at, - updated_at: entity.updated_at, - deleted_at: entity.deleted_at, + created_at: form_answer_entity.created_at, + updated_at: form_answer_entity.updated_at, + deleted_at: form_answer_entity.deleted_at, } } } diff --git a/crates/sos24-use-case/src/interactor/form_answer/find_by_form_id.rs b/crates/sos24-use-case/src/interactor/form_answer/find_by_form_id.rs index 89eb35ee..26cebf7e 100644 --- a/crates/sos24-use-case/src/interactor/form_answer/find_by_form_id.rs +++ b/crates/sos24-use-case/src/interactor/form_answer/find_by_form_id.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use sos24_domain::repository::project::ProjectRepository; use sos24_domain::{ ensure, entity::{form::FormId, permission::Permissions}, @@ -23,7 +24,7 @@ impl FormAnswerUseCase { ensure!(actor.has_permission(Permissions::READ_FORM_ANSWER_ALL)); let form_id = FormId::try_from(form_id)?; - let _form = self + let raw_form = self .repositories .form_repository() .find_by_id(form_id.clone()) @@ -36,10 +37,23 @@ impl FormAnswerUseCase { .find_by_form_id(form_id.clone()) .await?; - let form_answer_list = raw_form_answer_list - .into_iter() - .map(FormAnswerDto::from_entity); - Ok(form_answer_list.collect()) + let mut form_answer_list = Vec::new(); + for raw_form_answer in raw_form_answer_list { + let project_id = raw_form_answer.value.project_id(); + let raw_project = self + .repositories + .project_repository() + .find_by_id(project_id.clone()) + .await? + .ok_or(FormAnswerUseCaseError::ProjectNotFound(project_id.clone()))?; + form_answer_list.push(FormAnswerDto::from_entity(( + raw_form_answer, + raw_project, + raw_form.clone(), + ))); + } + + Ok(form_answer_list) } } diff --git a/crates/sos24-use-case/src/interactor/form_answer/find_by_id.rs b/crates/sos24-use-case/src/interactor/form_answer/find_by_id.rs index 8a05dc3c..cdc7d210 100644 --- a/crates/sos24-use-case/src/interactor/form_answer/find_by_id.rs +++ b/crates/sos24-use-case/src/interactor/form_answer/find_by_id.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use sos24_domain::repository::form::FormRepository; use sos24_domain::{ ensure, entity::form_answer::FormAnswerId, @@ -30,15 +31,27 @@ impl FormAnswerUseCase { .ok_or(FormAnswerUseCaseError::NotFound(id))?; let project_id = form_answer.value.project_id(); - let project = self + let raw_project = self .repositories .project_repository() .find_by_id(project_id.clone()) .await? .ok_or(FormAnswerUseCaseError::ProjectNotFound(project_id.clone()))?; - ensure!(project.value.is_visible_to(&actor)); + ensure!(raw_project.value.is_visible_to(&actor)); - Ok(FormAnswerDto::from_entity(form_answer)) + let form_id = form_answer.value.form_id(); + let raw_form = self + .repositories + .form_repository() + .find_by_id(form_id.clone()) + .await? + .ok_or(FormAnswerUseCaseError::FormNotFound(form_id.clone()))?; + + Ok(FormAnswerDto::from_entity(( + form_answer, + raw_project, + raw_form, + ))) } } @@ -75,6 +88,10 @@ mod tests { fixture::user::id1(), )))) }); + repositories + .form_repository_mut() + .expect_find_by_id() + .returning(|_| Ok(Some(fixture::date::with(fixture::form::form1())))); let use_case = FormAnswerUseCase::new(Arc::new(repositories)); let ctx = Context::with_actor(fixture::actor::actor1(UserRole::General)); @@ -136,6 +153,10 @@ mod tests { fixture::user::id2(), )))) }); + repositories + .form_repository_mut() + .expect_find_by_id() + .returning(|_| Ok(Some(fixture::date::with(fixture::form::form1())))); let use_case = FormAnswerUseCase::new(Arc::new(repositories)); let ctx = Context::with_actor(fixture::actor::actor1(UserRole::Committee)); diff --git a/crates/sos24-use-case/src/interactor/form_answer/find_by_project_id.rs b/crates/sos24-use-case/src/interactor/form_answer/find_by_project_id.rs index a5d69b78..ad3eda37 100644 --- a/crates/sos24-use-case/src/interactor/form_answer/find_by_project_id.rs +++ b/crates/sos24-use-case/src/interactor/form_answer/find_by_project_id.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use sos24_domain::repository::form::FormRepository; use sos24_domain::{ ensure, entity::project::ProjectId, @@ -36,10 +37,23 @@ impl FormAnswerUseCase { .find_by_project_id(project_id.clone()) .await?; - let form_answer_list = raw_form_answer_list - .into_iter() - .map(FormAnswerDto::from_entity); - Ok(form_answer_list.collect()) + let mut form_answer_list = Vec::new(); + for raw_form_answer in raw_form_answer_list { + let form_id = raw_form_answer.value.form_id(); + let raw_form = self + .repositories + .form_repository() + .find_by_id(form_id.clone()) + .await? + .ok_or(FormAnswerUseCaseError::FormNotFound(form_id.clone()))?; + form_answer_list.push(FormAnswerDto::from_entity(( + raw_form_answer, + project.clone(), + raw_form, + ))); + } + + Ok(form_answer_list) } } diff --git a/crates/sos24-use-case/src/interactor/form_answer/list.rs b/crates/sos24-use-case/src/interactor/form_answer/list.rs index 0bcc7af8..cf45ac77 100644 --- a/crates/sos24-use-case/src/interactor/form_answer/list.rs +++ b/crates/sos24-use-case/src/interactor/form_answer/list.rs @@ -1,5 +1,7 @@ use std::sync::Arc; +use sos24_domain::repository::form::FormRepository; +use sos24_domain::repository::project::ProjectRepository; use sos24_domain::{ ensure, entity::permission::Permissions, @@ -19,10 +21,33 @@ impl FormAnswerUseCase { ensure!(actor.has_permission(Permissions::READ_FORM_ANSWER_ALL)); let raw_form_answer_list = self.repositories.form_answer_repository().list().await?; - let form_answer_list = raw_form_answer_list - .into_iter() - .map(FormAnswerDto::from_entity); - Ok(form_answer_list.collect()) + + let mut form_answer_list = Vec::new(); + for raw_form_answer in raw_form_answer_list { + let project_id = raw_form_answer.value.project_id(); + let raw_project = self + .repositories + .project_repository() + .find_by_id(project_id.clone()) + .await? + .ok_or(FormAnswerUseCaseError::ProjectNotFound(project_id.clone()))?; + + let form_id = raw_form_answer.value.form_id(); + let raw_form = self + .repositories + .form_repository() + .find_by_id(form_id.clone()) + .await? + .ok_or(FormAnswerUseCaseError::FormNotFound(form_id.clone()))?; + + form_answer_list.push(FormAnswerDto::from_entity(( + raw_form_answer, + raw_project, + raw_form, + ))); + } + + Ok(form_answer_list) } }