From abc471fa35c1c97474216baf13dc1c8d8e0519aa Mon Sep 17 00:00:00 2001 From: Celeo Date: Wed, 20 Nov 2024 19:15:28 -0800 Subject: [PATCH] Show more info on user's self training notes page --- vzdv-site/src/endpoints/user.rs | 20 +++++++++++++++---- vzdv-site/templates/changelog.jinja | 1 + vzdv-site/templates/user/training_notes.jinja | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/vzdv-site/src/endpoints/user.rs b/vzdv-site/src/endpoints/user.rs index 26f1919..5e7a126 100644 --- a/vzdv-site/src/endpoints/user.rs +++ b/vzdv-site/src/endpoints/user.rs @@ -13,11 +13,14 @@ use axum::{ use chrono::NaiveDateTime; use log::{debug, warn}; use minijinja::context; -use std::{collections::HashMap, sync::Arc}; +use std::{ + collections::{HashMap, HashSet}, + sync::Arc, +}; use tower_sessions::Session; use vzdv::{ sql::{self, Controller}, - vatusa::{self, TrainingRecord}, + vatusa::{self, get_multiple_controller_names, TrainingRecord}, }; /// Retrieve and show the user their training records from VATUSA. @@ -30,8 +33,9 @@ async fn page_training_notes( Some(info) => info, None => return Ok(Redirect::to("/").into_response()), }; + // let all_training_records = vatusa::get_training_records(user_info.cid, &state.config.vatsim.vatusa_api_key) let all_training_records = - vatusa::get_training_records(user_info.cid, &state.config.vatsim.vatusa_api_key) + vatusa::get_training_records(1640903, &state.config.vatsim.vatusa_api_key) .await .map_err(|e| { AppError::GenericFallback("getting VATUSA training records by controller", e) @@ -56,9 +60,17 @@ async fn page_training_notes( .unwrap_or_else(|_| NaiveDateTime::default()); date_b.cmp(&date_a) // sort newest first }); + let instructor_cids: Vec = training_records + .iter() + .map(|record| record.instructor_id) + .collect::>() + .iter() + .copied() + .collect(); + let instructors = get_multiple_controller_names(&instructor_cids).await; let template = state.templates.get_template("user/training_notes.jinja")?; - let rendered = template.render(context! { user_info, training_records })?; + let rendered = template.render(context! { user_info, training_records, instructors })?; Ok(Html(rendered).into_response()) } diff --git a/vzdv-site/templates/changelog.jinja b/vzdv-site/templates/changelog.jinja index 8a05913..b8fdcc6 100644 --- a/vzdv-site/templates/changelog.jinja +++ b/vzdv-site/templates/changelog.jinja @@ -21,6 +21,7 @@
  • Styling improvements for modals on mobile
  • Improvements for Discord no-show notifications
  • +
  • Showing more info on user's own training notes page
diff --git a/vzdv-site/templates/user/training_notes.jinja b/vzdv-site/templates/user/training_notes.jinja index 73fe289..273c8d9 100644 --- a/vzdv-site/templates/user/training_notes.jinja +++ b/vzdv-site/templates/user/training_notes.jinja @@ -18,7 +18,7 @@ aria-expanded="false" aria-controls="record-{{ record.id }}" > - #{{ record.id }} on {{ record.position }} + #{{ record.id }} on {{ record.position }} on {{ record.session_date }} for {{ record.duration }} with {{ instructors[record.instructor_id] }}