use actix_web::{get, web::Data, HttpRequest, HttpResponse}; use askama::Template; use super::tcx::TemplateCtx; use crate::{ ctx::Ctx, db::models::{Board, LocalStats, NewsPost}, error::NekrochanError, filters, web::template_response, }; #[derive(Template)] #[template(path = "index.html")] struct IndexTemplate { tcx: TemplateCtx, news: Option, boards: Vec, stats: LocalStats, } #[get("/")] pub async fn index(ctx: Data, req: HttpRequest) -> Result { let tcx = TemplateCtx::new(&ctx, &req).await?; if tcx.boards.is_empty() { return Err(NekrochanError::HomePageError); } let news = NewsPost::read_latest(&ctx).await?; let boards = Board::read_all(&ctx).await?; let stats = LocalStats::read(&ctx).await?; let template = IndexTemplate { tcx, boards, stats, news, }; template_response(&template) }