working server built betterer in rust
This commit is contained in:
		
							parent
							
								
									1decdb43a5
								
							
						
					
					
						commit
						0ccbe35ca3
					
				
					 4 changed files with 258 additions and 16 deletions
				
			
		
							
								
								
									
										4
									
								
								justfile
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								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
 | 
			
		||||
    RUST_LOG=debug cargo test --benches --tests --all-features -- --nocapture
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -321,8 +321,7 @@ pub async fn camp_form(MultipartForm(form): MultipartForm<CampForm>) -> 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<CampForm>) -> HttpResp
 | 
			
		|||
            _ => {
 | 
			
		||||
                log::error!("Got registration error.....");
 | 
			
		||||
                let html = html! {
 | 
			
		||||
                    div {
 | 
			
		||||
                        class { "mt-8" }
 | 
			
		||||
                    div class="mt-8" {
 | 
			
		||||
                        h2 {
 | 
			
		||||
                            "Thank you, " (full_name) "!"
 | 
			
		||||
                        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<HealthForm>) -> Http
 | 
			
		|||
    let mut path: Option<String> = 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<HealthForm>) -> 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<HealthForm>) -> 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<HealthForm>) -> 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<HealthForm>) -> 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<HealthForm>) -> 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(())
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue