diff --git a/src/db/schema.rs b/src/db/schema.rs index 044dd5a..5d7042f 100644 --- a/src/db/schema.rs +++ b/src/db/schema.rs @@ -7,7 +7,7 @@ pub struct DollTags(sqlx::SqlitePool); pub type DollTagsDb = Connection; // Doll Profiles stuff -#[derive(Debug)] +#[derive(Debug, Serialise)] pub struct DollProfile { pub id: i64, pub created_at: chrono::NaiveDateTime, diff --git a/src/main.rs b/src/main.rs index c8b35cf..3fdbb77 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use db::schema::{CreateDollProfile, DollTags, DollTagsDb}; use regex::Regex; use rocket::form::Form; use rocket::fs::{relative, FileServer}; +use rocket::response::Redirect; use rocket_db_pools::Database; use rocket_dyn_templates::{context, Template}; @@ -102,16 +103,21 @@ async fn handle_register(db: DollTagsDb, tag: Form>) -> Template { } #[get("/profile?")] -async fn show_profile(db: DollTagsDb, ident: &str) -> Template { - let profile = doll::get(db, 423158).await.expect("fuck"); +async fn show_profile(db: DollTagsDb, ident: &str) -> Result { + let internal_id = id_public_to_db(ident).ok_or_else(|| Redirect::to(uri!("/")))?; + let profile = doll::get(db, internal_id).await.expect("fuck"); + + if let None = profile { + return Err(Redirect::to(uri!("/"))); + } println!("{:?}", profile); - Template::render( + Ok(Template::render( "show_profile", context! { - ident, + profile, }, - ) + )) } #[launch]