add: questions timelines

This commit is contained in:
trisua 2025-04-13 12:15:14 -04:00
parent 5d53ceb09c
commit 063e33899e
22 changed files with 407 additions and 90 deletions

View file

@ -158,6 +158,113 @@ pub async fn all_request(
Html(data.1.render("timelines/all.html", &context).unwrap())
}
/// `/questions`
pub async fn index_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_questions_from_user_communities(user.id, 12, req.page)
.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/home_questions.html", &context)
.unwrap(),
)
}
/// `/following/questions`
pub async fn following_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 Err(Html(
render_error(Error::NotAllowed, &jar, &data, &None).await,
));
}
};
let list = match data
.0
.get_questions_from_user_following(user.id, 12, req.page)
.await
{
Ok(l) => match data.0.fill_questions(l).await {
Ok(l) => l,
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
},
Err(e) => return Err(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);
Ok(Html(
data.1
.render("timelines/following_questions.html", &context)
.unwrap(),
))
}
/// `/all/questions`
pub async fn all_questions_request(
jar: CookieJar,
Extension(data): Extension<State>,
Query(req): Query<PaginatedQuery>,
) -> impl IntoResponse {
let data = data.read().await;
let user = get_user_from_token!(jar, data.0);
let list = match data.0.get_latest_global_questions(12, req.page).await {
Ok(l) => match data.0.fill_questions(l).await {
Ok(l) => l,
Err(e) => return Html(render_error(e, &jar, &data, &user).await),
},
Err(e) => return Html(render_error(e, &jar, &data, &user).await),
};
let lang = get_lang!(jar, data.0);
let mut context = initial_context(&data.0.0, lang, &user).await;
context.insert("list", &list);
context.insert("page", &req.page);
Html(
data.1
.render("timelines/all_questions.html", &context)
.unwrap(),
)
}
/// `/notifs`
pub async fn notifications_request(
jar: CookieJar,

View file

@ -16,11 +16,19 @@ use crate::{assets::initial_context, get_lang};
pub fn routes() -> Router {
Router::new()
// misc
// timelines
.route("/", get(misc::index_request))
.route("/popular", get(misc::popular_request))
.route("/following", get(misc::following_request))
.route("/all", get(misc::all_request))
// question timelines
.route("/questions", get(misc::index_questions_request))
.route(
"/following/questions",
get(misc::following_questions_request),
)
.route("/all/questions", get(misc::all_questions_request))
// misc
.route("/notifs", get(misc::notifications_request))
.route("/requests", get(misc::requests_request))
.route("/doc/{*file_name}", get(misc::markdown_document_request))