feat: add response to output

This commit is contained in:
Anna 2023-11-17 13:30:56 -05:00
parent af3148df06
commit 24dfc9ded5
Signed by: anna
GPG Key ID: D0943384CD9F87D1
2 changed files with 4 additions and 2 deletions

View File

@ -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());

View File

@ -16,6 +16,7 @@ pub struct FullQuestion {
#[serde(flatten)]
pub basic: BasicQuestion,
pub responses: Vec<u64>,
pub response: Option<u16>,
}
#[derive(Serialize)]