From 808525dee5bb266781a74157663513ab59a2db0c Mon Sep 17 00:00:00 2001 From: Philipp Hofer Date: Tue, 8 Apr 2025 18:35:59 +0200 Subject: [PATCH] rename 'group' to 'team' --- README.md | 12 +- migration.sql | 10 +- src/lib.rs | 16 +-- src/route/mod.rs | 12 +- src/route/web.rs | 26 ++-- src/station/web.rs | 8 +- src/{group => team}/mod.rs | 43 +++---- src/{group => team}/web.rs | 242 ++++++++++++++++++------------------- 8 files changed, 184 insertions(+), 185 deletions(-) rename src/{group => team}/mod.rs (77%) rename src/{group => team}/web.rs (61%) diff --git a/README.md b/README.md index 3a2eb6e..5cfc511 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,13 @@ - [x] Station - [x] Route - [x] Route_station -- [ ] Group +- [x] Team +- [ ] Station view (rate team) +- [ ] ## Fancy features -- see when a group starts going to your direction -- QR codes for groups, stations can then scan it? -- View all groups: where have they last made contact with *any* station? -- View single group: which stations are they still missing? +- see when a team starts going to your direction +- QR codes for teams, stations can then scan it? +- View all teams: where have they last made contact with *any* station? +- View single teams: which stations are they still missing? - Rangliste diff --git a/migration.sql b/migration.sql index 965afa4..91e7259 100644 --- a/migration.sql +++ b/migration.sql @@ -23,7 +23,7 @@ CREATE TABLE route_station ( FOREIGN KEY (station_id) REFERENCES station(id) ); -CREATE TABLE "group" ( +CREATE TABLE team ( id INTEGER PRIMARY KEY, name TEXT NOT NULL UNIQUE, notes TEXT, @@ -34,16 +34,16 @@ CREATE TABLE "group" ( FOREIGN KEY (route_id) REFERENCES route(id) ); -CREATE TABLE group_station ( - group_id INTEGER, +CREATE TABLE rating ( + team_id INTEGER, station_id INTEGER, points INTEGER, notes TEXT, arrived_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, started_at DATETIME, left_at DATETIME, - PRIMARY KEY (group_id, station_id), - FOREIGN KEY (group_id) REFERENCES "group"(id), + PRIMARY KEY (team_id, station_id), + FOREIGN KEY (team_id) REFERENCES team(id), FOREIGN KEY (station_id) REFERENCES station(id) ); diff --git a/src/lib.rs b/src/lib.rs index 5b36b78..9a4ec54 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,21 +1,21 @@ -use axum::{Router, body::Body, response::Response, routing::get}; -use maud::{Markup, html}; +use axum::{body::Body, response::Response, routing::get, Router}; +use maud::{html, Markup}; use partials::page; use sqlx::SqlitePool; use std::sync::Arc; use tokio::net::TcpListener; use tower_sessions::{MemoryStore, Session, SessionManagerLayer}; -pub(crate) mod group; mod partials; pub(crate) mod route; pub(crate) mod station; +pub(crate) mod team; -pub(crate) fn pl(amount: usize, single: &str) -> String { +pub(crate) fn pl(amount: usize, single: &str, append: &str) -> String { if amount == 1 { single.into() } else { - format!("{single}n") + format!("{single}{append}") } } @@ -101,8 +101,8 @@ async fn index(session: Session) -> Markup { } } li { - a role="button" href="/group" { - "Gruppen" + a role="button" href="/team" { + "Teams" } } } @@ -120,7 +120,7 @@ pub async fn start(listener: TcpListener, db: SqlitePool) { .route("/", get(index)) .nest("/station", station::routes()) .nest("/route", route::routes()) - .nest("/group", group::routes()) + .nest("/team", team::routes()) .route("/pico.css", get(serve_pico_css)) .route("/style.css", get(serve_my_css)) .route("/leaflet.css", get(serve_leaflet_css)) diff --git a/src/route/mod.rs b/src/route/mod.rs index 63eb900..a8b469c 100644 --- a/src/route/mod.rs +++ b/src/route/mod.rs @@ -1,4 +1,4 @@ -use crate::{group::Group, station::Station}; +use crate::{station::Station, team::Team}; use axum::Router; use serde::{Deserialize, Serialize}; use sqlx::{FromRow, Row, SqlitePool}; @@ -161,8 +161,8 @@ DROP TABLE temp_pos;", .unwrap() } - pub(crate) async fn groups(&self, db: &SqlitePool) -> Vec { - Group::all_with_route(db, self).await + pub(crate) async fn teams(&self, db: &SqlitePool) -> Vec { + Team::all_with_route(db, self).await } pub(crate) async fn get_next_first_station(&self, db: &SqlitePool) -> Option { @@ -170,13 +170,13 @@ DROP TABLE temp_pos;", " SELECT s.id AS next_first_station_id, - COUNT(g.id) AS group_count + COUNT(g.id) AS team_count FROM station s JOIN route_station rs ON s.id = rs.station_id - LEFT JOIN 'group' g ON s.id = g.first_station_id + LEFT JOIN 'team' g ON s.id = g.first_station_id WHERE rs.route_id = {} GROUP BY s.id - ORDER BY group_count ASC, s.id ASC + ORDER BY team_count ASC, s.id ASC LIMIT 1", self.id )) diff --git a/src/route/web.rs b/src/route/web.rs index f18308f..092ca7a 100644 --- a/src/route/web.rs +++ b/src/route/web.rs @@ -1,12 +1,12 @@ use super::Route; use crate::{err, page, station::Station, succ}; use axum::{ - Form, Router, extract::State, response::{IntoResponse, Redirect}, routing::{get, post}, + Form, Router, }; -use maud::{Markup, PreEscaped, html}; +use maud::{html, Markup, PreEscaped}; use serde::Deserialize; use sqlx::SqlitePool; use std::sync::Arc; @@ -25,7 +25,7 @@ async fn index(State(db): State>, session: Session) -> Markup { "definieren welche " a href="/station" { "Stationen" } " von den " - a href="/group" { "Gruppen" } + a href="/team" { "Teams" } " in welcher Reihenfolge abgeklappert werden sollen. Wenn es verschiedene Kategorien (zB Kinder- und Erwachsenenwertung) gibt, kannst du auch mehrere Routen mit (teils) überlappenden Stationen erstellen." } ol { @@ -53,7 +53,7 @@ async fn index(State(db): State>, session: Session) -> Markup { } h2 { "Neue Route" } form action="/route" method="post" { - fieldset role="group" { + fieldset role="team" { input type="text" name="name" placeholder="Routenname" required; input type="submit" value="Neue Route"; } @@ -127,7 +127,7 @@ async fn view( let cur_stations = route.stations(&db).await; let stations_not_in_route = route.stations_not_in_route(&db).await; - let groups = route.groups(&db).await; + let teams = route.teams(&db).await; let content = html! { h1 { @@ -189,21 +189,21 @@ async fn view( } } } - h2 { "Gruppen mit dieser Route" } - @if groups.is_empty() { + h2 { "Teams mit dieser Route" } + @if teams.is_empty() { article { - "Noch keine Gruppe ist dieser Route zugeteilt." - a role="button" href="/group" { - "Zu den Gruppen" + "Noch keine Team ist dieser Route zugeteilt." + a role="button" href="/team" { + "Zu den Teams" } } } @else { ol { - @for group in &groups { + @for team in &teams { li { - a href=(format!("/group/{}", group.id)) { - (group.name) + a href=(format!("/team/{}", team.id)) { + (team.name) } } } diff --git a/src/station/web.rs b/src/station/web.rs index 818278f..255b952 100644 --- a/src/station/web.rs +++ b/src/station/web.rs @@ -1,11 +1,11 @@ use crate::{err, partials::page, station::Station, succ}; use axum::{ - Form, Router, extract::State, response::{IntoResponse, Redirect}, routing::{get, post}, + Form, Router, }; -use maud::{Markup, html}; +use maud::{html, Markup}; use serde::Deserialize; use sqlx::SqlitePool; use std::sync::Arc; @@ -120,7 +120,7 @@ async fn view( td { (station.pw) article class="warning" { - (format!("Diesen Code nur Betreuern der Station {} geben! Mit diesem Code erhält man die Berechtigung, Gruppen zu bewerten.", station.name)) + (format!("Diesen Code nur Betreuern der Station {} geben! Mit diesem Code erhält man die Berechtigung, Teams zu bewerten.", station.name)) } } } @@ -444,7 +444,7 @@ async fn index(State(db): State>, session: Session) -> Markup { } h2 { "Neue Station" } form action="/station" method="post" { - fieldset role="group" { + fieldset role="team" { input type="text" name="name" placeholder="Stationsname" required; input type="submit" value="Neue Station"; } diff --git a/src/group/mod.rs b/src/team/mod.rs similarity index 77% rename from src/group/mod.rs rename to src/team/mod.rs index c230fc4..767bce0 100644 --- a/src/group/mod.rs +++ b/src/team/mod.rs @@ -7,7 +7,7 @@ use std::sync::Arc; mod web; #[derive(FromRow, Debug, Serialize, Deserialize)] -pub(crate) struct Group { +pub(crate) struct Team { pub(crate) id: i64, pub(crate) name: String, notes: Option, @@ -21,10 +21,10 @@ enum CreateError { DuplicateName(String), } -impl Group { +impl Team { pub(crate) async fn all(db: &SqlitePool) -> Vec { sqlx::query_as::<_, Self>( - "SELECT id, name, notes, amount_people, first_station_id, route_id FROM 'group';", + "SELECT id, name, notes, amount_people, first_station_id, route_id FROM team;", ) .fetch_all(db) .await @@ -33,8 +33,8 @@ impl Group { pub(crate) async fn all_with_route(db: &SqlitePool, route: &Route) -> Vec { sqlx::query_as!( - Group, - "select id, name, notes, amount_people, first_station_id, route_id from 'group' where route_id = ?;", + Team, + "select id, name, notes, amount_people, first_station_id, route_id from team where route_id = ?;", route.id ) .fetch_all(db) @@ -44,8 +44,8 @@ impl Group { pub(crate) async fn all_with_first_station(db: &SqlitePool, station: &Station) -> Vec { sqlx::query_as!( - Group, - "select id, name, notes, amount_people, first_station_id, route_id from 'group' where first_station_id = ?;", + Team, + "select id, name, notes, amount_people, first_station_id, route_id from team where first_station_id = ?;", station.id ) .fetch_all(db) @@ -56,7 +56,7 @@ impl Group { pub async fn find_by_id(db: &SqlitePool, id: i64) -> Option { sqlx::query_as!( Self, - "SELECT id, name, notes, amount_people, first_station_id, route_id FROM 'group' WHERE id = ?", + "SELECT id, name, notes, amount_people, first_station_id, route_id FROM team WHERE id = ?", id ) .fetch_one(db) @@ -65,14 +65,14 @@ impl Group { } async fn create(db: &SqlitePool, name: &str, route: &Route) -> Result<(), CreateError> { - // get next station id which has the lowest amount of groups to have in the first place + // get next station id which has the lowest amount of teams to have in the first place // assigned let Some(station) = route.get_next_first_station(db).await else { return Err(CreateError::NoStationForRoute); }; sqlx::query!( - "INSERT INTO 'group'(name, route_id, first_station_id) VALUES (?, ?, ?)", + "INSERT INTO team(name, route_id, first_station_id) VALUES (?, ?, ?)", name, route.id, station.id @@ -84,14 +84,14 @@ impl Group { } async fn update_name(&self, db: &SqlitePool, name: &str) { - sqlx::query!("UPDATE 'group' SET name = ? WHERE id = ?", name, self.id) + sqlx::query!("UPDATE team SET name = ? WHERE id = ?", name, self.id) .execute(db) .await .unwrap(); } async fn update_notes(&self, db: &SqlitePool, notes: &str) { - sqlx::query!("UPDATE 'group' SET notes = ? WHERE id = ?", notes, self.id) + sqlx::query!("UPDATE team SET notes = ? WHERE id = ?", notes, self.id) .execute(db) .await .unwrap(); @@ -99,7 +99,7 @@ impl Group { async fn update_amount_people(&self, db: &SqlitePool, amount_people: i64) { sqlx::query!( - "UPDATE 'group' SET amount_people = ? WHERE id = ?", + "UPDATE team SET amount_people = ? WHERE id = ?", amount_people, self.id ) @@ -114,7 +114,7 @@ impl Group { }; sqlx::query!( - "UPDATE 'group' SET route_id = ?, first_station_id = ? WHERE id = ?", + "UPDATE team SET route_id = ?, first_station_id = ? WHERE id = ?", route.id, station.id, self.id @@ -128,7 +128,7 @@ impl Group { async fn update_first_station(&self, db: &SqlitePool, station: &Station) { sqlx::query!( - "UPDATE 'group' SET first_station_id = ? WHERE id = ?", + "UPDATE team SET first_station_id = ? WHERE id = ?", station.id, self.id ) @@ -138,17 +138,14 @@ impl Group { } async fn update_amount_people_reset(&self, db: &SqlitePool) { - sqlx::query!( - "UPDATE 'group' SET amount_people = NULL WHERE id = ?", - self.id - ) - .execute(db) - .await - .unwrap(); + sqlx::query!("UPDATE team SET amount_people = NULL WHERE id = ?", self.id) + .execute(db) + .await + .unwrap(); } async fn delete(&self, db: &SqlitePool) -> Result<(), String> { - sqlx::query!("DELETE FROM 'group' WHERE id = ?", self.id) + sqlx::query!("DELETE FROM team WHERE id = ?", self.id) .execute(db) .await .map_err(|e| e.to_string())?; diff --git a/src/group/web.rs b/src/team/web.rs similarity index 61% rename from src/group/web.rs rename to src/team/web.rs index 5be5775..9a19b41 100644 --- a/src/group/web.rs +++ b/src/team/web.rs @@ -1,12 +1,12 @@ -use super::{CreateError, Group}; +use super::{CreateError, Team}; use crate::{err, partials::page, pl, route::Route, station::Station, succ}; use axum::{ - Form, Router, extract::State, response::{IntoResponse, Redirect}, routing::{get, post}, + Form, Router, }; -use maud::{Markup, PreEscaped, html}; +use maud::{html, Markup, PreEscaped}; use serde::Deserialize; use sqlx::SqlitePool; use std::sync::Arc; @@ -26,30 +26,30 @@ async fn create( let Some(route) = Route::find_by_id(&db, form.route_id).await else { err!( session, - "Gruppe mit {} konnte nicht erstellt werden, da keine Route mit ID {} existiert", + "Team mit {} konnte nicht erstellt werden, da keine Route mit ID {} existiert", form.name, form.route_id ); - return Redirect::to("/group"); + return Redirect::to("/team"); }; - match Group::create(&db, &form.name, &route).await { - Ok(()) => succ!(session, "Gruppe '{}' erfolgreich erstellt!", form.name), + match Team::create(&db, &form.name, &route).await { + Ok(()) => succ!(session, "Team '{}' erfolgreich erstellt!", form.name), Err(CreateError::DuplicateName(e)) => err!( session, - "Gruppe '{}' konnte _NICHT_ erstellt werden, da es bereits eine Gruppe mit diesem Namen gibt ({e})!", + "Team '{}' konnte _NICHT_ erstellt werden, da es bereits ein Team mit diesem Namen gibt ({e})!", form.name ), Err(CreateError::NoStationForRoute) => err!( session, - "Gruppe '{}' konnte _NICHT_ erstellt werden, da in der angegebenen Route '{}' noch keine Stationen vorkommen", + "Team '{}' konnte _NICHT_ erstellt werden, da in der angegebenen Route '{}' noch keine Stationen vorkommen", form.name, route.name ), } - Redirect::to("/group") + Redirect::to("/team") } async fn delete( @@ -57,25 +57,25 @@ async fn delete( session: Session, axum::extract::Path(id): axum::extract::Path, ) -> impl IntoResponse { - let Some(group) = Group::find_by_id(&db, id).await else { + let Some(team) = Team::find_by_id(&db, id).await else { err!( session, - "Gruppe mit ID {id} konnte nicht gelöscht werden, da sie nicht existiert" + "Team mit ID {id} konnte nicht gelöscht werden, da sie nicht existiert" ); - return Redirect::to("/group"); + return Redirect::to("/team"); }; - match group.delete(&db).await { - Ok(()) => succ!(session, "Gruppe '{}' erfolgreich gelöscht!", group.name), + match team.delete(&db).await { + Ok(()) => succ!(session, "Team '{}' erfolgreich gelöscht!", team.name), Err(e) => err!( session, - "Gruppe '{}' kann nicht gelöscht werden, da sie bereits verwendet wird. ({e})", - group.name + "Team '{}' kann nicht gelöscht werden, da sie bereits verwendet wird. ({e})", + team.name ), } - Redirect::to("/group") + Redirect::to("/team") } async fn view( @@ -83,30 +83,30 @@ async fn view( session: Session, axum::extract::Path(id): axum::extract::Path, ) -> Result { - let Some(group) = Group::find_by_id(&db, id).await else { + let Some(team) = Team::find_by_id(&db, id).await else { err!( session, - "Gruppe mit ID {id} konnte nicht geöffnet werden, da sie nicht existiert" + "Team mit ID {id} konnte nicht geöffnet werden, da sie nicht existiert" ); - return Err(Redirect::to("/group")); + return Err(Redirect::to("/team")); }; - let first_station = group.first_station(&db).await; + let first_station = team.first_station(&db).await; let routes = Route::all(&db).await; - let stations = group.route(&db).await.stations(&db).await; + let stations = team.route(&db).await.stations(&db).await; - // maybe switch to maud-display impl of group + // maybe switch to maud-display impl of team let content = html! { h1 { - a href="/group" { "↩️" } - "Gruppe " (group.name) + a href="/team" { "↩️" } + "Team " (team.name) } article { details { - summary { "Gruppennamen bearbeiten ✏️" } - form action=(format!("/group/{}/name", group.id)) method="post" { - input type="text" name="name" value=(group.name) required; + summary { "Teamnamen bearbeiten ✏️" } + form action=(format!("/team/{}/name", team.id)) method="post" { + input type="text" name="name" value=(team.name) required; input type="submit" value="Speichern"; } @@ -117,12 +117,12 @@ async fn view( tr { th scope="row" { "Notizen" }; td { - @match &group.notes { + @match &team.notes { Some(notes) => { (notes) details { summary { "✏️" } - form action=(format!("/group/{}/notes", group.id)) method="post" { + form action=(format!("/team/{}/notes", team.id)) method="post" { textarea name="notes" required rows="10" { (notes) }; input type="submit" value="Speichern"; } @@ -130,7 +130,7 @@ async fn view( }, None => details { summary { "Neue Notiz hinzufügen" } - form action=(format!("/group/{}/notes", group.id)) method="post" { + form action=(format!("/team/{}/notes", team.id)) method="post" { textarea name="notes" required rows="10" {}; input type="submit" value="Speichern"; } @@ -139,21 +139,21 @@ async fn view( } } tr { - th scope="row" { "Anzahl Gruppenmitglieder" }; + th scope="row" { "Anzahl Teammitglieder" }; td { - @match group.amount_people { + @match team.amount_people { Some(amount) => (amount), None => "?", } details { summary { "✏️" } - form action=(format!("/group/{}/amount-people", group.id)) method="post" { + form action=(format!("/team/{}/amount-people", team.id)) method="post" { input type="number" name="amount_people" min="0" max="10"; input type="submit" value="Speichern"; } - a href=(format!("/group/{}/amount-people-reset", group.id)) { + a href=(format!("/team/{}/amount-people-reset", team.id)) { button class="error" { - em data-tooltip="Ich weiß noch nicht wv. Personen diese Gruppe beherbergt." { + em data-tooltip="Ich weiß noch nicht wv. Personen dieses Team beherbergt." { "?" } } @@ -164,23 +164,23 @@ async fn view( tr { th scope="row" { "Route" }; td { - a href=(format!("/route/{}", &group.route(&db).await.id)) { - (&group.route(&db).await.name) + a href=(format!("/route/{}", &team.route(&db).await.id)) { + (&team.route(&db).await.name) } @if routes.len() > 1 { details { summary { "✏️" } - form action=(format!("/group/{}/update-route", group.id)) method="post" { + form action=(format!("/team/{}/update-route", team.id)) method="post" { select name="route_id" aria-label="Route auswählen" required { @for route in &routes { - @if route.id != group.route(&db).await.id { + @if route.id != team.route(&db).await.id { option value=(route.id) { (route.name) } } } } - input type="submit" value="Gruppe speichern"; + input type="submit" value="Team speichern"; } } } @@ -190,7 +190,7 @@ async fn view( th scope="row" { "Erste Station" article { - "Die erste Station wird beim Anlegen einer Gruppe automatisch an diejenige Station vergeben, die aktuell am wenigsten Startgruppen hat. Diese Zuteilung kannst du hier auch manuell verändern." + "Die erste Station wird beim Anlegen eines Team automatisch an diejenige Station vergeben, die aktuell am wenigsten Startteams hat. Diese Zuteilung kannst du hier auch manuell verändern." } }; td { @@ -200,15 +200,15 @@ async fn view( @if stations.len() > 1 { details { summary { "✏️" } - form action=(format!("/group/{}/update-first-station", group.id)) method="post" { + form action=(format!("/team/{}/update-first-station", team.id)) method="post" { select name="first_station_id" aria-label="Station auswählen" required { @for station in &stations { @if station.id != first_station.id { option value=(station.id) { (station.name) - @let amount_start_groups = Group::all_with_first_station(&db, station).await.len(); - @if amount_start_groups > 0 { - (format!(" (schon {amount_start_groups} {})", pl(amount_start_groups, "Startgruppe"))) + @let amount_start_teams = Team::all_with_first_station(&db, station).await.len(); + @if amount_start_teams > 0 { + (format!(" (schon {amount_start_teams} {})", pl(amount_start_teams, "Startteam", "s"))) } } } @@ -237,25 +237,25 @@ async fn update_name( axum::extract::Path(id): axum::extract::Path, Form(form): Form, ) -> impl IntoResponse { - let Some(group) = Group::find_by_id(&db, id).await else { + let Some(team) = Team::find_by_id(&db, id).await else { err!( session, - "Gruppe mit ID {id} konnte nicht bearbeitet werden, da sie nicht existiert" + "Team mit ID {id} konnte nicht bearbeitet werden, da sie nicht existiert" ); - return Redirect::to("/group"); + return Redirect::to("/team"); }; - group.update_name(&db, &form.name).await; + team.update_name(&db, &form.name).await; succ!( session, - "Gruppe '{}' heißt ab sofort '{}'.", - group.name, + "Team '{}' heißt ab sofort '{}'.", + team.name, form.name ); - Redirect::to(&format!("/group/{id}")) + Redirect::to(&format!("/team/{id}")) } #[derive(Deserialize)] @@ -268,24 +268,24 @@ async fn update_notes( axum::extract::Path(id): axum::extract::Path, Form(form): Form, ) -> impl IntoResponse { - let Some(group) = Group::find_by_id(&db, id).await else { + let Some(team) = Team::find_by_id(&db, id).await else { err!( session, - "Gruppe mit ID {id} konnte nicht bearbeitet werden, da sie nicht existiert" + "Team mit ID {id} konnte nicht bearbeitet werden, da sie nicht existiert" ); - return Redirect::to("/group"); + return Redirect::to("/team"); }; - group.update_notes(&db, &form.notes).await; + team.update_notes(&db, &form.notes).await; succ!( session, - "Notizen für die Gruppe '{}' wurden erfolgreich bearbeitet!", - group.name + "Notizen für das Team '{}' wurden erfolgreich bearbeitet!", + team.name ); - Redirect::to(&format!("/group/{id}")) + Redirect::to(&format!("/team/{id}")) } #[derive(Deserialize)] @@ -298,24 +298,24 @@ async fn update_amount_people( axum::extract::Path(id): axum::extract::Path, Form(form): Form, ) -> impl IntoResponse { - let Some(group) = Group::find_by_id(&db, id).await else { + let Some(team) = Team::find_by_id(&db, id).await else { err!( session, - "Gruppe mit ID {id} konnte nicht bearbeitet werden, da sie nicht existiert" + "Team mit ID {id} konnte nicht bearbeitet werden, da sie nicht existiert" ); - return Redirect::to("/group"); + return Redirect::to("/team"); }; - group.update_amount_people(&db, form.amount_people).await; + team.update_amount_people(&db, form.amount_people).await; succ!( session, - "Anzahl an Mitglieder für die Gruppe '{}' wurden erfolgreich bearbeitet!", - group.name + "Anzahl an Mitglieder für das Team '{}' wurden erfolgreich bearbeitet!", + team.name ); - Redirect::to(&format!("/group/{id}")) + Redirect::to(&format!("/team/{id}")) } #[derive(Deserialize)] @@ -329,43 +329,43 @@ async fn update_route( Form(form): Form, ) -> impl IntoResponse { // TODO: move sanity checks into mod.rs - let Some(group) = Group::find_by_id(&db, id).await else { + let Some(team) = Team::find_by_id(&db, id).await else { err!( session, - "Gruppe mit ID {id} konnte nicht bearbeitet werden, da sie nicht existiert" + "Team mit ID {id} konnte nicht bearbeitet werden, da sie nicht existiert" ); - return Redirect::to("/group"); + return Redirect::to("/team"); }; let Some(route) = Route::find_by_id(&db, form.route_id).await else { err!( session, - "Konnte Gruppe mit ID {id} konnte nicht zur Route mit ID {} bearbeiten, da diese Route nicht existiert.", + "Konnte Team mit ID {id} konnte nicht zur Route mit ID {} bearbeiten, da diese Route nicht existiert.", form.route_id ); - return Redirect::to(&format!("/group/{id}")); + return Redirect::to(&format!("/team/{id}")); }; - match group.update_route(&db, &route).await { + match team.update_route(&db, &route).await { Ok(new_first_station_name) => succ!( session, - "Gruppe '{}' laufen ab sofort die Route '{}'. Auch die erste Station hat sich dadurch auf {} verändert!!", - group.name, + "Team '{}' läuft ab sofort die Route '{}'. Auch die erste Station hat sich dadurch auf {} verändert!!", + team.name, route.name, new_first_station_name ), Err(()) => err!( session, - "Konnte für die Gruppe {} nicht die Route {} auswählen, da Route {} keine Stationen zugeteilt hat.", - group.name, + "Konnte für das Team {} nicht die Route {} auswählen, da Route {} keine Stationen zugeteilt hat.", + team.name, route.name, route.name ), } - Redirect::to(&format!("/group/{id}")) + Redirect::to(&format!("/team/{id}")) } #[derive(Deserialize)] @@ -378,49 +378,49 @@ async fn update_first_station( axum::extract::Path(id): axum::extract::Path, Form(form): Form, ) -> impl IntoResponse { - let Some(group) = Group::find_by_id(&db, id).await else { + let Some(team) = Team::find_by_id(&db, id).await else { err!( session, - "Gruppe mit ID {id} konnte nicht bearbeitet werden, da sie nicht existiert" + "Team mit ID {id} konnte nicht bearbeitet werden, da sie nicht existiert" ); - return Redirect::to("/group"); + return Redirect::to("/team"); }; let Some(station) = Station::find_by_id(&db, form.first_station_id).await else { err!( session, - "Konnte die erste Station (ID={}) der Gruppe mit ID {} nicht bearbeiten, da diese Station nicht existiert.", + "Konnte die erste Station (ID={}) des Teams mit ID {} nicht bearbeiten, da diese Station nicht existiert.", form.first_station_id, - group.id + team.id ); - return Redirect::to(&format!("/group/{id}")); + return Redirect::to(&format!("/team/{id}")); }; - if !station.is_in_route(&db, &group.route(&db).await).await { + if !station.is_in_route(&db, &team.route(&db).await).await { err!( session, - "Konnte Station {} nicht der Gruppe {} hinzufügen, weil die Gruppe bei Route {} und nicht bei Route {} mitläuft.", + "Konnte Station {} nicht dem Team {} hinzufügen, weil dieses Team bei Route {} und nicht bei Route {} mitläuft.", station.name, - group.name, - group.route(&db).await.name, - group.name + team.name, + team.route(&db).await.name, + team.name ); - return Redirect::to(&format!("/group/{id}")); + return Redirect::to(&format!("/team/{id}")); } - group.update_first_station(&db, &station).await; + team.update_first_station(&db, &station).await; succ!( session, - "Erste Station der Gruppe {} ist ab sofort {}", - group.name, + "Erste Station des Teams {} ist ab sofort {}", + team.name, station.name ); - Redirect::to(&format!("/group/{id}")) + Redirect::to(&format!("/team/{id}")) } async fn update_amount_people_reset( @@ -428,37 +428,37 @@ async fn update_amount_people_reset( session: Session, axum::extract::Path(id): axum::extract::Path, ) -> impl IntoResponse { - let Some(group) = Group::find_by_id(&db, id).await else { + let Some(team) = Team::find_by_id(&db, id).await else { err!( session, - "Gruppe mit ID {id} konnte nicht bearbeitet werden, da sie nicht existiert" + "Team mit ID {id} konnte nicht bearbeitet werden, da sie nicht existiert" ); - return Redirect::to("/group"); + return Redirect::to("/team"); }; - group.update_amount_people_reset(&db).await; + team.update_amount_people_reset(&db).await; succ!( session, - "Anzahl an Mitglieder für die Gruppe '{}' wurden erfolgreich bearbeitet!", - group.name + "Anzahl an Mitglieder für das Team '{}' wurden erfolgreich bearbeitet!", + team.name ); - Redirect::to(&format!("/group/{id}")) + Redirect::to(&format!("/team/{id}")) } async fn index(State(db): State>, session: Session) -> Markup { - let groups = Group::all(&db).await; + let teams = Team::all(&db).await; let routes = Route::all(&db).await; let content = html! { h1 { a href="/" { "↩️" } - "Gruppen" + "Teams" } article { - em { "Gruppen " } + em { "Teams " } "sind eine Menge an Personen, die verschiedene " a href="/station" { "Stationen" } " ablaufen. Welche Stationen, entscheidet sich je nachdem, welcher " @@ -466,44 +466,44 @@ async fn index(State(db): State>, session: Session) -> Markup { " sie zugewiesen sind." } ol { - @for group in &groups{ + @for team in &teams{ li { - a href=(format!("/group/{}", group.id)){ - (group.name) + a href=(format!("/team/{}", team.id)){ + (team.name) } - a href=(format!("/group/{}/delete", group.id)) - onclick="return confirm('Bist du sicher, dass die Gruppe gelöscht werden soll? Das kann _NICHT_ mehr rückgängig gemacht werden.');" { + a href=(format!("/team/{}/delete", team.id)) + onclick="return confirm('Bist du sicher, dass das Team gelöscht werden soll? Das kann _NICHT_ mehr rückgängig gemacht werden.');" { "🗑️" } } } } - @if groups.is_empty() { + @if teams.is_empty() { article class="warning" { - "Es gibt noch keine Gruppen. " + "Es gibt noch keine Teams. " @if !routes.is_empty() { "Das kannst du hier ändern ⤵️" } } } - h2 { "Neue Gruppe" } + h2 { "Neues Team" } @if routes.is_empty() { article class="error" { - (PreEscaped("Bevor du einer Gruppe erstellen kannst, musst du zumindest eine Route erstellen, die die Gruppe gehen kann → ")) + (PreEscaped("Bevor du ein Team erstellen kannst, musst du zumindest eine Route erstellen, die das Team gehen kann → ")) a role="button" href="/route" { - "Gruppe erstellen" + "Team erstellen" } } } @else { - form action="/group" method="post" { + form action="/team" method="post" { @if routes.len() == 1 { - fieldset role="group" { - input type="text" name="name" placeholder="Gruppenname" required; + fieldset role="team" { + input type="text" name="name" placeholder="Teamnamen" required; input type="hidden" name="route_id" value=(routes[0].id) ; - input type="submit" value="Neue Gruppe"; + input type="submit" value="Neues Team"; } } @else { - input type="text" name="name" placeholder="Gruppenname" required; + input type="text" name="name" placeholder="Teamnamen" required; select name="route_id" aria-label="Route auswählen" required { @for route in &routes { option value=(route.id) { @@ -511,7 +511,7 @@ async fn index(State(db): State>, session: Session) -> Markup { } } } - input type="submit" value="Neue Gruppe"; + input type="submit" value="Neues Team"; } } }