nekrochan/src/web/staff/banners.rs

31 řádky
787 B
Rust
Spustitelný soubor

use actix_web::{get, web::Data, HttpRequest, HttpResponse};
use askama::Template;
use crate::{
ctx::Ctx,
db::models::Banner,
error::NekrochanError,
web::{tcx::TemplateCtx, template_response},
};
#[derive(Template)]
#[template(path = "staff/banners.html")]
struct BannersTemplate {
tcx: TemplateCtx,
banners: Vec<Banner>,
}
#[get("/staff/banners")]
pub async fn banners(ctx: Data<Ctx>, req: HttpRequest) -> Result<HttpResponse, NekrochanError> {
let tcx = TemplateCtx::new(&ctx, &req).await?;
if !(tcx.perms.owner() || tcx.perms.banners()) {
return Err(NekrochanError::InsufficientPermissionError);
}
let banners = Banner::read_all(&ctx).await?;
let template = BannersTemplate { tcx, banners };
template_response(&template)
}