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;
#[derive(Serialize)]
pub struct FormContext<'a> {
pub struct ContactFormContext<'a> {
pub path_prefix: &'a str,
pub was_validated: bool,
pub id: u16,
@ -11,33 +11,3 @@ pub struct FormContext<'a> {
pub message: &'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 form_context = context::FormContext::new(
&config.path_prefix,
was_validated,
let form_context = context::ContactFormContext {
path_prefix: &config.path_prefix,
was_validated: was_validated.unwrap_or(false),
id,
name,
email,
telefon,
message,
&captcha_base64,
);
name: name.unwrap_or(""),
email: email.unwrap_or(""),
telefon: telefon.unwrap_or(""),
message: message.unwrap_or(""),
captcha: &captcha_base64,
};
Ok(Template::render("form", form_context))
}