fix answers api
This commit is contained in:
parent
6d5333b047
commit
a60b11925c
@ -24,5 +24,6 @@ CREATE TABLE IF NOT EXISTS question_tag (
|
||||
CREATE TABLE IF NOT EXISTS answers (
|
||||
id SERIAL PRIMARY KEY,
|
||||
question_id INT REFERENCES questions(id),
|
||||
FOREIGN KEY (question_id) REFERENCES questions(id),
|
||||
content TEXT NOT NULL
|
||||
);
|
||||
|
@ -394,12 +394,12 @@ impl Store {
|
||||
|
||||
// Add an answer entity
|
||||
pub async fn add_answer(&mut self, new_answer: NewAnswer) -> Result<Answer, String> {
|
||||
let result =
|
||||
sqlx::query("INSERT INTO answers VALUES ($1,$2) RETURNING id, content, question_id")
|
||||
.bind(new_answer.content)
|
||||
.bind(new_answer.question_id.to_string())
|
||||
.fetch_one(&self.connection)
|
||||
.await;
|
||||
let query = "INSERT INTO answers (content, question_id) VALUES ($1,$2) RETURNING id, content, question_id";
|
||||
let result = sqlx::query(query)
|
||||
.bind(new_answer.content)
|
||||
.bind(i32::from(new_answer.question_id))
|
||||
.fetch_one(&self.connection)
|
||||
.await;
|
||||
match result {
|
||||
Ok(pg_row) => Ok(Answer::new(
|
||||
Store::id_to_u8(&pg_row, "id"),
|
||||
|
Reference in New Issue
Block a user