diff --git a/src/model/planned_event.rs b/src/model/planned_event.rs index 497c615..e4a5df1 100644 --- a/src/model/planned_event.rs +++ b/src/model/planned_event.rs @@ -19,8 +19,15 @@ pub struct PlannedEvent { pub struct PlannedEventWithUser { #[serde(flatten)] planned_event: PlannedEvent, - cox: Vec, - rower: Vec, + cox: Vec, + rower: Vec, +} + +//TODO: move to appropriate place +#[derive(Serialize)] +pub struct Registration { + pub name: String, + pub registered_at: String, } impl PlannedEvent { @@ -60,9 +67,7 @@ WHERE day=?", let amount_currently_registered = i64::from(amount_currently_registered.count); let amount_allowed_to_register = sqlx::query!( - " - SELECT max_people FROM trip_details WHERE id = ? - ", + "SELECT max_people FROM trip_details WHERE id = ?", trip_details_id ) .fetch_one(db) @@ -73,32 +78,33 @@ WHERE day=?", amount_currently_registered < amount_allowed_to_register } - async fn get_all_cox_for_id(db: &SqlitePool, id: i64) -> Vec { - let res = sqlx::query!( + async fn get_all_cox_for_id(db: &SqlitePool, id: i64) -> Vec { + sqlx::query_as!( + Registration, " -SELECT (SELECT name FROM user WHERE cox_id = id) as name FROM trip WHERE planned_event_id = ? +SELECT (SELECT name FROM user WHERE cox_id = id) as name, (SELECT created_at FROM user WHERE cox_id = id) as registered_at FROM trip WHERE planned_event_id = ? ", id ) .fetch_all(db) .await - .unwrap(); //TODO: fixme - - res.into_iter().map(|x| x.name).collect() + .unwrap() //TODO: fixme } - async fn get_all_rower_for_id(db: &SqlitePool, id: i64) -> Vec { - let res = sqlx::query!( + async fn get_all_rower_for_id(db: &SqlitePool, id: i64) -> Vec { + sqlx::query_as!( + Registration, " -SELECT (SELECT name FROM user WHERE user_trip.user_id = user.id) as name FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM planned_event WHERE id = ?) +SELECT + (SELECT name FROM user WHERE user_trip.user_id = user.id) as name, + (SELECT created_at FROM user WHERE user_trip.user_id = user.id) as registered_at +FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM planned_event WHERE id = ?) ", id ) .fetch_all(db) .await - .unwrap(); //TODO: fixme - - res.into_iter().map(|x| x.name).collect() + .unwrap() //TODO: fixme } pub async fn create( diff --git a/src/model/trip.rs b/src/model/trip.rs index 77383c8..da9e0bf 100644 --- a/src/model/trip.rs +++ b/src/model/trip.rs @@ -2,6 +2,8 @@ use chrono::NaiveDate; use serde::Serialize; use sqlx::SqlitePool; +use super::planned_event::Registration; + #[derive(Serialize, Clone)] pub struct Trip { id: i64, @@ -18,7 +20,7 @@ pub struct Trip { pub struct TripWithUser { #[serde(flatten)] trip: Trip, - rower: Vec, + rower: Vec, } impl Trip { @@ -48,18 +50,19 @@ WHERE day=? ret } - async fn get_all_rower_for_id(db: &SqlitePool, id: i64) -> Vec { - let res = sqlx::query!( + async fn get_all_rower_for_id(db: &SqlitePool, id: i64) -> Vec { + sqlx::query_as!( + Registration, " -SELECT (SELECT name FROM user WHERE user_trip.user_id = user.id) as name FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM trip WHERE id = ?) - ", +SELECT + (SELECT name FROM user WHERE user_trip.user_id = user.id) as name, + (SELECT created_at FROM user WHERE user_trip.user_id = user.id) as registered_at +FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM trip WHERE id = ?)", id ) .fetch_all(db) .await - .unwrap(); //TODO: fixme - - res.into_iter().map(|x| x.name).collect() + .unwrap() //TODO: fixme } pub async fn new_own(db: &SqlitePool, cox_id: i64, trip_details_id: i64) { diff --git a/templates/index.html.tera b/templates/index.html.tera index 6007001..7750f80 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -50,7 +50,7 @@ Folgende Ruderer haben sich schon angemeldet: {% for rower in planned_event.rower%} - {{ rower }} + {{ rower.name }} (angemeldet seit {{ rower.registered_at }}) {% if rower == loggedin_user.name %} ABMELDEN {% endif %} @@ -78,7 +78,7 @@ Notes: {{ trip.notes }}
Folgende Ruderer haben sich schon angemeldet: {% for rower in trip.rower %} - {{ rower }} + {{ rower.name }} (angemeldet seit {{ rower.registered_at }}) {% if rower == loggedin_user.name %} ABMELDEN {% endif %}