little-hesinde/rusty-library/src/handlers/html/author.rs

22 lines
650 B
Rust

//! Handle a single author for html.
use calibre_db::data::author::Author;
use poem::{error::InternalServerError, web::Html, IntoResponse, Response};
use tera::Context;
use crate::{data::book::Book, templates::TEMPLATES};
/// Render a single author in html.
pub async fn handler(author: Author, books: Vec<Book>) -> Result<Response, poem::Error> {
let mut context = Context::new();
context.insert("title", &author.name);
context.insert("nav", "authors");
context.insert("books", &books);
Ok(TEMPLATES
.render("book_list", &context)
.map_err(InternalServerError)
.map(Html)?
.into_response())
}