use std::sync::Arc; use poem::{ error::InternalServerError, handler, web::{Data, Html}, }; use tera::Context; use crate::{ app_state::AppState, data::book::Book, handlers::error::HandlerError, templates::TEMPLATES, }; #[handler] pub async fn handler(state: Data<&Arc>) -> Result, poem::Error> { let recent_books = state .calibre .recent_books(25) .map_err(HandlerError::DataError)?; let recent_books = recent_books .iter() .filter_map(|x| Book::full_book(x, &state)) .collect::>(); let mut context = Context::new(); context.insert("title", "Recent Books"); context.insert("nav", "recent"); context.insert("books", &recent_books); TEMPLATES .render("book_list", &context) .map_err(InternalServerError) .map(Html) }