Skip to content

Commit

Permalink
fix: insert class with multiple lecturers
Browse files Browse the repository at this point in the history
  • Loading branch information
albugowy15 committed Feb 9, 2024
1 parent e1ce815 commit e5820c8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "auto-frs-schedule"
version = "2.6.0"
version = "2.6.1"
edition = "2021"
description = "Automatically generate TC FRS schedule from Excel file"
authors = ["Mohamad Kholid Bughowi <[email protected]>"]
Expand Down
8 changes: 7 additions & 1 deletion src/commands/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ pub async fn compare_handler(file: &PathBuf, sheet: &str, outdir: &PathBuf) {
let key = (class.subject_name.clone(), class.class_code.clone());
if let Some(val) = db_classes_res.get(&key) {
if !val.eq(&class) {
changed.push((val.clone(), class.clone()));
let mut db_lec_codes = val.lecturer_code.clone();
db_lec_codes.sort();
let mut excel_lec_codes = class.lecturer_code.clone();
excel_lec_codes.sort();
if !db_lec_codes.eq(&excel_lec_codes) {
changed.push((val.clone(), class.clone()));
}
}
db_classes_res.remove(&key).unwrap();
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/db/repository/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Class {
pub session_id: i8,
}

#[derive(PartialEq, Clone)]
#[derive(PartialEq, Clone, Debug)]
pub struct ClassFromSchedule {
pub subject_name: String,
pub class_code: String,
Expand Down Expand Up @@ -86,7 +86,7 @@ impl ClassRepository<'_> {
}

#[allow(deprecated)]
pub async fn insert_classes(&self, data: &Vec<Class>) -> Result<()> {
pub async fn insert_classes(&self, data: &[Class]) -> Result<()> {
let mut tx = self.db_pool.begin().await?;
Self::drop_old_classes(&mut tx)
.await
Expand Down
5 changes: 3 additions & 2 deletions src/utils/excel/schedule_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ impl ScheduleParser<ClassFromSchedule> for Excel {
Some(val) => val,
None => continue,
};
list_class.push(ClassFromSchedule {
let data = ClassFromSchedule {
subject_name,
class_code,
lecturer_code: lecturers,
day: day.to_string(),
session_start,
})
};
list_class.push(data);
}
}
list_class
Expand Down
19 changes: 12 additions & 7 deletions src/utils/excel/schedule_parser_with_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ impl AsIdParser for Excel {
fn get_lecturer_id(&self, row: u32, col: u32) -> Option<Vec<String>> {
let lecturers_str = self.retrieve_class_detail(row, col)?;
let lecturers = Excel::parse_lecturer(&lecturers_str)?;
let unk_id = self
.lecturer_subjects_session_map
.lecturers
.get(&String::from("UNK"))?
.to_string();
let lecturers_id: Vec<String> = lecturers
.into_iter()
.map(|lecture_code| {
.map(|lecturer_code| {
self.lecturer_subjects_session_map
.lecturers
.get(lecture_code.trim())
.unwrap_or(&"UNK".to_string())
.get(lecturer_code.trim())
.unwrap_or(&unk_id)
.to_string()
})
.collect();

lecturers_id.into_iter().next().map(|first| vec![first])
Some(lecturers_id)
}
}

Expand Down Expand Up @@ -64,13 +68,14 @@ impl ScheduleParser<Class> for Excel {
Some(val) => val,
None => continue,
};
list_class.push(Class {
let data = Class {
matkul_id: subject_id,
lecturers_id,
day: day.to_string(),
code: class_code,
session_id,
});
};
list_class.push(data);
}
}
list_class
Expand Down

0 comments on commit e5820c8

Please sign in to comment.