diff --git a/server/domain/src/form/models.rs b/server/domain/src/form/models.rs index 6a4190b2..211edd31 100644 --- a/server/domain/src/form/models.rs +++ b/server/domain/src/form/models.rs @@ -1,32 +1,22 @@ -use async_trait::async_trait; use chrono::{DateTime, Utc}; #[cfg(test)] use common::test_utils::{arbitrary_date_time, arbitrary_opt_date_time, arbitrary_with_size}; use derive_getters::Getters; use deriving_via::DerivingVia; -use errors::{domain::DomainError, Error}; +use errors::domain::DomainError; #[cfg(test)] use proptest_derive::Arbitrary; use serde::{Deserialize, Serialize}; use strum_macros::{Display, EnumString}; use typed_builder::TypedBuilder; -use types::Resolver; use crate::{ - repository::form_repository::FormRepository, types::authorization_guard::AuthorizationGuardDefinitions, user::models::{Role::Administrator, User}, }; pub type FormId = types::IntegerId
; -#[async_trait] -impl Resolver for FormId { - async fn resolve(&self, repo: &Repo) -> Result, Error> { - repo.get(self.to_owned()).await - } -} - #[derive(Deserialize, Debug)] pub struct OffsetAndLimit { #[serde(default)] @@ -218,13 +208,6 @@ impl DefaultAnswerTitle { pub type AnswerId = types::IntegerId; -#[async_trait] -impl Resolver for AnswerId { - async fn resolve(&self, repo: &Repo) -> Result, Error> { - repo.get_answers(self.to_owned()).await - } -} - #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct FormAnswer { pub id: AnswerId, diff --git a/server/infra/resource/src/repository/form_repository_impl.rs b/server/infra/resource/src/repository/form_repository_impl.rs index 1096ef0b..06f26b45 100644 --- a/server/infra/resource/src/repository/form_repository_impl.rs +++ b/server/infra/resource/src/repository/form_repository_impl.rs @@ -12,7 +12,6 @@ use domain::{ use errors::{domain::DomainError, infra::InfraError::AnswerNotFount, Error}; use futures::{stream, stream::StreamExt}; use outgoing::form_outgoing; -use types::Resolver; use crate::{ database::components::{DatabaseComponents, FormDatabase}, @@ -303,7 +302,7 @@ impl FormRepository for Repository } async fn post_comment(&self, answer_id: AnswerId, comment: &Comment) -> Result<(), Error> { - let posted_answers = answer_id.resolve(self).await?.ok_or(AnswerNotFount { + let posted_answers = self.get_answers(answer_id).await?.ok_or(AnswerNotFount { id: answer_id.into_inner(), })?; diff --git a/server/types/src/lib.rs b/server/types/src/lib.rs index 1feca007..45ee6227 100644 --- a/server/types/src/lib.rs +++ b/server/types/src/lib.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; #[cfg(feature = "arbitrary")] use common::test_utils::arbitrary_uuid_v7; use deriving_via::DerivingVia; @@ -36,8 +35,3 @@ impl Id { Self(Uuid::now_v7(), std::marker::PhantomData) } } - -#[async_trait] -pub trait Resolver { - async fn resolve(&self, repo: &Repo) -> Result, Error>; -} diff --git a/server/usecase/src/form.rs b/server/usecase/src/form.rs index 888a6bb7..2ecaac6d 100644 --- a/server/usecase/src/form.rs +++ b/server/usecase/src/form.rs @@ -26,7 +26,6 @@ use futures::{ future::{join_all, OptionFuture}, stream, try_join, StreamExt, }; -use types::Resolver; use crate::dto::AnswerDto; @@ -146,23 +145,22 @@ impl FormUseCase<'_, R1, R2> { title: DefaultAnswerTitle, answers: Vec, ) -> Result<(), Error> { - let is_within_period = form_id - .resolve(self.form_repository) - .await? - .and_then(|form| { - let response_period = form.settings.response_period; - - response_period - .start_at - .zip(response_period.end_at) - .map(|(start_at, end_at)| { - let now = Utc::now(); - now >= start_at && now <= end_at - }) - }) - // Note: Noneの場合はフォームが存在していないかそもそも回答期間が無いフォーム - .unwrap_or(true); - + let is_within_period = + self.form_repository + .get(form_id) + .await? + .and_then(|form| { + let response_period = form.settings.response_period; + + response_period.start_at.zip(response_period.end_at).map( + |(start_at, end_at)| { + let now = Utc::now(); + now >= start_at && now <= end_at + }, + ) + }) + // Note: Noneの場合はフォームが存在していないかそもそも回答期間が無いフォーム + .unwrap_or(true); if is_within_period { self.form_repository .post_answer(user, form_id, title, answers) @@ -276,14 +274,15 @@ impl FormUseCase<'_, R1, R2> { let can_post_comment = match comment.commented_by.role { Administrator => true, StandardUser => { - let answer = answer_id - .resolve(self.form_repository) + let answer = self + .form_repository + .get_answers(answer_id) .await? .ok_or(AnswerNotFound)?; - let form = answer - .form_id - .resolve(self.form_repository) + let form = self + .form_repository + .get(answer.form_id) .await? .ok_or(FormNotFound)?;