Better database layout with uuid primary keys
Serialize and deserialize the uuid ids as base62 strings in the URLs.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use axum::extract::{State, Path};
|
||||
use axum::extract::{Path, State};
|
||||
use axum::response::Response;
|
||||
use maud::{html, PreEscaped};
|
||||
use sqlx::PgPool;
|
||||
@@ -6,9 +6,14 @@ use sqlx::PgPool;
|
||||
use crate::error::Result;
|
||||
use crate::models::entry::get_entry;
|
||||
use crate::partials::layout::Layout;
|
||||
use crate::uuid::Base62Uuid;
|
||||
|
||||
pub async fn get(Path(id): Path<i32>, State(pool): State<PgPool>, layout: Layout) -> Result<Response> {
|
||||
let entry = get_entry(&pool, id).await?;
|
||||
pub async fn get(
|
||||
Path(id): Path<Base62Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
layout: Layout,
|
||||
) -> Result<Response> {
|
||||
let entry = get_entry(&pool, id.as_uuid()).await?;
|
||||
Ok(layout.render(html! {
|
||||
@let title = entry.title.unwrap_or_else(|| "Untitled".to_string());
|
||||
h1 { a href=(entry.url) { (title) } }
|
||||
|
||||
Reference in New Issue
Block a user