little-hesinde/rusty-library/src/handlers/authors.rs

37 lines
960 B
Rust
Raw Normal View History

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