2025-03-26 21:46:21 -04:00
|
|
|
use super::{PaginatedQuery, render_error};
|
2025-03-25 23:58:27 -04:00
|
|
|
use crate::{State, assets::initial_context, get_lang, get_user_from_token};
|
|
|
|
use axum::{
|
|
|
|
Extension,
|
2025-03-26 21:46:21 -04:00
|
|
|
extract::{Path, Query},
|
2025-03-25 23:58:27 -04:00
|
|
|
response::{Html, IntoResponse},
|
|
|
|
};
|
|
|
|
use axum_extra::extract::CookieJar;
|
|
|
|
|
|
|
|
/// `/user/{username}`
|
|
|
|
pub async fn posts_request(
|
|
|
|
jar: CookieJar,
|
|
|
|
Path(username): Path<String>,
|
2025-03-26 21:46:21 -04:00
|
|
|
Query(props): Query<PaginatedQuery>,
|
2025-03-25 23:58:27 -04:00
|
|
|
Extension(data): Extension<State>,
|
|
|
|
) -> impl IntoResponse {
|
|
|
|
let data = data.read().await;
|
|
|
|
let user = get_user_from_token!(jar, data.0);
|
|
|
|
|
|
|
|
let other_user = match data.0.get_user_by_username(&username).await {
|
|
|
|
Ok(ua) => ua,
|
2025-03-26 21:46:21 -04:00
|
|
|
Err(e) => return Err(Html(render_error(e, &jar, &data, &user))),
|
|
|
|
};
|
|
|
|
|
|
|
|
let posts = match data
|
|
|
|
.0
|
|
|
|
.get_posts_by_user(other_user.id, 12, props.page)
|
|
|
|
.await
|
|
|
|
{
|
|
|
|
Ok(p) => p,
|
|
|
|
Err(e) => return Err(Html(render_error(e, &jar, &data, &user))),
|
2025-03-25 23:58:27 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
let lang = get_lang!(jar, data.0);
|
|
|
|
let mut context = initial_context(&data.0.0, lang, &user);
|
2025-03-26 21:46:21 -04:00
|
|
|
|
2025-03-25 23:58:27 -04:00
|
|
|
context.insert("profile", &other_user);
|
2025-03-26 21:46:21 -04:00
|
|
|
context.insert("posts", &posts);
|
2025-03-25 23:58:27 -04:00
|
|
|
|
|
|
|
Ok(Html(
|
|
|
|
data.1.render("profile/posts.html", &mut context).unwrap(),
|
|
|
|
))
|
|
|
|
}
|