From 450468ef3d6903aa56eb6e5422e5bd3e765b47cf Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Mon, 4 May 2026 13:30:33 +0200 Subject: [PATCH] feat(templates): add base layout, login, register, new_review templates; update diary --- crates/adapters/template-askama/src/lib.rs | 63 +++++++++- .../template-askama/templates/base.html | 29 +++++ .../template-askama/templates/diary.html | 110 ++++++------------ .../template-askama/templates/login.html | 18 +++ .../template-askama/templates/new_review.html | 40 +++++++ .../template-askama/templates/register.html | 18 +++ 6 files changed, 198 insertions(+), 80 deletions(-) create mode 100644 crates/adapters/template-askama/templates/base.html create mode 100644 crates/adapters/template-askama/templates/login.html create mode 100644 crates/adapters/template-askama/templates/new_review.html create mode 100644 crates/adapters/template-askama/templates/register.html diff --git a/crates/adapters/template-askama/src/lib.rs b/crates/adapters/template-askama/src/lib.rs index 0689d65..4e8f177 100644 --- a/crates/adapters/template-askama/src/lib.rs +++ b/crates/adapters/template-askama/src/lib.rs @@ -1,5 +1,7 @@ use askama::Template; -use application::ports::HtmlRenderer; +use application::ports::{ + HtmlPageContext, HtmlRenderer, LoginPageData, NewReviewPageData, RegisterPageData, +}; use domain::models::{DiaryEntry, collections::Paginated}; #[derive(Template)] @@ -9,6 +11,28 @@ struct DiaryTemplate<'a> { current_offset: u32, limit: u32, has_more: bool, + ctx: &'a HtmlPageContext, +} + +#[derive(Template)] +#[template(path = "login.html")] +struct LoginTemplate<'a> { + error: Option<&'a str>, + ctx: &'a HtmlPageContext, +} + +#[derive(Template)] +#[template(path = "register.html")] +struct RegisterTemplate<'a> { + error: Option<&'a str>, + ctx: &'a HtmlPageContext, +} + +#[derive(Template)] +#[template(path = "new_review.html")] +struct NewReviewTemplate<'a> { + error: Option<&'a str>, + ctx: &'a HtmlPageContext, } pub struct AskamaHtmlRenderer; @@ -20,16 +44,43 @@ impl AskamaHtmlRenderer { } impl HtmlRenderer for AskamaHtmlRenderer { - fn render_diary_page(&self, data: &Paginated) -> Result { + fn render_diary_page(&self, data: &Paginated, ctx: HtmlPageContext) -> Result { let has_more = (data.offset + data.limit) < data.total_count as u32; - - let template = DiaryTemplate { + DiaryTemplate { entries: &data.items, current_offset: data.offset, limit: data.limit, has_more, - }; + ctx: &ctx, + } + .render() + .map_err(|e| e.to_string()) + } - template.render().map_err(|e| e.to_string()) + fn render_login_page(&self, data: LoginPageData<'_>) -> Result { + LoginTemplate { + error: data.error, + ctx: &data.ctx, + } + .render() + .map_err(|e| e.to_string()) + } + + fn render_register_page(&self, data: RegisterPageData<'_>) -> Result { + RegisterTemplate { + error: data.error, + ctx: &data.ctx, + } + .render() + .map_err(|e| e.to_string()) + } + + fn render_new_review_page(&self, data: NewReviewPageData<'_>) -> Result { + NewReviewTemplate { + error: data.error, + ctx: &data.ctx, + } + .render() + .map_err(|e| e.to_string()) } } diff --git a/crates/adapters/template-askama/templates/base.html b/crates/adapters/template-askama/templates/base.html new file mode 100644 index 0000000..ec6fb1e --- /dev/null +++ b/crates/adapters/template-askama/templates/base.html @@ -0,0 +1,29 @@ + + + + + + Movies Diary + + + +
+ Movies Diary + +
+
+ {% block content %}{% endblock %} +
+ + diff --git a/crates/adapters/template-askama/templates/diary.html b/crates/adapters/template-askama/templates/diary.html index 7a54782..00ed72c 100644 --- a/crates/adapters/template-askama/templates/diary.html +++ b/crates/adapters/template-askama/templates/diary.html @@ -1,76 +1,38 @@ - - - - - - My Movie Diary - - - -

Movie Diary

- - -
-
- Log a Movie - - -

- - -

- - -

- - -

- - -
-
- -
- - -
- {% for entry in entries %} -
- {% if let Some(poster) = entry.movie().poster_path() %} - - Poster - {% endif %} - -

{{ entry.movie().title().value() }} ({{ entry.movie().release_year().value() }})

-

Rating: {{ entry.review().rating().value() }} / 5

- - {% if let Some(comment) = entry.review().comment() %} -

"{{ comment.value() }}"

- {% endif %} - -

Watched on: {{ entry.review().watched_at().format("%Y-%m-%d") }}

-
-
- {% else %} -

No movies logged yet. Go watch something!

- {% endfor %} +{% extends "base.html" %} +{% block content %} +
+ {% for entry in entries %} +
+ {% if let Some(poster) = entry.movie().poster_path() %} +
+
- - -
- {% if current_offset > 0 %} - Previous Page - {% endif %} - {% if has_more %} - Next Page - {% endif %} + {% endif %} +
+
+ {{ entry.movie().title().value() }} + ({{ entry.movie().release_year().value() }}) +
+ {% if let Some(dir) = entry.movie().director() %} +
{{ dir }}
+ {% endif %} +
{{ entry.review().rating().value() }}/5
+ {% if let Some(comment) = entry.review().comment() %} +
{{ comment.value() }}
+ {% endif %} +
{{ entry.review().watched_at().format("%Y-%m-%d") }}
- - \ No newline at end of file +
+ {% else %} +

No movies logged yet.

+ {% endfor %} +
+ +{% endblock %} diff --git a/crates/adapters/template-askama/templates/login.html b/crates/adapters/template-askama/templates/login.html new file mode 100644 index 0000000..967c22c --- /dev/null +++ b/crates/adapters/template-askama/templates/login.html @@ -0,0 +1,18 @@ +{% extends "base.html" %} +{% block content %} +

Login

+{% if let Some(err) = error %} +

{{ err }}

+{% endif %} +
+ + + +
+{% endblock %} diff --git a/crates/adapters/template-askama/templates/new_review.html b/crates/adapters/template-askama/templates/new_review.html new file mode 100644 index 0000000..912f2b7 --- /dev/null +++ b/crates/adapters/template-askama/templates/new_review.html @@ -0,0 +1,40 @@ +{% extends "base.html" %} +{% block content %} +

Log a Review

+{% if let Some(err) = error %} +

{{ err }}

+{% endif %} +
+ +
+ + + +
+ + + + +
+{% endblock %} diff --git a/crates/adapters/template-askama/templates/register.html b/crates/adapters/template-askama/templates/register.html new file mode 100644 index 0000000..7d9f02f --- /dev/null +++ b/crates/adapters/template-askama/templates/register.html @@ -0,0 +1,18 @@ +{% extends "base.html" %} +{% block content %} +

Register

+{% if let Some(err) = error %} +

{{ err }}

+{% endif %} +
+ + + +
+{% endblock %}