little-hesinde/rusty-library/src/handlers/authors.rs
2024-05-06 14:17:25 +02:00

37 lines
960 B
Rust

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<AppState>>) -> Result<Html<String>, poem::Error> {
authors(&state.calibre, None, &SortOrder::ASC)
}
#[handler]
pub async fn handler(
Path((cursor, sort_order)): Path<(String, SortOrder)>,
state: Data<&Arc<AppState>>,
) -> Result<Html<String>, poem::Error> {
authors(&state.calibre, Some(&cursor), &sort_order)
}
fn authors(
calibre: &Calibre,
cursor: Option<&str>,
sort_order: &SortOrder,
) -> Result<Html<String>, 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),
)
}