Skip to content

Commit

Permalink
feat: 申請の回答取得時に回答した企画と申請を返すように
Browse files Browse the repository at this point in the history
  • Loading branch information
arata-nvm committed Apr 2, 2024
1 parent 20549d2 commit 7415b5a
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 22 deletions.
4 changes: 4 additions & 0 deletions crates/sos24-presentation/src/model/form_answer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FormAnswerItem>,
created_at: String,
updated_at: String,
Expand All @@ -74,7 +76,9 @@ impl From<FormAnswerDto> 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()
Expand Down
21 changes: 15 additions & 6 deletions crates/sos24-use-case/src/dto/form_answer.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -57,29 +59,36 @@ 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<FormAnswerItemDto>,
pub created_at: chrono::DateTime<chrono::Utc>,
pub updated_at: chrono::DateTime<chrono::Utc>,
pub deleted_at: Option<chrono::DateTime<chrono::Utc>>,
}

impl FromEntity for FormAnswerDto {
type Entity = WithDate<FormAnswer>;
fn from_entity(entity: Self::Entity) -> Self {
let form_answer = entity.value.destruct();
type Entity = (WithDate<FormAnswer>, WithDate<Project>, WithDate<Form>);
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,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use sos24_domain::repository::project::ProjectRepository;
use sos24_domain::{
ensure,
entity::{form::FormId, permission::Permissions},
Expand All @@ -23,7 +24,7 @@ impl<R: Repositories> FormAnswerUseCase<R> {
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())
Expand All @@ -36,10 +37,23 @@ impl<R: Repositories> FormAnswerUseCase<R> {
.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)
}
}

Expand Down
27 changes: 24 additions & 3 deletions crates/sos24-use-case/src/interactor/form_answer/find_by_id.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use sos24_domain::repository::form::FormRepository;
use sos24_domain::{
ensure,
entity::form_answer::FormAnswerId,
Expand Down Expand Up @@ -30,15 +31,27 @@ impl<R: Repositories> FormAnswerUseCase<R> {
.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,
)))
}
}

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use sos24_domain::repository::form::FormRepository;
use sos24_domain::{
ensure,
entity::project::ProjectId,
Expand Down Expand Up @@ -36,10 +37,23 @@ impl<R: Repositories> FormAnswerUseCase<R> {
.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)
}
}

Expand Down
33 changes: 29 additions & 4 deletions crates/sos24-use-case/src/interactor/form_answer/list.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -19,10 +21,33 @@ impl<R: Repositories> FormAnswerUseCase<R> {
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)
}
}

Expand Down

0 comments on commit 7415b5a

Please sign in to comment.