Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config.prod.json
Comment thread
AnnaFYZ marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"github_org": "CodeYourFuture",
"github_client_id": "Ov23liyZuouqyi9L3ZpM",
"github_client_id": "Ov23cturUbMnqQZ535bF",
"github_client_secret": "$CYF_TRAINEE_TRACKER_GITHUB_CLIENT_SECRET",
"addr": "0.0.0.0",
"port": 3000,
"public_base_url": "https://trainee-tracker.hosting.codeyourfuture.io",
"google_apis_client_id": "403459539948-q1psg497mlfk9u6cgf0eea5qum4gp92n.apps.googleusercontent.com",
"public_base_url": "http://localhost:3000",
"google_apis_client_id": "403459539948-0af4rtk7po28idm3eiv0jj7qcq6u8vvs.apps.googleusercontent.com",
"google_apis_client_secret": "$CYF_TRAINEE_TRACKER_GOOGLE_APIS_CLIENT_SECRET",
"github_email_mapping_sheet_id": "1ahDEnO8odD9oLtO_EBcvcmEaF0qsX-I4iLCIY0XLjt0",
"reviewer_staff_info_sheet_id": "1CKDrXtx5lkgfZ8E2mjvsDup2K8UyBsq99CIV0qOxrP0",
Expand Down
4 changes: 4 additions & 0 deletions src/bin/trainee-tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ async fn main() {
"/groups/slack.csv",
get(trainee_tracker::frontend::list_slack_groups_csv),
)
.route(
"/api/attendance",
get(trainee_tracker::endpoints::fecth_attendance),
)
.layer(session_layer)
.with_state(server_state);

Expand Down
61 changes: 61 additions & 0 deletions src/endpoints.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::BTreeMap;

use ::octocrab::models::{teams::RequestedTeam, Author};
use anyhow::Context;
use axum::{
Expand All @@ -15,6 +17,7 @@ use crate::{
newtypes::GithubLogin,
octocrab::{all_pages, octocrab},
prs::{fill_in_reviewers, get_prs, PrWithReviews},
register::{get_register, Attendance},
sheets::sheets_client,
Error, ServerState,
};
Expand Down Expand Up @@ -207,3 +210,61 @@ pub async fn get_region(
.map(|trainee| trainee.region.clone()),
}))
}

type SprintAttendance = BTreeMap<String, Vec<Attendance>>;
type ModuleAttendance = BTreeMap<String, SprintAttendance>;
type BatchAttendance = BTreeMap<String, ModuleAttendance>;
type CourseAttendance = BTreeMap<String, BatchAttendance>;

#[derive(Serialize)]
pub struct AttendanceResponse {
courses: CourseAttendance,
}

pub async fn fecth_attendance(
Comment thread
AnnaFYZ marked this conversation as resolved.
Outdated
session: Session,
State(server_state): State<ServerState>,
OriginalUri(original_uri): OriginalUri,
) -> Result<Json<AttendanceResponse>, Error> {
let all_courses = &server_state.config.courses;
let sheets_client = sheets_client(&session, server_state.clone(), original_uri.clone()).await?;
let github_org = &server_state.config.github_org;
let octocrab = octocrab(&session, &server_state, original_uri).await?;
let mut courses: CourseAttendance = BTreeMap::new();
for (course_name, course_info) in all_courses {
let mut course_batches: BatchAttendance = BTreeMap::new();
for batch_name in course_info.batches.keys() {
let course_schedule = server_state
.config
.get_course_schedule_with_register_sheet_id(course_name.clone(), batch_name)
.ok_or_else(|| Error::Fatal(anyhow::anyhow!("Course not found: {course_name}")))?;
let mut modules: ModuleAttendance = BTreeMap::new();
let course = course_schedule
.with_assignments(&octocrab, github_org)
.await?;
Comment thread
AnnaFYZ marked this conversation as resolved.
Outdated
let register_info = get_register(
sheets_client.clone(),
course.register_sheet_id.clone(),
course.start_date,
course.end_date,
)
.await?;
Comment thread
AnnaFYZ marked this conversation as resolved.
Outdated

for (module_name, sprint_info) in register_info.modules {
let mut sprints: SprintAttendance = BTreeMap::new();
for (sprint_number, sprint_info) in sprint_info.attendance.into_iter().enumerate() {
let mut entries: Vec<Attendance> = Vec::new();
for entry in sprint_info.into_values() {
entries.push(entry);
}
sprints.insert(format!("Sprint-{}", sprint_number + 1), entries);
}
Comment thread
AnnaFYZ marked this conversation as resolved.
Outdated
modules.insert(module_name.clone(), sprints);
}
course_batches.insert(batch_name.clone(), modules);
}
courses.insert(course_name.clone(), course_batches);
}

Ok(Json(AttendanceResponse { courses }))
}
3 changes: 2 additions & 1 deletion src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use anyhow::Context;
use chrono::{DateTime, NaiveDate, Utc};
use email_address::EmailAddress;
use indexmap::IndexMap;
use serde::Serialize;
use sheets::types::{CellData, GridData};
use tracing::warn;

Expand All @@ -24,7 +25,7 @@ pub struct ModuleAttendance {
pub attendance: Vec<IndexMap<EmailAddress, Attendance>>,
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize)]
pub struct Attendance {
pub name: String,
pub email: EmailAddress,
Expand Down