diff --git a/server/domain/src/form/answer/models.rs b/server/domain/src/form/answer/models.rs index b64ffcc5..0f535568 100644 --- a/server/domain/src/form/answer/models.rs +++ b/server/domain/src/form/answer/models.rs @@ -4,7 +4,6 @@ use deriving_via::DerivingVia; #[cfg(test)] use proptest_derive::Arbitrary; use serde::{Deserialize, Serialize}; -use std::collections::HashMap; use types::non_empty_string::NonEmptyString; use crate::{ diff --git a/server/domain/src/form/answer/service.rs b/server/domain/src/form/answer/service.rs index 3f11082e..8ba576ff 100644 --- a/server/domain/src/form/answer/service.rs +++ b/server/domain/src/form/answer/service.rs @@ -2,13 +2,10 @@ use async_trait::async_trait; use chrono::Utc; use errors::{domain::DomainError, Error}; -use crate::types::verified::{Verified, Verifier}; use crate::{ - form::{ - answer::models::{AnswerEntry, AnswerTitle}, - models::{FormId, Visibility}, - }, + form::{answer::models::AnswerEntry, models::Visibility}, repository::form::form_repository::FormRepository, + types::verified::{Verified, Verifier}, user::models::User, }; @@ -39,7 +36,7 @@ impl Verifier for PostAnswerEntriesVerifi .is_within_period(Utc::now()); if is_public_form && is_within_period { - Ok(Self::new(target)) + Ok(Self::new_verified(target)) } else { Err(Error::from(DomainError::Forbidden)) } diff --git a/server/domain/src/form/models.rs b/server/domain/src/form/models.rs index 1e7e7460..64c46d69 100644 --- a/server/domain/src/form/models.rs +++ b/server/domain/src/form/models.rs @@ -1,6 +1,6 @@ use chrono::{DateTime, Utc}; #[cfg(test)] -use common::test_utils::{arbitrary_date_time, arbitrary_opt_date_time}; +use common::test_utils::arbitrary_date_time; use derive_getters::Getters; use deriving_via::DerivingVia; use errors::domain::DomainError; diff --git a/server/domain/src/form/service.rs b/server/domain/src/form/service.rs index 3934cdae..a324f901 100644 --- a/server/domain/src/form/service.rs +++ b/server/domain/src/form/service.rs @@ -88,7 +88,10 @@ mod tests { use super::*; use crate::{ - form::{answer::models::FormAnswerContent, question::models::QuestionId}, + form::{ + answer::models::{AnswerId, FormAnswerContent}, + question::models::QuestionId, + }, repository::form::{ answer_repository::MockAnswerRepository, form_repository::MockFormRepository, question_repository::MockQuestionRepository, @@ -104,9 +107,7 @@ mod tests { let default_answer_title = DefaultAnswerTitle::new(Some( NonEmptyString::try_new(format!( "Answer to ${}, ${}, ${}", - first_question_id.to_string(), - second_question_id.to_string(), - third_question_id.to_string() + first_question_id, second_question_id, third_question_id )) .unwrap(), )); diff --git a/server/domain/src/repository/form/answer_repository.rs b/server/domain/src/repository/form/answer_repository.rs index 430bd8fb..211063e1 100644 --- a/server/domain/src/repository/form/answer_repository.rs +++ b/server/domain/src/repository/form/answer_repository.rs @@ -2,11 +2,13 @@ use async_trait::async_trait; use errors::Error; use mockall::automock; -use crate::form::{ - answer::models::{AnswerEntry, AnswerId, FormAnswerContent}, - models::FormId, +use crate::{ + form::{ + answer::models::{AnswerEntry, AnswerId, FormAnswerContent}, + models::FormId, + }, + types::verified::Verified, }; -use crate::types::verified::Verified; #[automock] #[async_trait] diff --git a/server/domain/src/types/verified.rs b/server/domain/src/types/verified.rs index 4e68dafe..bfeec330 100644 --- a/server/domain/src/types/verified.rs +++ b/server/domain/src/types/verified.rs @@ -20,7 +20,7 @@ impl Verified { pub trait Verifier { async fn verify(self) -> Result, Error>; - fn new(inner: T) -> Verified { + fn new_verified(inner: T) -> Verified { Verified { inner } } } diff --git a/server/infra/resource/src/repository/form_repository_impls/answer_repository_impl.rs b/server/infra/resource/src/repository/form_repository_impls/answer_repository_impl.rs index b7db73fb..77f65664 100644 --- a/server/infra/resource/src/repository/form_repository_impls/answer_repository_impl.rs +++ b/server/infra/resource/src/repository/form_repository_impls/answer_repository_impl.rs @@ -1,19 +1,20 @@ -use crate::{ - database::components::{DatabaseComponents, FormAnswerDatabase}, - repository::Repository, -}; use async_trait::async_trait; -use domain::types::verified::Verified; use domain::{ form::{ answer::models::{AnswerEntry, AnswerId, FormAnswerContent}, models::FormId, }, repository::form::answer_repository::AnswerRepository, + types::verified::Verified, }; use errors::Error; use futures::{stream, StreamExt}; +use crate::{ + database::components::{DatabaseComponents, FormAnswerDatabase}, + repository::Repository, +}; + #[async_trait] impl AnswerRepository for Repository { #[tracing::instrument(skip(self))] @@ -37,7 +38,7 @@ impl AnswerRepository for Repository AnswerRepository for Repository Result, Error> { stream::iter(self.client.form_answer().get_all_answers().await?) - .then(|posted_answers_dto| async { Ok(posted_answers_dto.try_into()?) }) + .then(|posted_answers_dto| async { posted_answers_dto.try_into() }) .collect::>>() .await .into_iter() diff --git a/server/presentation/src/handlers/form/answer_handler.rs b/server/presentation/src/handlers/form/answer_handler.rs index 457ed61b..bc63903a 100644 --- a/server/presentation/src/handlers/form/answer_handler.rs +++ b/server/presentation/src/handlers/form/answer_handler.rs @@ -57,7 +57,7 @@ pub async fn get_answer_handler( State(repository): State, Path(_answer_id): Path, ) -> impl IntoResponse { - let form_answer_use_case = AnswerUseCase { + let _form_answer_use_case = AnswerUseCase { answer_repository: repository.form_answer_repository(), form_repository: repository.form_repository(), comment_repository: repository.form_comment_repository(), @@ -111,7 +111,7 @@ pub async fn get_answer_by_form_id_handler( State(repository): State, Path(_form_id): Path, ) -> impl IntoResponse { - let form_answer_use_case = AnswerUseCase { + let _form_answer_use_case = AnswerUseCase { answer_repository: repository.form_answer_repository(), form_repository: repository.form_repository(), comment_repository: repository.form_comment_repository(), diff --git a/server/usecase/src/forms/answer.rs b/server/usecase/src/forms/answer.rs index db51a509..9573dde6 100644 --- a/server/usecase/src/forms/answer.rs +++ b/server/usecase/src/forms/answer.rs @@ -1,10 +1,9 @@ -use crate::dto::AnswerDto; -use domain::form::answer::models::AnswerEntry; -use domain::form::answer::service::PostAnswerEntriesVerifier; -use domain::types::verified::Verifier; use domain::{ form::{ - answer::models::{AnswerId, FormAnswerContent}, + answer::{ + models::{AnswerEntry, AnswerId, FormAnswerContent}, + service::PostAnswerEntriesVerifier, + }, models::FormId, service::DefaultAnswerTitleDomainService, }, @@ -13,11 +12,14 @@ use domain::{ comment_repository::CommentRepository, form_repository::FormRepository, question_repository::QuestionRepository, }, + types::verified::Verifier, user::models::User, }; use errors::{usecase::UseCaseError::AnswerNotFound, Error}; use futures::{stream, try_join, StreamExt}; +use crate::dto::AnswerDto; + pub struct AnswerUseCase< 'a, AnswerRepo: AnswerRepository,