show registration time for rowers

This commit is contained in:
philipp 2023-04-05 17:25:22 +02:00
parent 80976058b9
commit f7c7f9aaf8
3 changed files with 36 additions and 27 deletions

View File

@ -19,8 +19,15 @@ pub struct PlannedEvent {
pub struct PlannedEventWithUser { pub struct PlannedEventWithUser {
#[serde(flatten)] #[serde(flatten)]
planned_event: PlannedEvent, planned_event: PlannedEvent,
cox: Vec<String>, cox: Vec<Registration>,
rower: Vec<String>, rower: Vec<Registration>,
}
//TODO: move to appropriate place
#[derive(Serialize)]
pub struct Registration {
pub name: String,
pub registered_at: String,
} }
impl PlannedEvent { impl PlannedEvent {
@ -60,9 +67,7 @@ WHERE day=?",
let amount_currently_registered = i64::from(amount_currently_registered.count); let amount_currently_registered = i64::from(amount_currently_registered.count);
let amount_allowed_to_register = sqlx::query!( 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 trip_details_id
) )
.fetch_one(db) .fetch_one(db)
@ -73,32 +78,33 @@ WHERE day=?",
amount_currently_registered < amount_allowed_to_register amount_currently_registered < amount_allowed_to_register
} }
async fn get_all_cox_for_id(db: &SqlitePool, id: i64) -> Vec<String> { async fn get_all_cox_for_id(db: &SqlitePool, id: i64) -> Vec<Registration> {
let res = sqlx::query!( 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 id
) )
.fetch_all(db) .fetch_all(db)
.await .await
.unwrap(); //TODO: fixme .unwrap() //TODO: fixme
res.into_iter().map(|x| x.name).collect()
} }
async fn get_all_rower_for_id(db: &SqlitePool, id: i64) -> Vec<String> { async fn get_all_rower_for_id(db: &SqlitePool, id: i64) -> Vec<Registration> {
let res = sqlx::query!( 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 id
) )
.fetch_all(db) .fetch_all(db)
.await .await
.unwrap(); //TODO: fixme .unwrap() //TODO: fixme
res.into_iter().map(|x| x.name).collect()
} }
pub async fn create( pub async fn create(

View File

@ -2,6 +2,8 @@ use chrono::NaiveDate;
use serde::Serialize; use serde::Serialize;
use sqlx::SqlitePool; use sqlx::SqlitePool;
use super::planned_event::Registration;
#[derive(Serialize, Clone)] #[derive(Serialize, Clone)]
pub struct Trip { pub struct Trip {
id: i64, id: i64,
@ -18,7 +20,7 @@ pub struct Trip {
pub struct TripWithUser { pub struct TripWithUser {
#[serde(flatten)] #[serde(flatten)]
trip: Trip, trip: Trip,
rower: Vec<String>, rower: Vec<Registration>,
} }
impl Trip { impl Trip {
@ -48,18 +50,19 @@ WHERE day=?
ret ret
} }
async fn get_all_rower_for_id(db: &SqlitePool, id: i64) -> Vec<String> { async fn get_all_rower_for_id(db: &SqlitePool, id: i64) -> Vec<Registration> {
let res = sqlx::query!( 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 id
) )
.fetch_all(db) .fetch_all(db)
.await .await
.unwrap(); //TODO: fixme .unwrap() //TODO: fixme
res.into_iter().map(|x| x.name).collect()
} }
pub async fn new_own(db: &SqlitePool, cox_id: i64, trip_details_id: i64) { pub async fn new_own(db: &SqlitePool, cox_id: i64, trip_details_id: i64) {

View File

@ -50,7 +50,7 @@
Folgende Ruderer haben sich schon angemeldet: Folgende Ruderer haben sich schon angemeldet:
{% for rower in planned_event.rower%} {% for rower in planned_event.rower%}
{{ rower }} {{ rower.name }} (angemeldet seit {{ rower.registered_at }})
{% if rower == loggedin_user.name %} {% if rower == loggedin_user.name %}
<a href="/remove/{{ planned_event.trip_details_id }}">ABMELDEN</a> <a href="/remove/{{ planned_event.trip_details_id }}">ABMELDEN</a>
{% endif %} {% endif %}
@ -78,7 +78,7 @@
Notes: {{ trip.notes }}<br /> Notes: {{ trip.notes }}<br />
Folgende Ruderer haben sich schon angemeldet: Folgende Ruderer haben sich schon angemeldet:
{% for rower in trip.rower %} {% for rower in trip.rower %}
{{ rower }} {{ rower.name }} (angemeldet seit {{ rower.registered_at }})
{% if rower == loggedin_user.name %} {% if rower == loggedin_user.name %}
<a href="/remove/{{ trip.trip_details_id }}">ABMELDEN</a> <a href="/remove/{{ trip.trip_details_id }}">ABMELDEN</a>
{% endif %} {% endif %}