feat: add has_next to response
This commit is contained in:
parent
4e29c174fe
commit
94ae2f65c6
|
@ -180,6 +180,7 @@ enum GetDataResult {
|
|||
V2 {
|
||||
current: Option<Question>,
|
||||
page: Vec<Question>,
|
||||
has_next: bool,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -235,7 +236,7 @@ async fn get_data_v2(
|
|||
from questions q
|
||||
where q.publish_date <= current_timestamp
|
||||
order by q.publish_date desc
|
||||
limit $2::bigint + 1 offset $3::bigint * $2::bigint
|
||||
limit $2::bigint + 2 offset $3::bigint * $2::bigint
|
||||
"#,
|
||||
user.id,
|
||||
PER_PAGE as i64,
|
||||
|
@ -258,7 +259,7 @@ async fn get_data_v2(
|
|||
.try_collect::<Vec<_>>()
|
||||
.await?;
|
||||
|
||||
let questions = questions.into_iter()
|
||||
let mut questions: Vec<Question> = questions.into_iter()
|
||||
.flat_map(|question| {
|
||||
if question.active {
|
||||
if include_current {
|
||||
|
@ -296,8 +297,12 @@ async fn get_data_v2(
|
|||
}
|
||||
}
|
||||
|
||||
let has_next = questions.len() > PER_PAGE;
|
||||
questions.truncate(PER_PAGE);
|
||||
|
||||
Ok(GetDataResult::V2 {
|
||||
current,
|
||||
has_next,
|
||||
page: questions,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue