nekrochan/src/web/board_catalog.rs

47 řádky
1000 B
Rust
Surový Normální zobrazení Historie

2023-12-11 15:18:43 +00:00
use actix_web::{
get,
web::{Data, Path},
HttpRequest, HttpResponse,
};
use askama::Template;
use crate::{
ctx::Ctx,
db::models::{Board, Post},
error::NekrochanError,
filters,
web::{tcx::TemplateCtx, template_response},
};
#[derive(Template)]
#[template(path = "board_catalog.html")]
struct BoardCatalogTemplate {
tcx: TemplateCtx,
board: Board,
threads: Vec<Post>,
}
#[get("/boards/{board}/catalog")]
pub async fn board_catalog(
ctx: Data<Ctx>,
req: HttpRequest,
path: Path<String>,
) -> Result<HttpResponse, NekrochanError> {
let tcx = TemplateCtx::new(&ctx, &req).await?;
let board = path.into_inner();
let board = Board::read(&ctx, board.clone())
.await?
.ok_or(NekrochanError::BoardNotFound(board))?;
let threads = Post::read_board_catalog(&ctx, board.id.clone()).await?;
let template = BoardCatalogTemplate {
tcx,
board,
threads,
};
2023-12-11 15:59:32 +00:00
template_response(&template)
2023-12-11 15:18:43 +00:00
}