Migrated to bitflags

This commit is contained in:
2025-02-07 14:24:21 +01:00
parent cf379a1288
commit 07493b83a5
12 changed files with 177 additions and 64 deletions

View File

@@ -1,17 +1,91 @@
#[derive(Debug, Clone, serde::Serialize)]
use bitflags::bitflags;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize)]
pub struct Name {
pub first: String,
pub full: String,
}
#[derive(Debug, Clone, serde::Serialize)]
#[derive(Debug, Clone, Serialize)]
pub struct Member {
pub id: String,
pub name: Name,
pub registration_token: Option<String>,
pub diploma: Option<String>,
pub hours: Vec<String>,
pub groups: Vec<String>,
pub swim_groups: SwimGroups,
pub groups: Groups,
}
bitflags! {
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub struct Groups: u64 {
const NONE = 1 << 0;
const KADER = 1 << 1;
const ZWEMZAKEN = 1 << 2;
const WEDSTRIJDEN = 1 << 3;
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub struct SwimGroups: u64 {
const NONE = 1 << 0;
const A1 = 1 << 1;
const A2 = 1 << 2;
const A3 = 1 << 3;
const A4 = 1 << 4;
const A5 = 1 << 5;
const A6 = 1 << 6;
const B1 = 1 << 7;
const B2 = 1 << 8;
const B3 = 1 << 9;
const B4 = 1 << 10;
const B5 = 1 << 11;
const B6 = 1 << 12;
const C1 = 1 << 13;
const C2 = 1 << 14;
const C3 = 1 << 15;
const C4 = 1 << 16;
const C5 = 1 << 17;
const C6 = 1 << 18;
const D1 = 1 << 19;
const D2 = 1 << 20;
const D3 = 1 << 21;
const D4 = 1 << 22;
const D5 = 1 << 23;
const D6 = 1 << 24;
const E1 = 1 << 25;
const E2 = 1 << 26;
const E3 = 1 << 27;
const E4 = 1 << 28;
const E5 = 1 << 29;
const E6 = 1 << 30;
const Z1 = 1 << 31;
const Z2 = 1 << 32;
const Z3 = 1 << 33;
const Z4 = 1 << 34;
const Z5 = 1 << 35;
const Z6 = 1 << 36;
const WEDSTRIJD = 1 << 37;
}
}
impl From<i64> for SwimGroups {
fn from(value: i64) -> Self {
Self::from_bits(value as u64).unwrap_or(SwimGroups::NONE)
}
}
impl From<i64> for Groups {
fn from(value: i64) -> Self {
Self::from_bits(value as u64).unwrap_or(Groups::NONE)
}
}
use crate::database::model::Member as DbMember;
@@ -25,7 +99,7 @@ impl From<DbMember> for Member {
},
registration_token: value.registration_token,
diploma: value.diploma,
hours: value.hours,
swim_groups: value.swim_groups,
groups: value.groups,
}
}
@@ -39,7 +113,7 @@ impl From<Member> for DbMember {
full_name: value.name.full,
registration_token: None,
diploma: value.diploma,
hours: value.hours,
swim_groups: value.swim_groups,
groups: value.groups,
}
}