forked from Ruderverein-Donau-Linz/rowt
42 lines
964 B
Rust
42 lines
964 B
Rust
use sea_orm::{DatabaseConnection, ModelTrait};
|
|
use serde::Serialize;
|
|
|
|
use super::{day, trip, user};
|
|
|
|
#[derive(Serialize, Debug)]
|
|
pub struct TripWithUser {
|
|
pub trip: trip::Model,
|
|
pub user: user::Model,
|
|
}
|
|
|
|
impl TripWithUser {
|
|
async fn new(trip: trip::Model, db: &DatabaseConnection) -> Self {
|
|
Self {
|
|
trip: trip.clone(),
|
|
user: trip
|
|
.find_related(user::Entity)
|
|
.one(db)
|
|
.await
|
|
.unwrap()
|
|
.unwrap(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Debug)]
|
|
pub struct DayWithTrips {
|
|
pub day: day::Model,
|
|
pub trips: Vec<TripWithUser>,
|
|
}
|
|
|
|
impl DayWithTrips {
|
|
pub async fn new(day: day::Model, db: &DatabaseConnection) -> Self {
|
|
let mut trips = Vec::new();
|
|
for trip in day.find_related(trip::Entity).all(db).await.unwrap() {
|
|
trips.push(TripWithUser::new(trip, db).await);
|
|
}
|
|
|
|
Self { day, trips }
|
|
}
|
|
}
|