fix answers api

This commit is contained in:
David Westgate 2024-06-02 19:01:54 -07:00
parent 6d5333b047
commit a60b11925c
2 changed files with 7 additions and 6 deletions

View File

@ -24,5 +24,6 @@ CREATE TABLE IF NOT EXISTS question_tag (
CREATE TABLE IF NOT EXISTS answers ( CREATE TABLE IF NOT EXISTS answers (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
question_id INT REFERENCES questions(id), question_id INT REFERENCES questions(id),
FOREIGN KEY (question_id) REFERENCES questions(id),
content TEXT NOT NULL content TEXT NOT NULL
); );

View File

@ -394,10 +394,10 @@ impl Store {
// Add an answer entity // Add an answer entity
pub async fn add_answer(&mut self, new_answer: NewAnswer) -> Result<Answer, String> { pub async fn add_answer(&mut self, new_answer: NewAnswer) -> Result<Answer, String> {
let result = let query = "INSERT INTO answers (content, question_id) VALUES ($1,$2) RETURNING id, content, question_id";
sqlx::query("INSERT INTO answers VALUES ($1,$2) RETURNING id, content, question_id") let result = sqlx::query(query)
.bind(new_answer.content) .bind(new_answer.content)
.bind(new_answer.question_id.to_string()) .bind(i32::from(new_answer.question_id))
.fetch_one(&self.connection) .fetch_one(&self.connection)
.await; .await;
match result { match result {