cleanup database calls
@@ -248,10 +248,9 @@ pub async fn compile_packets(db: &Database) {
// So we have everyone's materials stored locally @ /{temp_dir}/{username}.pdf.
// Let's compile the materials for candidates into one file.
- let mut packets: HashMap<String, Vec<String>> = HashMap::new();
+ let mut packets: HashMap<String, (Applicant, Vec<String>)> = HashMap::new();
for (email, itrs) in interviewers {
- let mut args: Vec<String> = Default::default();
-
+ if let Ok(applicant) = applicants::dsl::applicants.filter(applicants::dsl::email.eq(email.to_string())).first::<Applicant>(&db.conn()) {
// Create the cover page.
let mut user_html = "".to_string();
for (i, start_time, end_time) in itrs.clone() {
@@ -265,6 +264,7 @@ pub async fn compile_packets(db: &Database) {
let cover_html = format!(
r#"<html>
<body>
+<p>{},</p>
<p>
Thank you for your interest in Oxide! We have enjoyed reading the materials
you submitted to Oxide, and we are looking forward to having more conversations
@@ -299,7 +299,7 @@ Sincerely,<br>
The Oxide Team
</body>
</html>"#,
- user_html
+ applicant.name, user_html
);
// Generate a cover for the packet.
@@ -315,8 +315,8 @@ The Oxide Team
pandoc.set_output(OutputKind::File(cover_output.clone()));
pandoc.execute().unwrap();
- // Add the header to our string.
- args.push(cover_output.to_str().unwrap().to_string());
+ // Add the header to our strings.
+ let mut args = vec![cover_output.to_str().unwrap().to_string()];
// Iterate over the interviewees and add their packet to our list of packets.
for (i, start_time, end_time) in itrs {
@@ -352,21 +352,20 @@ The Oxide Team
let mut materials = env::temp_dir();
materials.push(format!("{}.pdf", username));
args.push(materials.to_str().unwrap().to_string());
+ }
// Push it onto our array.
- packets.insert(email.to_string(), args.to_vec());
+ packets.insert(email.to_string(), (applicant.clone(), args.to_vec()));
}
}
// Concatenate all the files.
- for (applicant_email, packet_args) in packets {
- if let Ok(mut applicant) = applicants::dsl::applicants
- .filter(applicants::dsl::email.eq(applicant_email.to_string()))
- .first::<Applicant>(&db.conn())
- {
+ for (a, packet_args) in packets.values() {
+ let mut applicant = a.clone();
+
let filename = format!("Interview Packet - {}.pdf", applicant.name);
- let buffer = combine_pdfs(packet_args);
+ let buffer = combine_pdfs(packet_args.to_vec());
// Create or update the file in the google_drive.
drive_client.create_or_upload_file(&drive_id, &parent_id, &filename, "application/pdf", &buffer).await.unwrap();
@@ -379,7 +378,6 @@ The Oxide Team
applicant.update(db).await;
}
}
-}
/// Download materials file from Google drive and save it as a pdf under the persons username.
#[instrument(skip(drive_client))]
