adding working mission trip forms

This commit is contained in:
Chris Cochrun 2024-12-05 15:16:45 -06:00
parent 6603d2c6bc
commit 67fb7b0f00
16 changed files with 104 additions and 581 deletions

View file

@ -22,6 +22,7 @@ struct MtParentForm {
first_name: Text<String>,
#[multipart(rename = "lastname")]
last_name: Text<String>,
email: Text<String>,
#[multipart(rename = "studentfirstname")]
student_first_name: Text<String>,
#[multipart(rename = "studentlastname")]
@ -42,18 +43,19 @@ struct MtParentForm {
impl From<&MtParentForm> for HashMap<i32, String> {
fn from(form: &MtParentForm) -> Self {
let mut map = HashMap::new();
map.insert(158, format!("{} {}", form.first_name.0, form.last_name.0));
map.insert(167, format!("{} {}", form.first_name.0, form.last_name.0));
map.insert(
159,
168,
format!("{} {}", form.student_first_name.0, form.student_last_name.0),
);
map.insert(160, form.authority.0.clone());
map.insert(163, form.positive.0.clone());
map.insert(164, form.negative.0.clone());
map.insert(161, form.family.0.clone());
map.insert(162, form.previous_trip.0.clone());
map.insert(165, form.feelings.0.clone());
map.insert(166, form.extra_info.0.clone());
map.insert(169, form.authority.0.clone());
map.insert(170, form.positive.0.clone());
map.insert(171, form.negative.0.clone());
map.insert(172, form.family.0.clone());
map.insert(173, form.previous_trip.0.clone());
map.insert(174, form.feelings.0.clone());
map.insert(175, form.extra_info.0.clone());
map.insert(176, form.email.0.clone());
map
}
}
@ -65,7 +67,7 @@ impl MtParentForm {
meta charset="utf-8";
html {
head {
title { (self.first_name.0) " " (self.last_name.0) " signed up for mission trip!" }
title { (self.first_name.0) " " (self.last_name.0) " filled out a parent form for " (self.student_first_name.0) " " (self.student_last_name.0) "!" }
style {
"table { border-collapse: collapse; width: 100% }"
"td, th { padding: 8px }"
@ -76,7 +78,7 @@ impl MtParentForm {
}
}
body {
h1 { "Mission trip form for " (self.first_name.0) " " (self.last_name.0) "!" }
h1 { "Parent reference form for " (self.student_first_name.0) " " (self.student_last_name.0) "!" }
hr;
table {
tr {
@ -87,6 +89,10 @@ impl MtParentForm {
th { "Student" }
td { (self.student_first_name.0) " " (self.student_last_name.0) }
}
tr {
th { "Email" }
td { (self.email.0) }
}
tr {
th { "Authority" }
td { (self.authority.0) }
@ -127,9 +133,9 @@ impl MtParentForm {
let mut json = HashMap::new();
json.insert("data", map);
let link = r#"https://staff.tfcconnection.org/apps/tables/#/table/13/row/757"#;
let link = r#"https://staff.tfcconnection.org/apps/tables/#/table/14/row/757"#;
let res = client
.post("https://staff.tfcconnection.org/ocs/v2.php/apps/tables/api/2/tables/13/rows")
.post("https://staff.tfcconnection.org/ocs/v2.php/apps/tables/api/2/tables/14/rows")
.basic_auth("chris", Some("2VHeGxeC^Zf9KqFK^G@Pt!zu2q^6@b"))
.header("OCS-APIRequest", "true")
.header("Content-Type", "application/json")
@ -148,10 +154,10 @@ impl MtParentForm {
}
async fn send_email(&mut self) -> Result<()> {
let first = self.first_name.clone();
let last = self.last_name.clone();
let email_subject = format!("{} {} signed up for mission trip!", first, last);
info!("{first} {last} signed up for mission trip!");
let first = self.student_first_name.clone();
let last = self.student_last_name.clone();
let email_subject = format!("Parent reference form for {} {}!", first, last);
info!("{first} {last} parent reference form!");
let email = self.build_email().await;
let email = SinglePart::html(email.into_string());
@ -172,8 +178,8 @@ impl MtParentForm {
}
}
#[post("/api/mt-teacher-form")]
pub async fn mt_form(MultipartForm(mut form): MultipartForm<MtParentForm>) -> HttpResponse {
#[post("/api/mt-parent-form")]
pub async fn mt_parent_form(MultipartForm(mut form): MultipartForm<MtParentForm>) -> HttpResponse {
match form.store_form().await {
Ok(_) => info!("Successfully sent form to nextcloud!"),
Err(e) => error!("There was an erroring sending form to nextcloud: {e}"),
@ -196,10 +202,11 @@ mod test {
fn form() -> MtParentForm {
MtParentForm {
first_name: Text(String::from("Frodo")),
first_name: Text(String::from("Bilbo")),
last_name: Text(String::from("Braggins")),
student_first_name: Text(String::from("Bilbo")),
student_first_name: Text(String::from("Frodo")),
student_last_name: Text(String::from("Braggins")),
email: Text(String::from("biblo@hobbits.us")),
authority: Text(String::from("Uncle")),
positive: Text(String::from("Nimble and brave")),
negative: Text(String::from("Small")),