No need for context constructor

This commit is contained in:
Mo 2022-10-29 17:55:00 +02:00
parent 57471181f3
commit 635e7e4266
2 changed files with 10 additions and 40 deletions

View file

@ -1,7 +1,7 @@
use serde::Serialize; use serde::Serialize;
#[derive(Serialize)] #[derive(Serialize)]
pub struct FormContext<'a> { pub struct ContactFormContext<'a> {
pub path_prefix: &'a str, pub path_prefix: &'a str,
pub was_validated: bool, pub was_validated: bool,
pub id: u16, pub id: u16,
@ -11,33 +11,3 @@ pub struct FormContext<'a> {
pub message: &'a str, pub message: &'a str,
pub captcha: &'a str, pub captcha: &'a str,
} }
impl<'a> FormContext<'a> {
pub fn new(
path_prefix: &'a str,
was_validated: Option<bool>,
id: u16,
name: Option<&'a str>,
email: Option<&'a str>,
telefon: Option<&'a str>,
message: Option<&'a str>,
captcha: &'a str,
) -> Self {
let was_validated = was_validated.unwrap_or(false);
let name = name.unwrap_or("");
let email = email.unwrap_or("");
let telefon = telefon.unwrap_or("");
let message = message.unwrap_or("");
Self {
path_prefix,
was_validated,
id,
name,
email,
telefon,
message,
captcha,
}
}
}

View file

@ -29,16 +29,16 @@ pub fn index(
let id = captcha_solutions.store_solution(&captcha.chars_as_string()); let id = captcha_solutions.store_solution(&captcha.chars_as_string());
let form_context = context::FormContext::new( let form_context = context::ContactFormContext {
&config.path_prefix, path_prefix: &config.path_prefix,
was_validated, was_validated: was_validated.unwrap_or(false),
id, id,
name, name: name.unwrap_or(""),
email, email: email.unwrap_or(""),
telefon, telefon: telefon.unwrap_or(""),
message, message: message.unwrap_or(""),
&captcha_base64, captcha: &captcha_base64,
); };
Ok(Template::render("form", form_context)) Ok(Template::render("form", form_context))
} }