use std::sync::Arc; use calibre_db::data::pagination::SortOrder; use poem::{ error::InternalServerError, handler, web::{Data, Html, Path}, }; use tera::Context; use crate::{ app_state::AppState, data::book::Book, handlers::error::SqliteError, templates::TEMPLATES, }; #[handler] pub async fn handler( id: Path, state: Data<&Arc>, ) -> Result, poem::Error> { let author = state.calibre.scalar_author(*id).map_err(SqliteError)?; let books = state .calibre .author_books(*id, u32::MAX.into(), None, SortOrder::ASC) .map_err(SqliteError)?; let books = books .iter() .filter_map(|x| Book::full_book(x, &state)) .collect::>(); let mut context = Context::new(); context.insert("title", &author.name); context.insert("nav", "authors"); context.insert("books", &books); TEMPLATES .render("book_list", &context) .map_err(InternalServerError) .map(Html) }