Skip to content

Commit

Permalink
add option to get next and previous books
Browse files Browse the repository at this point in the history
  • Loading branch information
berinaniesh committed Nov 3, 2023
1 parent a1a9598 commit 5cafd6d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,30 @@ pub async fn get_next_page(current_page: web::Json<PageIn>, app_data: web::Data<
abbreviation).fetch_one(&app_data.pool).await?.id;
}

if current_page.chapter == 0 {
if book_id == 1 {
previous = None
} else {
let p = sqlx::query!(
r#"
SELECT name, abbreviation FROM "Book" where id=$1
"#,
book_id-1).fetch_one(&app_data.pool).await?;
previous = Some(PageOut {book: p.name, abbreviation: p.abbreviation, chapter: 0});
}
if book_id == 66 {
next = None
} else {
let n = sqlx::query!(
r#"
SELECT name, abbreviation FROM "Book" WHERE id=$1
"#,
book_id+1).fetch_one(&app_data.pool).await?;
next = Some(PageOut{book: n.name, abbreviation: n.abbreviation, chapter: 0});
}
return Ok(HttpResponse::Ok().json(json!({"previous": previous, "next": next})))
}

if book_id == 1 && current_page.chapter == 1 {
previous = None;
} else {
Expand Down

0 comments on commit 5cafd6d

Please sign in to comment.