feat: add response to output
This commit is contained in:
parent
af3148df06
commit
24dfc9ded5
|
@ -137,7 +137,7 @@ async fn get_data(
|
|||
select
|
||||
q.*,
|
||||
current_timestamp <= q.publish_date + interval '1 day' and current_timestamp > q.publish_date as "active!",
|
||||
exists(select 1 from responses r where r.question_id = q.id and r.user_id = $1) as "voted!"
|
||||
(select answer from responses r where r.question_id = q.id and r.user_id = $1) as response
|
||||
from questions q
|
||||
where q.publish_date <= current_timestamp
|
||||
order by q.publish_date desc
|
||||
|
@ -170,10 +170,11 @@ async fn get_data(
|
|||
answers: question.answers,
|
||||
};
|
||||
|
||||
if question.voted || !question.active {
|
||||
if question.response.is_some() || !question.active {
|
||||
parsed.push(FullQuestion {
|
||||
basic,
|
||||
responses,
|
||||
response: question.response.map(|r| r as u16),
|
||||
}.into());
|
||||
} else {
|
||||
parsed.push(basic.into());
|
||||
|
|
|
@ -16,6 +16,7 @@ pub struct FullQuestion {
|
|||
#[serde(flatten)]
|
||||
pub basic: BasicQuestion,
|
||||
pub responses: Vec<u64>,
|
||||
pub response: Option<u16>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
|
Loading…
Reference in New Issue