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 (
|
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
|
||||||
);
|
);
|
||||||
|
@ -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 {
|
||||||
|
Reference in New Issue
Block a user