47 řádky
999 B
Rust
47 řádky
999 B
Rust
|
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,
|
||
|
};
|
||
|
|
||
|
template_response(template)
|
||
|
}
|