diff --git a/justfile b/justfile index 9c5a727..88d2fdd 100644 --- a/justfile +++ b/justfile @@ -2,6 +2,8 @@ default: just --list build: rm -rf public && NODE_ENV=production ./themes/blowfish/node_modules/tailwindcss/lib/cli.js -c ./themes/blowfish/tailwind.config.js -i ./themes/blowfish/assets/css/main.css -o ./assets/css/compiled/main.css --jit && hugo --gc --minify +run: + cargo run server: hugo server --noHTTPCache --disableFastRender dev: @@ -12,4 +14,4 @@ clean: cargo clean rm -rf bld/ test: - RUST_LOG=debug cargo test --benches --tests --all-features -- --nocapture \ No newline at end of file + RUST_LOG=debug cargo test --benches --tests --all-features -- --nocapture diff --git a/src/api/camp_form.rs b/src/api/camp_form.rs index 61faaa9..2822df5 100644 --- a/src/api/camp_form.rs +++ b/src/api/camp_form.rs @@ -321,8 +321,7 @@ pub async fn camp_form(MultipartForm(form): MultipartForm) -> HttpResp "later" => { log::info!("{} would like to pay later", full_name); let html = html! { - div { - class { "mt-8" } + div class="mt-8" { h2 { "Thank you, " (full_name) "!" } @@ -338,8 +337,7 @@ pub async fn camp_form(MultipartForm(form): MultipartForm) -> HttpResp _ => { log::error!("Got registration error....."); let html = html! { - div { - class { "mt-8" } + div class="mt-8" { h2 { "Thank you, " (full_name) "!" } diff --git a/src/api/health_form.rs b/src/api/health_form.rs index ca29d1d..2b3b482 100644 --- a/src/api/health_form.rs +++ b/src/api/health_form.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{collections::HashMap, fs}; use actix_multipart::form::{tempfile::TempFile, text::Text, MultipartForm}; use actix_web::{post, HttpResponse}; @@ -8,6 +8,7 @@ use lettre::{ Message, SmtpTransport, Transport, }; use maud::html; +use reqwest::{Client, Error}; #[derive(Debug, MultipartForm, Default)] struct HealthForm { @@ -386,7 +387,13 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http let mut path: Option = Some(String::from("")); let mut file_exists = false; let mut filename = String::from(""); - log::info!("{:?}", file_exists); + log::info!("Does the file exist? {:?}", file_exists); + + match store_health_form(&form).await { + Ok(_) => log::info!("Successfully posted the health form in nextcloud tables"), + Err(e) => log::error!("Error posting health form to nextcloud tables: {:?}", e), + } + if let Some(f) = form.file { if let Some(file) = f.file_name { if let Some(ext) = file.rsplit('.').next() { @@ -399,7 +406,10 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http log::info!("saving to {}", path.clone().unwrap()); match f.file.persist(path.clone().unwrap()) { Ok(f) => { - log::info!("{:?}", f); + log::info!( + "Hey! We got a file! {:?}", + f.metadata().expect("Something bad happened mate") + ); if f.metadata().unwrap().len() > 0 { file_exists = true; } @@ -413,7 +423,7 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http let filebody = fs::read(path.clone().unwrap_or_default()); let content_type = ContentType::parse("image/jpg").unwrap(); let attachment = Attachment::new(filename).body(filebody.unwrap(), content_type); - log::info!("{:?}", attachment); + // log::info!("The attachment is: {:?}", attachment.headers()); MultiPart::mixed() .singlepart(SinglePart::html(email.into_string())) .singlepart(attachment) @@ -475,8 +485,7 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http "later" => { log::info!("{} would like to pay later", full_name); let html = html! { - div { - class { "mt-8" } + div class="mt-8" { h2 { "Thank you, " (full_name) "!" } @@ -492,8 +501,7 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http _ => { log::error!("Got registration error....."); let html = html! { - div { - class { "mt-8" } + div class="mt-8" { h2 { "Thank you, " (full_name) "!" } @@ -510,6 +518,240 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http // HttpResponse::Ok().body("hi") } -async fn store_health_form(_form: HealthForm) -> bool { - todo!() +async fn store_health_form(form: &HealthForm) -> Result<(), Error> { + let request = Client::new(); + let mut map = HashMap::new(); + map.insert( + 37, + format!( + "{} {}", + form.first_name + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + form.last_name + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone() + ), + ); + map.insert( + 38, + format!( + "{} {}", + form.parent_first_name + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + form.parent_last_name + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone() + ), + ); + map.insert( + 39, + form.birthdate + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 40, + form.street + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 41, + form.city.as_ref().unwrap_or(&Text(String::new())).0.clone(), + ); + map.insert( + 42, + form.state + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 43, + form.zip.as_ref().unwrap_or(&Text(String::new())).0.clone(), + ); + map.insert( + 44, + form.parent_cellphone + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 45, + form.homephone + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 46, + format!( + "{} {}", + form.contact + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + form.contact_phone + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ), + ); + map.insert( + 47, + form.doctorname + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 48, + form.doctorcity + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 49, + form.doctorphone + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 50, + form.medical + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 51, + form.insurance + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 52, + form.policy_number + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 54, + form.agreement + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 55, + format!( + "{}{}", + form.allergies + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + form.allergies_other + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ), + ); + map.insert( + 56, + form.specific_allergies + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 57, + form.treatment + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 58, + form.conditions + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 59, + form.tetanus + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 62, + form.swimming + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 60, + form.medication + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + map.insert( + 61, + form.notes + .as_ref() + .unwrap_or(&Text(String::new())) + .0 + .clone(), + ); + let mut json = HashMap::new(); + json.insert("data", map); + request + .post("https://staff.tfcconnection.org/apps/tables/api/1/tables/4/rows") + .basic_auth("chris", Some("2VHeGxeC^Zf9KqFK^G@Pt!zu2q^6@b")) + .json(&json) + .send() + .await?; + Ok(()) } diff --git a/src/api/mod.rs b/src/api/mod.rs index f9c19bf..184fa4f 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,6 +1,6 @@ pub mod camp_form; pub mod church_form; -pub mod errors; +// pub mod errors; pub mod health_form; pub mod local_trip_form; pub mod mt_form;