From 370a25e5a0cbb95e2aa1cec55305b22aeaf99aa0 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Tue, 12 Dec 2023 14:14:30 +0000 Subject: initial refactor --- src/routes/home.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/routes/home.rs (limited to 'src/routes/home.rs') diff --git a/src/routes/home.rs b/src/routes/home.rs new file mode 100644 index 0000000..11d3a72 --- /dev/null +++ b/src/routes/home.rs @@ -0,0 +1,21 @@ +use actix_session::Session; +use actix_web::{get, web, HttpResponse}; + +use crate::templates; +use crate::{Pinussy, Result}; + +#[get("/")] +async fn get(session: Session, state: web::Data) -> Result { + let username: Option; + if let Some(user_id) = session.get::("user_id")? { + username = Some( + sqlx::query!("select username from users where id = $1", user_id) + .fetch_one(&state.db) + .await? + .username, + ) + } else { + username = None + } + return Ok(HttpResponse::Ok().body(render!(templates::home_html, username).unwrap())); +} -- cgit