From 7aa6d7bf4d945387fb16a9c2a7a2c6e00adcd4fc Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Mon, 4 May 2026 14:31:12 +0200 Subject: [PATCH] feat(template): add user_id to HtmlPageContext and delete button to diary --- crates/adapters/template-askama/templates/diary.html | 7 +++++++ crates/application/src/ports.rs | 3 +++ crates/presentation/src/handlers.rs | 8 ++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/adapters/template-askama/templates/diary.html b/crates/adapters/template-askama/templates/diary.html index ac0492e..61fc515 100644 --- a/crates/adapters/template-askama/templates/diary.html +++ b/crates/adapters/template-askama/templates/diary.html @@ -21,6 +21,13 @@
{{ comment.value() }}
{% endif %}
{{ entry.review().watched_at().format("%Y-%m-%d") }}
+ {% if let Some(uid) = ctx.user_id %} + {% if *uid == entry.review().user_id().value() %} +
+ +
+ {% endif %} + {% endif %} {% else %} diff --git a/crates/application/src/ports.rs b/crates/application/src/ports.rs index f11ff46..1b03f17 100644 --- a/crates/application/src/ports.rs +++ b/crates/application/src/ports.rs @@ -1,7 +1,10 @@ +use uuid::Uuid; + use domain::models::{DiaryEntry, collections::Paginated}; pub struct HtmlPageContext { pub user_email: Option, + pub user_id: Option, pub register_enabled: bool, } diff --git a/crates/presentation/src/handlers.rs b/crates/presentation/src/handlers.rs index 872649d..72d2ae5 100644 --- a/crates/presentation/src/handlers.rs +++ b/crates/presentation/src/handlers.rs @@ -24,11 +24,12 @@ pub mod html { }; async fn build_page_context(state: &AppState, user_id: Option) -> HtmlPageContext { - let user_email = if let Some(id) = user_id { + let uuid = user_id.as_ref().map(|u| u.value()); + let user_email = if let Some(ref id) = user_id { state .app_ctx .user_repository - .find_by_id(&id) + .find_by_id(id) .await .ok() .flatten() @@ -38,6 +39,7 @@ pub mod html { }; HtmlPageContext { user_email, + user_id: uuid, register_enabled: state.app_ctx.config.allow_registration, } } @@ -89,6 +91,7 @@ pub mod html { ) -> impl IntoResponse { let ctx = HtmlPageContext { user_email: None, + user_id: None, register_enabled: state.app_ctx.config.allow_registration, }; let html = state @@ -140,6 +143,7 @@ pub mod html { } let ctx = HtmlPageContext { user_email: None, + user_id: None, register_enabled: true, }; let html = state