fix get single question
This commit is contained in:
parent
094496961a
commit
a5b576838c
@ -30,7 +30,7 @@ pub async fn read_question(
|
||||
None => QuestionDTO::new(question, vec![]).into_response(),
|
||||
}
|
||||
}
|
||||
None => (StatusCode::NOT_EXTENDED).into_response(),
|
||||
None => (StatusCode::NOT_FOUND).into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,8 +210,6 @@ impl Store {
|
||||
propert_id: u8,
|
||||
property_type: &str,
|
||||
) -> Option<Vec<Tag>> {
|
||||
println!("Property type {}", property_type);
|
||||
println!("Property id {} ", propert_id);
|
||||
let query = format!("SELECT * FROM tags WHERE {} = ($2);", property_type).to_string(); //looks risky, but user does not get to control property type
|
||||
let result = sqlx::query(&query)
|
||||
.bind(property_type.to_string())
|
||||
@ -220,7 +218,6 @@ impl Store {
|
||||
.await;
|
||||
match result {
|
||||
Ok(pg_rows) => {
|
||||
println!("num tag rows {}", pg_rows.len());
|
||||
let tags: Vec<Tag> = pg_rows
|
||||
.iter()
|
||||
.map(|pg_row| Tag::new(Store::id_to_u8(pg_row, "id"), pg_row.get("label")))
|
||||
@ -311,8 +308,8 @@ impl Store {
|
||||
|
||||
// Fetch one question, but do not worry about joining the tags
|
||||
pub async fn fetch_one_question_by_id(&self, id: u8) -> Option<Question> {
|
||||
let row_result = sqlx::query("SELECT * FROM questions WHERE id = $1")
|
||||
.bind(id.to_string())
|
||||
let row_result = sqlx::query("SELECT id,title,content FROM questions WHERE id = $1")
|
||||
.bind(i32::from(id))
|
||||
.fetch_one(&self.connection)
|
||||
.await;
|
||||
match row_result {
|
||||
@ -321,7 +318,10 @@ impl Store {
|
||||
pg_row.get("title"),
|
||||
pg_row.get("content"),
|
||||
)),
|
||||
_ => None,
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user