From 06efb2cf444d0cfef2bb08007e370dd102a902f8 Mon Sep 17 00:00:00 2001 From: Kavika Date: Tue, 5 Nov 2024 11:17:23 +1100 Subject: [PATCH] fix enum errors --- backend/server/src/models/answer.rs | 4 ++-- backend/server/src/models/question.rs | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/backend/server/src/models/answer.rs b/backend/server/src/models/answer.rs index a2d56a9b..e4fb1d9a 100644 --- a/backend/server/src/models/answer.rs +++ b/backend/server/src/models/answer.rs @@ -55,10 +55,10 @@ impl AnswerData { pub async fn insert_into_db(self, answer_id: i64, pool: &Pool) -> Result<()> { match self { - Self::ShortAnswer => { + Self::ShortAnswer(text) => { let result = sqlx::query!( "INSERT INTO short_answer_answers (text, answer_id) VALUES ($1, $2)", - self.text, + text, answer_id ) .execute(pool) diff --git a/backend/server/src/models/question.rs b/backend/server/src/models/question.rs index db6fca5e..1c6771f3 100644 --- a/backend/server/src/models/question.rs +++ b/backend/server/src/models/question.rs @@ -94,11 +94,9 @@ impl QuestionData { let mut query_builder = QueryBuilder::new("INSERT INTO multi_option_question_options (id, text, question_id, rank)"); - let mut rank = 1; - query_builder.push_values(self.options, |mut b, option| { + query_builder.push_values(data.options, |mut b, option| { let id = snowflake_generator.real_time_generate(); - b.push_bind(id).push_bind(option).push_bind(question_id).push_bind(rank); - rank += 1; + b.push_bind(id).push_bind(option.text).push_bind(question_id).push_bind(option.rank); }); let query = query_builder.build();