barebones quote-specific page
This commit is contained in:
@@ -50,6 +50,7 @@ pub fn pages() -> Router<MnemoState> {
|
|||||||
.route("/logs", get(logs::page))
|
.route("/logs", get(logs::page))
|
||||||
//
|
//
|
||||||
.route("/quotes", get(quotes::page))
|
.route("/quotes", get(quotes::page))
|
||||||
|
.route("/quotes/{id}", get(quotes::id::page))
|
||||||
.route("/quotes/add", get(quotes::add::page))
|
.route("/quotes/add", get(quotes::add::page))
|
||||||
.route("/quotes/add-form", post(quotes::add::form))
|
.route("/quotes/add-form", post(quotes::add::form))
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub mod add;
|
pub mod add;
|
||||||
|
pub mod id;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct PageQuery {
|
pub struct PageQuery {
|
||||||
@@ -85,7 +86,7 @@ pub async fn page(
|
|||||||
}
|
}
|
||||||
div class="flex flex-col gap-4 mb-8" {
|
div class="flex flex-col gap-4 mb-8" {
|
||||||
@for q in "es {
|
@for q in "es {
|
||||||
(quote(q))
|
a href=(format!("/quotes/{}", q.id)) {(quote(q))}
|
||||||
}
|
}
|
||||||
|
|
||||||
div class="flex justify-between items-center mt-4 text-neutral-400" {
|
div class="flex justify-between items-center mt-4 text-neutral-400" {
|
||||||
|
|||||||
53
src/web/pages/quotes/id.rs
Normal file
53
src/web/pages/quotes/id.rs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
use axum::{
|
||||||
|
extract::{Path, Request, State},
|
||||||
|
response::{IntoResponse, Redirect, Response},
|
||||||
|
};
|
||||||
|
use maud::{PreEscaped, html};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
MnemoState,
|
||||||
|
error::CompositeError,
|
||||||
|
quotes::Quote,
|
||||||
|
users::{User, auth::UserAuthenticate},
|
||||||
|
web::{
|
||||||
|
components::{nav::nav, quote::quote},
|
||||||
|
icons,
|
||||||
|
pages::base,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub async fn page(
|
||||||
|
State(state): State<MnemoState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
req: Request,
|
||||||
|
) -> Result<Response, CompositeError> {
|
||||||
|
let mut conn = state.pool.acquire().await?;
|
||||||
|
let u = match User::authenticate(&mut *conn, req.headers()).await? {
|
||||||
|
Some(u) => u,
|
||||||
|
None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()),
|
||||||
|
};
|
||||||
|
let q = Quote::get_by_id(&mut conn, id).await;
|
||||||
|
|
||||||
|
Ok(base(
|
||||||
|
"Add Quote | Mnemosyne",
|
||||||
|
html!(
|
||||||
|
(nav(&mut conn, Some(&u), req.uri().path()).await)
|
||||||
|
|
||||||
|
div class="max-w-4xl mx-auto px-2" {
|
||||||
|
div class="my-4 flex justify-between" {
|
||||||
|
p class="flex items-center gap-2 text-neutral-500" {
|
||||||
|
(PreEscaped(icons::SCROLL_TEXT))
|
||||||
|
span class="font-lora" {"Quote of ID " (id)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@if let Ok(q) = q {
|
||||||
|
(quote(&q))
|
||||||
|
} @else {
|
||||||
|
"Failed to fetch quote. Are you sure it exists?"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.into_response())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user