send triptype to frontend
This commit is contained in:
@ -5,6 +5,7 @@ use sqlx::SqlitePool;
|
||||
use super::{
|
||||
planned_event::{PlannedEvent, Registration},
|
||||
tripdetails::TripDetails,
|
||||
triptype::TripType,
|
||||
user::CoxUser,
|
||||
};
|
||||
|
||||
@ -18,13 +19,15 @@ pub struct Trip {
|
||||
max_people: i64,
|
||||
day: String,
|
||||
notes: Option<String>,
|
||||
trip_type_id: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct TripWithUser {
|
||||
pub struct TripWithUserAndType {
|
||||
#[serde(flatten)]
|
||||
trip: Trip,
|
||||
rower: Vec<Registration>,
|
||||
trip_type: Option<TripType>,
|
||||
}
|
||||
|
||||
impl Trip {
|
||||
@ -44,7 +47,7 @@ impl Trip {
|
||||
sqlx::query_as!(
|
||||
Self,
|
||||
"
|
||||
SELECT trip.id, cox_id, user.name as cox_name, trip_details_id, planned_starting_time, max_people, day, notes
|
||||
SELECT trip.id, cox_id, user.name as cox_name, trip_details_id, planned_starting_time, max_people, day, notes, trip_type_id
|
||||
FROM trip
|
||||
INNER JOIN trip_details ON trip.trip_details_id = trip_details.id
|
||||
INNER JOIN user ON trip.cox_id = user.id
|
||||
@ -92,12 +95,12 @@ WHERE trip.id=?
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_for_day(db: &SqlitePool, day: NaiveDate) -> Vec<TripWithUser> {
|
||||
pub async fn get_for_day(db: &SqlitePool, day: NaiveDate) -> Vec<TripWithUserAndType> {
|
||||
let day = format!("{day}");
|
||||
let trips = sqlx::query_as!(
|
||||
Trip,
|
||||
"
|
||||
SELECT trip.id, cox_id, user.name as cox_name, trip_details_id, planned_starting_time, max_people, day, notes
|
||||
SELECT trip.id, cox_id, user.name as cox_name, trip_details_id, planned_starting_time, max_people, day, notes, trip_type_id
|
||||
FROM trip
|
||||
INNER JOIN trip_details ON trip.trip_details_id = trip_details.id
|
||||
INNER JOIN user ON trip.cox_id = user.id
|
||||
@ -110,8 +113,13 @@ WHERE day=?
|
||||
.unwrap(); //TODO: fixme
|
||||
let mut ret = Vec::new();
|
||||
for trip in trips {
|
||||
ret.push(TripWithUser {
|
||||
let mut trip_type = None;
|
||||
if let Some(trip_type_id) = trip.trip_type_id {
|
||||
trip_type = TripType::find_by_id(db, trip_type_id).await;
|
||||
}
|
||||
ret.push(TripWithUserAndType {
|
||||
trip: trip.clone(),
|
||||
trip_type,
|
||||
rower: trip.get_all_rower(db).await,
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user