Skip to content

Commit

Permalink
refactor: Verifier trait の verify 関数として T 型の引数を受け取るように
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed Jan 19, 2025
1 parent 7e7ddef commit 6066904
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
5 changes: 1 addition & 4 deletions server/domain/src/form/answer/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ use crate::{
pub struct PostAnswerEntriesVerifier<'a, FormRepo: FormRepository> {
pub form_repo: &'a FormRepo,
pub actor: &'a User,
pub answer_entry: AnswerEntry,
}

#[async_trait]
impl<FormRepo: FormRepository> Verifier<AnswerEntry> for PostAnswerEntriesVerifier<'_, FormRepo> {
async fn verify(self) -> Result<Verified<AnswerEntry>, Error> {
let target = self.answer_entry;

async fn verify(self, target: AnswerEntry) -> Result<Verified<AnswerEntry>, Error> {
let form = self
.form_repo
.get(*target.form_id())
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 @@ -18,7 +18,7 @@ impl<T> Verified<T> {

#[async_trait]
pub trait Verifier<T> {
async fn verify(self) -> Result<Verified<T>, Error>;
async fn verify(self, target: T) -> Result<Verified<T>, Error>;

fn new_verified(inner: T) -> Verified<T> {
Verified { inner }
Expand Down
7 changes: 3 additions & 4 deletions server/usecase/src/forms/answer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ impl<
.to_answer_title(&user, form_id, answers.as_slice())
.await?;

let answer_entry = AnswerEntry::new(user.to_owned(), form_id, title);

let verifier = PostAnswerEntriesVerifier {
form_repo: self.form_repository,
actor: &user,
answer_entry,
};

let answer_entry = verifier.verify().await?;
let answer_entry = verifier
.verify(AnswerEntry::new(user.to_owned(), form_id, title))
.await?;

self.answer_repository
.post_answer(answer_entry, answers)
Expand Down

0 comments on commit 6066904

Please sign in to comment.