//! Handle requests for a single series. use std::sync::Arc; use poem::{ handler, web::{Data, Path}, Response, }; use crate::{app_state::AppState, data::book::Book, handlers::error::HandlerError, Accept}; /// Handle a request for a series with `id` and decide whether to render to html or OPDS. #[handler] pub async fn handler( id: Path, accept: Data<&Accept>, state: Data<&Arc>, ) -> Result { let series = state .calibre .scalar_series(*id) .map_err(HandlerError::DataError)?; let books = state .calibre .series_books(*id) .map_err(HandlerError::DataError)?; let books = books .iter() .filter_map(|x| Book::full_book(x, &state)) .collect::>(); match accept.0 { Accept::Html => crate::handlers::html::series_single::handler(series, books).await, Accept::Opds => crate::handlers::opds::series_single::handler(series, books).await, } }