Added diploma support

This commit is contained in:
xeovalyte 2024-10-09 12:14:56 +02:00
parent 1aa7a0565d
commit 570edc1b44
Signed by: xeovalyte
SSH Key Fingerprint: SHA256:kSQDrQDmKzljJzfGYcd3m9RqHi4h8rSwkZ3sQ9kBURo
7 changed files with 64 additions and 66 deletions

View File

@ -3019,8 +3019,8 @@ details.collapse summary::-webkit-details-marker {
max-width: 42rem; max-width: 42rem;
} }
.max-w-4xl { .max-w-3xl {
max-width: 56rem; max-width: 48rem;
} }
.max-w-lg { .max-w-lg {

View File

@ -9,9 +9,7 @@ pub fn Members() -> Element {
rsx! { rsx! {
div { div {
class: "flex justify-center", class: "max-w-3xl w-full",
div {
class: "max-w-4xl w-full",
h2 { class: "font-bold text-lg", "Leden" }, h2 { class: "font-bold text-lg", "Leden" },
match &*members.read_unchecked() { match &*members.read_unchecked() {
Some(Ok(res)) => rsx! { Some(Ok(res)) => rsx! {
@ -40,7 +38,6 @@ pub fn Members() -> Element {
} }
} }
} }
}
#[derive(Props, Clone, PartialEq)] #[derive(Props, Clone, PartialEq)]
struct MemberRowProps { struct MemberRowProps {

View File

@ -7,9 +7,7 @@ pub fn Users() -> Element {
rsx! { rsx! {
div { div {
class: "flex justify-center", class: "max-w-3xl w-full",
div {
class: "max-w-4xl w-full",
h2 { class: "font-bold text-lg", "Gebruikers" }, h2 { class: "font-bold text-lg", "Gebruikers" },
match &*users.read_unchecked() { match &*users.read_unchecked() {
Some(Ok(res)) => rsx! { Some(Ok(res)) => rsx! {
@ -37,7 +35,6 @@ pub fn Users() -> Element {
} }
} }
} }
}
#[derive(Props, Clone, PartialEq)] #[derive(Props, Clone, PartialEq)]
struct UserRowProps { struct UserRowProps {

View File

@ -251,9 +251,11 @@ fn Members() -> Element {
} }
div { div {
class: "", class: "",
span { "LS2" }, if let Some(d) = member.diploma {
span { "{d}" }
span { class: "mx-1.5", "" } span { class: "mx-1.5", "" }
span { "A1, B2" } }
span { {member.hours.join(", ")} }
} }
}, },
div { div {
@ -308,7 +310,7 @@ fn Members() -> Element {
async fn fetch_members() -> Result<Vec<Member>, ServerFnError> { async fn fetch_members() -> Result<Vec<Member>, ServerFnError> {
let user = Session::fetch_current_user().await?; let user = Session::fetch_current_user().await?;
let members = Member::fetch_from_user(user.id).await?; let members = Member::fetch_from_user(&user.id).await?;
Ok(members) Ok(members)
} }

View File

@ -1,6 +1,8 @@
#[cfg(feature = "server")] #[cfg(feature = "server")]
use crate::util::surrealdb::{thing_to_string, DB}; use crate::util::surrealdb::{thing_to_string, DB};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "server")]
use surrealdb::sql::Thing;
#[cfg(feature = "server")] #[cfg(feature = "server")]
mod migration; mod migration;
@ -57,12 +59,10 @@ impl Member {
} }
} }
pub async fn fetch_from_user(user_id: String) -> Result<Vec<Self>, crate::Error> { pub async fn fetch_from_user(user_id: &str) -> Result<Vec<Self>, crate::Error> {
let mut res = DB let mut res = DB
.query( .query("SELECT VALUE ->user_to_member->member.* FROM ONLY $user")
"SELECT VALUE ->user_to_member->member.* FROM ONLY type::thing('user', $user_id)", .bind(("user", Thing::from(("user", user_id))))
)
.bind(("user_id", user_id))
.await?; .await?;
res = res.check()?; res = res.check()?;

View File

@ -202,7 +202,7 @@ impl MembersMigration {
} }
pub async fn migrate(id: u16) -> Result<(), Box<dyn std::error::Error>> { pub async fn migrate(id: u16) -> Result<(), Box<dyn std::error::Error>> {
let members_store = MEMBERS_STORE.lock().await; let mut members_store = MEMBERS_STORE.lock().await;
let members_migration = match members_store.get(&id) { let members_migration = match members_store.get(&id) {
Some(mm) => mm, Some(mm) => mm,
@ -212,31 +212,30 @@ impl MembersMigration {
let mut transaction = DB.query(BeginStatement::default()); let mut transaction = DB.query(BeginStatement::default());
for member in members_migration.updated.clone() { for member in members_migration.updated.clone() {
// TODO add hours and diploma support
let id = member.id.clone(); let id = member.id.clone();
transaction = transaction.query(format!("UPDATE type::thing('member', $id_{id}) SET name.first = $name_first_{id}, name.full = $name_full_{id}, hours = $hours_{id}, groups = $groups_{id};")) transaction = transaction.query(format!("UPDATE type::thing('member', $id_{id}) SET name.first = $name_first_{id}, name.full = $name_full_{id}, hours = $hours_{id}, groups = $groups_{id}, diploma = $diploma_{id};"))
.bind((format!("id_{id}"), member.id)) .bind((format!("id_{id}"), member.id))
.bind((format!("name_first_{id}"), member.name.first)) .bind((format!("name_first_{id}"), member.name.first))
.bind((format!("name_full_{id}"), member.name.full)) .bind((format!("name_full_{id}"), member.name.full))
.bind((format!("hours_{id}"), member.hours)) .bind((format!("hours_{id}"), member.hours))
.bind((format!("groups_{id}"), member.groups)); .bind((format!("groups_{id}"), member.groups))
.bind((format!("diploma_{id}"), member.diploma));
} }
for member in members_migration.inserted.clone() { for member in members_migration.inserted.clone() {
// TODO add hours and diploma support
let id = member.id.clone(); let id = member.id.clone();
transaction = transaction.query(format!("CREATE type::thing('member', $id_{id}) SET name.first = $name_first_{id}, name.full = $name_full_{id}, hours = $hours_{id}, groups = $groups_{id};")) transaction = transaction.query(format!("CREATE type::thing('member', $id_{id}) SET name.first = $name_first_{id}, name.full = $name_full_{id}, hours = $hours_{id}, groups = $groups_{id}, diploma = $diploma_{id};"))
.bind((format!("id_{id}"), member.id)) .bind((format!("id_{id}"), member.id))
.bind((format!("name_first_{id}"), member.name.first)) .bind((format!("name_first_{id}"), member.name.first))
.bind((format!("name_full_{id}"), member.name.full)) .bind((format!("name_full_{id}"), member.name.full))
.bind((format!("hours_{id}"), member.hours)) .bind((format!("hours_{id}"), member.hours))
.bind((format!("groups_{id}"), member.groups)); .bind((format!("groups_{id}"), member.groups))
.bind((format!("diploma_{id}"), member.diploma));
} }
for member in members_migration.removed.clone() { for member in members_migration.removed.clone() {
// TODO add hours and diploma support
let id = member.id.clone(); let id = member.id.clone();
transaction = transaction transaction = transaction
@ -249,6 +248,8 @@ impl MembersMigration {
.await? .await?
.check()?; .check()?;
members_store.remove(&id);
Ok(()) Ok(())
} }
} }

View File

@ -66,6 +66,7 @@ async fn apply_queries() -> surrealdb::Result<()> {
DEFINE FIELD name.full ON TABLE member TYPE string; DEFINE FIELD name.full ON TABLE member TYPE string;
DEFINE FIELD registration_token ON TABLE member TYPE string DEFINE FIELD registration_token ON TABLE member TYPE string
VALUE rand::string(16); VALUE rand::string(16);
DEFINE FIELD diploma ON TABLE member TYPE option<string>;
DEFINE FIELD hours ON TABLE member TYPE set<string>; DEFINE FIELD hours ON TABLE member TYPE set<string>;
DEFINE FIELD groups ON TABLE member TYPE set<string>; DEFINE FIELD groups ON TABLE member TYPE set<string>;
", ",