add: popular questions timeline
This commit is contained in:
parent
424c823926
commit
d6c7372610
6 changed files with 100 additions and 1 deletions
|
@ -196,6 +196,44 @@ pub async fn index_questions_request(
|
|||
)
|
||||
}
|
||||
|
||||
/// `/popular/questions`
|
||||
pub async fn popular_questions_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Query(req): Query<PaginatedQuery>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => {
|
||||
return Html(render_error(Error::NotAllowed, &jar, &data, &None).await);
|
||||
}
|
||||
};
|
||||
|
||||
let list = match data
|
||||
.0
|
||||
.get_popular_global_questions(12, req.page, 604_800_000)
|
||||
.await
|
||||
{
|
||||
Ok(l) => match data.0.fill_questions(l).await {
|
||||
Ok(l) => l,
|
||||
Err(e) => return Html(render_error(e, &jar, &data, &Some(user)).await),
|
||||
},
|
||||
Err(e) => return Html(render_error(e, &jar, &data, &Some(user)).await),
|
||||
};
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
|
||||
|
||||
context.insert("list", &list);
|
||||
context.insert("page", &req.page);
|
||||
Html(
|
||||
data.1
|
||||
.render("timelines/popular_questions.html", &context)
|
||||
.unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
/// `/following/questions`
|
||||
pub async fn following_questions_request(
|
||||
jar: CookieJar,
|
||||
|
|
|
@ -23,6 +23,7 @@ pub fn routes() -> Router {
|
|||
.route("/all", get(misc::all_request))
|
||||
// question timelines
|
||||
.route("/questions", get(misc::index_questions_request))
|
||||
.route("/popular/questions", get(misc::popular_questions_request))
|
||||
.route(
|
||||
"/following/questions",
|
||||
get(misc::following_questions_request),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue