add series support
This commit is contained in:
parent
6a79f0c1ed
commit
a91fe9a0bb
11 changed files with 183 additions and 43 deletions
|
@ -31,11 +31,10 @@ fn books(
|
|||
paginated::render(
|
||||
"books",
|
||||
|| {
|
||||
state.calibre.books(25, cursor, sort_order).map(|x| {
|
||||
x.iter()
|
||||
.filter_map(|y| Book::full_book(y, &state))
|
||||
.collect()
|
||||
})
|
||||
state
|
||||
.calibre
|
||||
.books(25, cursor, sort_order)
|
||||
.map(|x| x.iter().filter_map(|y| Book::full_book(y, state)).collect())
|
||||
},
|
||||
|book| book.sort.clone(),
|
||||
|cursor| state.calibre.has_previous_books(cursor),
|
||||
|
|
|
@ -1,10 +1,38 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use poem::{handler, web::Data};
|
||||
use calibre_db::data::pagination::SortOrder;
|
||||
use poem::{
|
||||
handler,
|
||||
web::{Data, Html, Path},
|
||||
};
|
||||
|
||||
use crate::app_state::AppState;
|
||||
|
||||
use super::paginated;
|
||||
|
||||
#[handler]
|
||||
pub async fn handler(state: Data<&Arc<AppState>>) -> Result<String, poem::Error> {
|
||||
Ok("series".to_string())
|
||||
pub async fn handler_init(state: Data<&Arc<AppState>>) -> Result<Html<String>, poem::Error> {
|
||||
series(&state, None, &SortOrder::ASC)
|
||||
}
|
||||
|
||||
#[handler]
|
||||
pub async fn handler(
|
||||
Path((cursor, sort_order)): Path<(String, SortOrder)>,
|
||||
state: Data<&Arc<AppState>>,
|
||||
) -> Result<Html<String>, poem::Error> {
|
||||
series(&state, Some(&cursor), &sort_order)
|
||||
}
|
||||
|
||||
fn series(
|
||||
state: &Arc<AppState>,
|
||||
cursor: Option<&str>,
|
||||
sort_order: &SortOrder,
|
||||
) -> Result<Html<String>, poem::Error> {
|
||||
paginated::render(
|
||||
"series",
|
||||
|| state.calibre.series(25, cursor, sort_order),
|
||||
|series| series.sort.clone(),
|
||||
|cursor| state.calibre.has_previous_series(cursor),
|
||||
|cursor| state.calibre.has_more_series(cursor),
|
||||
)
|
||||
}
|
||||
|
|
35
rusty-library/src/handlers/series_single.rs
Normal file
35
rusty-library/src/handlers/series_single.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use poem::{
|
||||
error::InternalServerError,
|
||||
handler,
|
||||
web::{Data, Html, Path},
|
||||
};
|
||||
use tera::Context;
|
||||
|
||||
use crate::{
|
||||
app_state::AppState, data::book::Book, handlers::error::SqliteError, templates::TEMPLATES,
|
||||
};
|
||||
|
||||
#[handler]
|
||||
pub async fn handler(
|
||||
id: Path<u64>,
|
||||
state: Data<&Arc<AppState>>,
|
||||
) -> Result<Html<String>, poem::Error> {
|
||||
let series = state.calibre.scalar_series(*id).map_err(SqliteError)?;
|
||||
let books = state.calibre.series_books(*id).map_err(SqliteError)?;
|
||||
let books = books
|
||||
.iter()
|
||||
.filter_map(|x| Book::full_book(x, &state))
|
||||
.collect::<Vec<Book>>();
|
||||
|
||||
let mut context = Context::new();
|
||||
context.insert("title", &series.name);
|
||||
context.insert("nav", &series.name);
|
||||
context.insert("books", &books);
|
||||
|
||||
TEMPLATES
|
||||
.render("book_list", &context)
|
||||
.map_err(InternalServerError)
|
||||
.map(Html)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue