diff --git a/src/routes/admin/dashboard.rs b/src/routes/admin/dashboard.rs index e2bbbd1..0fd32fd 100644 --- a/src/routes/admin/dashboard.rs +++ b/src/routes/admin/dashboard.rs @@ -20,7 +20,7 @@ pub(super) async fn admin_dashboard( .map_err(e500)?; Ok(Dashboard { - title: "Admin Dashboard", + page_title: "Admin Dashboard", welcome: "Welcome", available_actions: "Available actions", send_newsletter: "Send newsletter", @@ -50,7 +50,7 @@ pub async fn get_username(db_pool: &PgPool, user_id: Uuid) -> Result { - title: &'a str, + page_title: &'a str, welcome: &'a str, available_actions: &'a str, send_newsletter: &'a str, diff --git a/src/routes/admin/newsletters/get.rs b/src/routes/admin/newsletters/get.rs index 08f1b54..55a6899 100644 --- a/src/routes/admin/newsletters/get.rs +++ b/src/routes/admin/newsletters/get.rs @@ -7,13 +7,13 @@ pub(in crate::routes::admin) async fn newsletter_form( let flashes = messages.map(|m| m.message).collect(); NewsletterForm { - title: "Send Newsletter", - newsletter_title_label: "Newsletter title", - newsletter_title_placeholder: "Enter newsletter title", - newsletter_html_label: "Newsletter HTML content", - newsletter_html_placeholder: "Enter newsletter HTML content", - newsletter_text_label: "Newsletter text", - newsletter_text_placeholder: "Enter newsletter text", + page_title: "Send Newsletter", + title_label: "Newsletter title", + title_placeholder: "Enter newsletter title", + html_content_label: "Newsletter HTML content", + html_content_placeholder: "Enter newsletter HTML content", + text_content_label: "Newsletter text", + text_content_placeholder: "Enter newsletter text", send_newsletter_button: "Send newsletter", back_link: "Back", flashes, @@ -23,13 +23,13 @@ pub(in crate::routes::admin) async fn newsletter_form( #[derive(Template)] #[template(path = "web/newsletter_form.html")] pub(in crate::routes::admin) struct NewsletterForm<'a> { - title: &'a str, - newsletter_title_label: &'a str, - newsletter_title_placeholder: &'a str, - newsletter_html_label: &'a str, - newsletter_html_placeholder: &'a str, - newsletter_text_label: &'a str, - newsletter_text_placeholder: &'a str, + page_title: &'a str, + title_label: &'a str, + title_placeholder: &'a str, + html_content_label: &'a str, + html_content_placeholder: &'a str, + text_content_label: &'a str, + text_content_placeholder: &'a str, send_newsletter_button: &'a str, back_link: &'a str, flashes: Vec, diff --git a/src/routes/admin/newsletters/post.rs b/src/routes/admin/newsletters/post.rs index 1d78b94..24c8b1d 100644 --- a/src/routes/admin/newsletters/post.rs +++ b/src/routes/admin/newsletters/post.rs @@ -24,9 +24,9 @@ pub(in crate::routes::admin) async fn publish_newsletter( .email_client .send_email( &subscriber.email, - &form.newsletter_title, - &form.newsletter_html, - &form.newsletter_text, + &form.title, + &form.html_content, + &form.text_content, ) .await .with_context(|| { @@ -73,9 +73,9 @@ async fn get_confirmed_subscribers( #[derive(Deserialize)] pub(in crate::routes::admin) struct FormData { - newsletter_title: String, - newsletter_html: String, - newsletter_text: String, + title: String, + html_content: String, + text_content: String, } struct ConfirmedSubscriber { diff --git a/src/routes/admin/password/get.rs b/src/routes/admin/password/get.rs index d721ace..67e6a35 100644 --- a/src/routes/admin/password/get.rs +++ b/src/routes/admin/password/get.rs @@ -7,7 +7,7 @@ pub(in crate::routes::admin) async fn change_password_form( let flashes = messages.map(|m| m.message).collect(); ChangePasswordForm { - title: "Change Password", + page_title: "Change Password", current_password_label: "Current Password", current_password_placeholder: "Enter current password", new_password_label: "New Password", @@ -23,7 +23,7 @@ pub(in crate::routes::admin) async fn change_password_form( #[derive(Template)] #[template(path = "web/change_password_form.html")] pub(in crate::routes::admin) struct ChangePasswordForm<'a> { - title: &'a str, + page_title: &'a str, current_password_label: &'a str, current_password_placeholder: &'a str, new_password_label: &'a str, diff --git a/src/routes/home.rs b/src/routes/home.rs index 74a44f8..bcda68e 100644 --- a/src/routes/home.rs +++ b/src/routes/home.rs @@ -9,7 +9,7 @@ pub fn router() -> Router { #[tracing::instrument(name = "Render home page")] async fn home() -> HomeTemplate<'static> { HomeTemplate { - title: "zero2prod", + page_title: "zero2prod", username: None, } } @@ -17,6 +17,6 @@ async fn home() -> HomeTemplate<'static> { #[derive(Template)] #[template(path = "web/home.html")] struct HomeTemplate<'a> { - title: &'a str, + page_title: &'a str, username: Option, } diff --git a/src/routes/login/get.rs b/src/routes/login/get.rs index 5a1d8da..698b809 100644 --- a/src/routes/login/get.rs +++ b/src/routes/login/get.rs @@ -6,7 +6,7 @@ pub(super) async fn login_form(messages: Messages) -> LoginForm<'static> { let flashes = messages.map(|m| m.message).collect(); LoginForm { - title: "Login", + page_title: "Login", username_label: "Username", username_placeholder: "Enter username", password_label: "Password", @@ -20,7 +20,7 @@ pub(super) async fn login_form(messages: Messages) -> LoginForm<'static> { #[derive(Template)] #[template(path = "web/login_form.html")] pub(super) struct LoginForm<'a> { - title: &'a str, + page_title: &'a str, username_label: &'a str, username_placeholder: &'a str, password_label: &'a str, diff --git a/templates/web/base.html b/templates/web/base.html index bb25518..d80b1b3 100644 --- a/templates/web/base.html +++ b/templates/web/base.html @@ -3,11 +3,11 @@ - {% block title %}{{ title }}{% endblock %} + {% block page_title %}{{ page_title }}{% endblock %} - {% block content %}Something went wrong with rendering{% endblock %} + {% block page_content %}Something went wrong with rendering{% endblock %} diff --git a/templates/web/change_password_form.html b/templates/web/change_password_form.html index 0fb81a7..a7394a4 100644 --- a/templates/web/change_password_form.html +++ b/templates/web/change_password_form.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% block content %} +{% block page_content %} {%- for flash in flashes %}

{{ flash }}

{%- endfor %} diff --git a/templates/web/dashboard.html b/templates/web/dashboard.html index 70e1314..c7f3a7b 100644 --- a/templates/web/dashboard.html +++ b/templates/web/dashboard.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% block content %} +{% block page_content %}

{{ welcome }}, {{ username }}!

{{ available_actions }}:

    diff --git a/templates/web/home.html b/templates/web/home.html index de0b0b2..b7592fb 100644 --- a/templates/web/home.html +++ b/templates/web/home.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% block content %} +{% block page_content %} {%- if let Some(username) = username %}

    Welcome to our newsletter, {{ username }}!

    {% else %} diff --git a/templates/web/login_form.html b/templates/web/login_form.html index 4eb22d5..e09f2c6 100644 --- a/templates/web/login_form.html +++ b/templates/web/login_form.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% block content %} +{% block page_content %} {%- for flash in flashes %}

    {{ flash }}

    {%- endfor %} diff --git a/templates/web/newsletter_form.html b/templates/web/newsletter_form.html index 70c34d0..da14327 100644 --- a/templates/web/newsletter_form.html +++ b/templates/web/newsletter_form.html @@ -1,28 +1,28 @@ {% extends "base.html" %} -{% block content %} +{% block page_content %} {%- for flash in flashes %}

    {{ flash }}

    {%- endfor %}






    diff --git a/tests/api/admin_newsletters.rs b/tests/api/admin_newsletters.rs index 130efbb..a037876 100644 --- a/tests/api/admin_newsletters.rs +++ b/tests/api/admin_newsletters.rs @@ -10,9 +10,9 @@ async fn newsletters_are_delivered_to_confirmed_subscribers() { // given let app = TestApp::spawn().await; let newsletter_request_body = json!({ - "newsletter_title": "Newsletter Title", - "newsletter_html": "

    Newsletter body as html.

    ", - "newsletter_text": "Newsletter body as text.", + "title": "Newsletter Title", + "html_content": "

    Newsletter body as html.

    ", + "text_content": "Newsletter body as text.", }); create_confirmed_subscriber(&app).await; @@ -43,9 +43,9 @@ async fn newsletters_are_not_delivered_to_unconfirmed_subscribers() { // given let app = TestApp::spawn().await; let newsletter_request_body = json!({ - "newsletter_title": "Newsletter Title", - "newsletter_html": "

    Newsletter body as html.

    ", - "newsletter_text": "Newsletter body as text.", + "title": "Newsletter Title", + "html_content": "

    Newsletter body as html.

    ", + "text_content": "Newsletter body as text.", }); create_unfonfirmed_subscriber(&app).await; @@ -77,22 +77,22 @@ async fn newsletters_returns_400_for_invalid_data() { let test_cases = vec![ ( json!({ - "newsletter_html": "

    Newsletter body as html.

    ", - "newsletter_text": "Newsletter body as text.", + "html_content": "

    Newsletter body as html.

    ", + "text_content": "Newsletter body as text.", }), "missing title", ), ( json!({ - "newsletter_title": "Newsletter Title", - "newsletter_text": "Newsletter body as text.", + "title": "Newsletter Title", + "text_content": "Newsletter body as text.", }), "missing html content", ), ( json!({ - "newsletter_title": "Newsletter Title", - "newsletter_html": "

    Newsletter body as html.

    ", + "title": "Newsletter Title", + "html_content": "

    Newsletter body as html.

    ", }), "missing text content", ), @@ -125,9 +125,9 @@ async fn requests_from_anonymous_users_are_redirected_to_login() { // given let app = TestApp::spawn().await; let newsletter_request_body = json!({ - "newsletter_title": "Newsletter Title", - "newsletter_html": "

    Newsletter body as html.

    ", - "newsletter_text": "Newsletter body as text.", + "title": "Newsletter Title", + "html_content": "

    Newsletter body as html.

    ", + "text_content": "Newsletter body as text.", }); // when