From 6a8dd1054ccc1f7a90db2f84a582a2738eb79e0a Mon Sep 17 00:00:00 2001 From: Mariano Riefolo Date: Wed, 4 Sep 2024 15:46:54 +0200 Subject: [PATCH] fix(api): fix api to handle documents with more generic format --- src/api/mod.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/api/mod.rs b/src/api/mod.rs index a2a2956..facac97 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -202,6 +202,8 @@ pub fn get_header(record: &StringRecord) -> Header { .position(|x| !x.is_empty()) .unwrap_or(record.len()); + let field = field.replace("ì", "i").replace(" ", "").to_uppercase(); + if field == "DOCENTE" { docente = i as u8; } else if field == "LUNEDI" { @@ -250,12 +252,7 @@ pub async fn get_teachers(Query(params): Query) -> impl IntoRe for record in rdr.records() { let record = match record { Ok(x) => x, - Err(_) => { - return ( - StatusCode::UNPROCESSABLE_ENTITY, - Json(json!({ "errore": "Formato non supportato"})), - ) - } + Err(_) => continue, }; if let Some(teacher) = record.get(header.teacher as usize) { @@ -304,7 +301,10 @@ pub async fn get_classes(Query(params): Query) -> impl IntoResp let mut classes: Vec>> = vec![HashMap::new(); 5]; for record in rdr.records() { - let record = record.unwrap(); + let record = match record { + Ok(x) => x, + Err(_) => continue, + }; for (i, cell) in record.iter().enumerate() { for (_, range) in header.weekdays.clone() { if range.contains(&i) && is_valid_class(cell) {