From 2110516859553dfd7f6df8748e137b58df2d4d5b Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Tue, 9 Jan 2024 06:01:02 -0600 Subject: [PATCH] adding a more robust health form api --- src/api/health_form.rs | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/api/health_form.rs b/src/api/health_form.rs index 6662602..5731c32 100644 --- a/src/api/health_form.rs +++ b/src/api/health_form.rs @@ -63,14 +63,40 @@ struct HealthForm { #[post("/health-form")] pub async fn health_form(MultipartForm(form): MultipartForm) -> HttpResponse { - let first = form.first_name.as_ref().unwrap().0.clone(); - let last = form.last_name.as_ref().unwrap().0.clone(); + let first = form + .first_name + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); + let last = form + .last_name + .as_ref() + .unwrap_or(&Text { + 0: String::from(""), + }) + .0 + .clone(); let email_subject = format!("{} {} filled out a health form!", first, last); let filename_noext = String::from(format!("{}_{}", first, last)); let parent = format!( "{} {}", - form.parent_first_name.as_ref().unwrap().0.clone(), - form.parent_last_name.as_ref().unwrap().0.clone() + form.parent_first_name + .as_ref() + .unwrap_or(&Text { + 0: String::from("") + }) + .0 + .clone(), + form.parent_last_name + .as_ref() + .unwrap_or(&Text { + 0: String::from("") + }) + .0 + .clone() ); let birthdate = form .birthdate