merge upstream
All checks were successful
mnemo-build-and-publish / gractwo-mnemo-build (push) Successful in 44s
All checks were successful
mnemo-build-and-publish / gractwo-mnemo-build (push) Successful in 44s
This commit is contained in:
@@ -131,6 +131,18 @@ impl Quote {
|
||||
|
||||
ids.iter().map(|id| Self::get_by_id(conn, *id)).collect()
|
||||
}
|
||||
pub fn get_chronological_offset(
|
||||
conn: &Connection,
|
||||
offset: i64,
|
||||
limit: i64,
|
||||
) -> Result<Vec<Quote>, QuoteError> {
|
||||
let ids = conn
|
||||
.prepare("SELECT id FROM quotes ORDER BY id DESC LIMIT ?1 OFFSET ?2")?
|
||||
.query_map((limit, offset), |r| r.get(0))?
|
||||
.collect::<Result<Vec<Uuid>, _>>()?;
|
||||
|
||||
ids.iter().map(|id| Self::get_by_id(conn, *id)).collect()
|
||||
}
|
||||
pub fn create(
|
||||
conn: &Connection,
|
||||
lines: Vec<(String, Name)>,
|
||||
|
||||
@@ -31,6 +31,7 @@ impl User {
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
todo!("Do the permission checking here once permissions are modeled in the DB")
|
||||
Ok(false)
|
||||
// todo!("Do the permission checking here once permissions are modeled in the DB")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
use axum::{
|
||||
extract::Request,
|
||||
extract::{Query, Request},
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use maud::{PreEscaped, html};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
database,
|
||||
@@ -21,10 +22,25 @@ use crate::{
|
||||
|
||||
pub mod add;
|
||||
|
||||
pub async fn page(req: Request) -> Result<Response, CompositeError> {
|
||||
#[derive(Deserialize)]
|
||||
pub struct PageQuery {
|
||||
page: Option<i64>,
|
||||
}
|
||||
|
||||
pub async fn page(
|
||||
Query(query): Query<PageQuery>,
|
||||
req: Request,
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(req.headers())?.required()?;
|
||||
let conn = database::conn()?;
|
||||
let quotes = Quote::get_chronological_cursorscroll(&conn, None, 20)?;
|
||||
|
||||
let page = query.page.unwrap_or(1).max(1);
|
||||
let per_page = 10;
|
||||
let offset = (page - 1) * per_page;
|
||||
|
||||
let quotes = Quote::get_chronological_offset(&conn, offset, per_page)?;
|
||||
let total_quotes = Quote::total_count(&conn)?;
|
||||
let total_pages = (total_quotes as f64 / per_page as f64).ceil() as i64;
|
||||
|
||||
Ok(base(
|
||||
"Quotes | Mnemosyne",
|
||||
@@ -50,9 +66,31 @@ pub async fn page(req: Request) -> Result<Response, CompositeError> {
|
||||
"Chronological"
|
||||
}
|
||||
}
|
||||
div class="flex flex-col gap-4" {
|
||||
@for q in quotes {
|
||||
(quote(&q))
|
||||
div class="flex flex-col gap-4 mb-8" {
|
||||
@for q in "es {
|
||||
(quote(q))
|
||||
}
|
||||
|
||||
div class="flex justify-between items-center mt-4 text-neutral-400" {
|
||||
@if page > 1 {
|
||||
a href=(format!("/quotes?page={}", (page - 1).min(1))) class="px-4 py-2 border border-neutral-200/25 hover:border-neutral-200/45 bg-neutral-200/5 hover:bg-neutral-200/15 rounded" {
|
||||
"Previous"
|
||||
}
|
||||
} @else {
|
||||
div {}
|
||||
}
|
||||
|
||||
span {
|
||||
"Page " (page) " of " (total_pages)
|
||||
}
|
||||
|
||||
@if page < total_pages {
|
||||
a href=(format!("/quotes?page={}", page + 1)) class="px-4 py-2 border border-neutral-200/25 hover:border-neutral-200/45 bg-neutral-200/5 hover:bg-neutral-200/15 rounded" {
|
||||
"Next"
|
||||
}
|
||||
} @else {
|
||||
div {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user