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, } #[get("/boards/{board}/catalog")] pub async fn board_catalog( ctx: Data, req: HttpRequest, path: Path, ) -> Result { 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) }