Skip to content

Commit

Permalink
chore: apply clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed Jan 19, 2025
1 parent 998c919 commit fb0588c
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 31 deletions.
1 change: 0 additions & 1 deletion server/domain/src/form/answer/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
9 changes: 3 additions & 6 deletions server/domain/src/form/answer/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -39,7 +36,7 @@ impl<FormRepo: FormRepository> Verifier<AnswerEntry> 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))
}
Expand Down
2 changes: 1 addition & 1 deletion server/domain/src/form/models.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
9 changes: 5 additions & 4 deletions server/domain/src/form/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
));
Expand Down
10 changes: 6 additions & 4 deletions server/domain/src/repository/form/answer_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion server/domain/src/types/verified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<T> Verified<T> {
pub trait Verifier<T> {
async fn verify(self) -> Result<Verified<T>, Error>;

fn new(inner: T) -> Verified<T> {
fn new_verified(inner: T) -> Verified<T> {
Verified { inner }
}
}
Original file line number Diff line number Diff line change
@@ -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<Client: DatabaseComponents + 'static> AnswerRepository for Repository<Client> {
#[tracing::instrument(skip(self))]
Expand All @@ -37,7 +38,7 @@ impl<Client: DatabaseComponents + 'static> AnswerRepository for Repository<Clien
.form_answer()
.get_answers(answer_id)
.await?
.map(|posted_answers_dto| Ok(posted_answers_dto.try_into()?))
.map(|posted_answers_dto| posted_answers_dto.try_into())
.transpose()
}

Expand Down Expand Up @@ -77,7 +78,7 @@ impl<Client: DatabaseComponents + 'static> AnswerRepository for Repository<Clien
#[tracing::instrument(skip(self))]
async fn get_all_answers(&self) -> Result<Vec<AnswerEntry>, 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::<Vec<Result<AnswerEntry, _>>>()
.await
.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions server/presentation/src/handlers/form/answer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub async fn get_answer_handler(
State(repository): State<RealInfrastructureRepository>,
Path(_answer_id): Path<AnswerId>,
) -> 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(),
Expand Down Expand Up @@ -111,7 +111,7 @@ pub async fn get_answer_by_form_id_handler(
State(repository): State<RealInfrastructureRepository>,
Path(_form_id): Path<FormId>,
) -> 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(),
Expand Down
12 changes: 7 additions & 5 deletions server/usecase/src/forms/answer.rs
Original file line number Diff line number Diff line change
@@ -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,
},
Expand All @@ -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,
Expand Down

0 comments on commit fb0588c

Please sign in to comment.