Added support for groups and hours

This commit is contained in:
xeovalyte 2024-07-26 13:17:58 +02:00
parent feeb0facfc
commit b36fb6af89
Signed by: xeovalyte
SSH Key Fingerprint: SHA256:kSQDrQDmKzljJzfGYcd3m9RqHi4h8rSwkZ3sQ9kBURo
2 changed files with 31 additions and 32 deletions

View File

@ -1,7 +1,6 @@
#[cfg(feature = "server")] #[cfg(feature = "server")]
use crate::util::surrealdb::DB; use crate::util::surrealdb::DB;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::BTreeSet;
#[cfg(feature = "server")] #[cfg(feature = "server")]
mod migration; mod migration;
@ -10,10 +9,10 @@ mod migration;
pub struct Member { pub struct Member {
pub id: String, pub id: String,
pub name: Name, pub name: Name,
// pub hours: BTreeSet<String>, pub hours: Vec<String>,
// pub groups: BTreeSet<String>, pub groups: Vec<String>,
// pub diploma: Option<String>, pub diploma: Option<String>,
// pub registration_token: Option<String>, pub registration_token: Option<String>,
} }
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)] #[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]

View File

@ -64,16 +64,16 @@ impl Row {
first: self.first_name.clone(), first: self.first_name.clone(),
full: self.generate_full_name(), full: self.generate_full_name(),
}, },
// hours: self.generate_hours(), hours: self.generate_hours(),
// groups: BTreeSet::new(), groups: Vec::new(),
// diploma: self.diploma.clone(), diploma: self.diploma.clone(),
// registration_token: None, registration_token: None,
} }
} }
// Get the hour data from the raw string // Get the hour data from the raw string
fn generate_hours(&self) -> BTreeSet<String> { fn generate_hours(&self) -> Vec<String> {
let mut hours: BTreeSet<String> = BTreeSet::new(); let mut hours: Vec<String> = Vec::new();
let group_parts: Vec<&str> = self.hours.split(", ").collect(); let group_parts: Vec<&str> = self.hours.split(", ").collect();
@ -82,7 +82,7 @@ impl Row {
for part in hour_parts { for part in hour_parts {
if &*part != "Groep" { if &*part != "Groep" {
hours.insert(part.to_string()); hours.push(part.to_string());
} }
} }
} }
@ -164,10 +164,10 @@ fn combine_members_lists(
updated_members.push(Member { updated_members.push(Member {
id: current_member.id, id: current_member.id,
name: new_member_clone.name, name: new_member_clone.name,
// hours: new_member_clone.hours, hours: new_member_clone.hours,
// groups: current_member.groups, groups: current_member.groups,
// diploma: new_member_clone.diploma, diploma: new_member_clone.diploma,
// registration_token: current_member.diploma, registration_token: current_member.diploma,
}) })
} else { } else {
// Remove member // Remove member
@ -221,8 +221,8 @@ impl Member {
// TODO add hours and diploma support // TODO add hours and diploma support
query = query query = query
+ format!( + format!(
"UPDATE member:{} SET name.first = \"{}\", name.full = \"{}\";", "UPDATE member:{} SET name.first = \"{}\", name.full = \"{}\", hours = {:?}, groups = {:?};",
member.id, member.name.first, member.name.full member.id, member.name.first, member.name.full, member.hours, member.groups
) )
.as_str(); .as_str();
} }
@ -231,8 +231,8 @@ impl Member {
// TODO add hours and diploma support // TODO add hours and diploma support
query = query query = query
+ format!( + format!(
"CREATE member:{} SET name.first = \"{}\", name.full = \"{}\";", "CREATE member:{} SET name.first = \"{}\", name.full = \"{}\", hours = {:?}, groups = {:?};",
member.id, member.name.first, member.name.full member.id, member.name.first, member.name.full, member.hours, member.groups
) )
.as_str(); .as_str();
} }
@ -267,14 +267,14 @@ mod tests {
first: "First".to_string(), first: "First".to_string(),
full: "First Last".to_string(), full: "First Last".to_string(),
}, },
// hours: BTreeSet::from([ hours: Vec::from([
// "Wedstrijd".to_string(), "Wedstrijd".to_string(),
// "Z5".to_string(), "Z5".to_string(),
// "Zaterdag".to_string(), "Zaterdag".to_string(),
// ]), ]),
// groups: BTreeSet::new(), groups: vec![],
// diploma: Some("LS1".to_string()), diploma: Some("LS1".to_string()),
// registration_token: None, registration_token: None,
}, },
Member { Member {
id: "D000002".to_string(), id: "D000002".to_string(),
@ -282,10 +282,10 @@ mod tests {
first: "First2".to_string(), first: "First2".to_string(),
full: "First2 Last2".to_string(), full: "First2 Last2".to_string(),
}, },
// hours: BTreeSet::from(["Z5".to_string(), "Zaterdag".to_string()]), hours: Vec::from(["Z5".to_string(), "Zaterdag".to_string()]),
// groups: BTreeSet::new(), groups: Vec::new(),
// diploma: Some("ZR4".to_string()), diploma: Some("ZR4".to_string()),
// registration_token: None, registration_token: None,
}, },
]; ];