use std::sync::Arc; use calibre_db::{calibre::Calibre, data::pagination::SortOrder}; use poem::{ handler, web::{Data, Html, Path}, }; use crate::{app_state::AppState, handlers::paginated}; #[handler] pub async fn handler_init(state: Data<&Arc>) -> Result, poem::Error> { authors(&state.calibre, None, &SortOrder::ASC) } #[handler] pub async fn handler( Path((cursor, sort_order)): Path<(String, SortOrder)>, state: Data<&Arc>, ) -> Result, poem::Error> { authors(&state.calibre, Some(&cursor), &sort_order) } fn authors( calibre: &Calibre, cursor: Option<&str>, sort_order: &SortOrder, ) -> Result, poem::Error> { paginated::render( "authors", || calibre.authors(25, cursor, sort_order), |author| author.sort.clone(), |cursor| calibre.has_previous_authors(cursor), |cursor| calibre.has_more_authors(cursor), ) }