Skip to content

Commit

Permalink
Merge pull request #289 from GiganticMinecraft/refactorBuildModel
Browse files Browse the repository at this point in the history
refactor: real_answersの構築でinto_iter()を使う
  • Loading branch information
rito528 authored Sep 16, 2023
2 parents a5ac8f5 + ce00947 commit 314908d
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions server/infra/resource/src/database/form.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use async_trait::async_trait;
use chrono::Utc;
use domain::form::models::{
DefaultAnswerTitle, FormDescription, FormId, FormQuestionUpdateSchema, FormTitle,
Answer, DefaultAnswerTitle, FormDescription, FormId, FormQuestionUpdateSchema, FormTitle,
FormUpdateTargets, OffsetAndLimit, PostedAnswers,
};
use entities::{
Expand Down Expand Up @@ -418,13 +418,19 @@ impl FormDatabase for ConnectionPool {

let real_answer_models = answer
.answers
.iter()
.map(|answer| real_answers::ActiveModel {
id: Default::default(),
answer_id: Set(id),
question_id: Set(answer.question_id.to_owned()),
answer: Set(answer.answer.to_owned()),
})
.into_iter()
.map(
|Answer {
question_id,
answer,
..
}| real_answers::ActiveModel {
id: Default::default(),
answer_id: Set(id),
question_id: Set(question_id.into()),
answer: Set(answer),
},
)
.collect_vec();

RealAnswers::insert_many(real_answer_models)
Expand All @@ -448,7 +454,7 @@ impl FormDatabase for ConnectionPool {
.await?
.into_iter()
.map(
|entities::real_answers::Model {
|real_answers::Model {
question_id,
answer,
..
Expand Down

0 comments on commit 314908d

Please sign in to comment.