show registration time for rowers
This commit is contained in:
parent
80976058b9
commit
f7c7f9aaf8
@ -19,8 +19,15 @@ pub struct PlannedEvent {
|
||||
pub struct PlannedEventWithUser {
|
||||
#[serde(flatten)]
|
||||
planned_event: PlannedEvent,
|
||||
cox: Vec<String>,
|
||||
rower: Vec<String>,
|
||||
cox: Vec<Registration>,
|
||||
rower: Vec<Registration>,
|
||||
}
|
||||
|
||||
//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<String> {
|
||||
let res = sqlx::query!(
|
||||
async fn get_all_cox_for_id(db: &SqlitePool, id: i64) -> Vec<Registration> {
|
||||
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<String> {
|
||||
let res = sqlx::query!(
|
||||
async fn get_all_rower_for_id(db: &SqlitePool, id: i64) -> Vec<Registration> {
|
||||
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(
|
||||
|
@ -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<String>,
|
||||
rower: Vec<Registration>,
|
||||
}
|
||||
|
||||
impl Trip {
|
||||
@ -48,18 +50,19 @@ WHERE day=?
|
||||
ret
|
||||
}
|
||||
|
||||
async fn get_all_rower_for_id(db: &SqlitePool, id: i64) -> Vec<String> {
|
||||
let res = sqlx::query!(
|
||||
async fn get_all_rower_for_id(db: &SqlitePool, id: i64) -> Vec<Registration> {
|
||||
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) {
|
||||
|
@ -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 %}
|
||||
<a href="/remove/{{ planned_event.trip_details_id }}">ABMELDEN</a>
|
||||
{% endif %}
|
||||
@ -78,7 +78,7 @@
|
||||
Notes: {{ trip.notes }}<br />
|
||||
Folgende Ruderer haben sich schon angemeldet:
|
||||
{% for rower in trip.rower %}
|
||||
{{ rower }}
|
||||
{{ rower.name }} (angemeldet seit {{ rower.registered_at }})
|
||||
{% if rower == loggedin_user.name %}
|
||||
<a href="/remove/{{ trip.trip_details_id }}">ABMELDEN</a>
|
||||
{% endif %}
|
||||
|
Loading…
Reference in New Issue
Block a user