50 lines
1.2 KiB
Rust
50 lines
1.2 KiB
Rust
use chrono::NaiveDate;
|
|
use serde::Serialize;
|
|
use sqlx::SqlitePool;
|
|
|
|
use self::{
|
|
planned_event::{PlannedEvent, PlannedEventWithUserAndTriptype},
|
|
trip::{Trip, TripWithUserAndType},
|
|
};
|
|
|
|
pub mod boat;
|
|
pub mod location;
|
|
pub mod log;
|
|
pub mod planned_event;
|
|
pub mod trip;
|
|
pub mod tripdetails;
|
|
pub mod triptype;
|
|
pub mod user;
|
|
pub mod usertrip;
|
|
|
|
#[derive(Serialize)]
|
|
pub struct Day {
|
|
day: NaiveDate,
|
|
planned_events: Vec<PlannedEventWithUserAndTriptype>,
|
|
trips: Vec<TripWithUserAndType>,
|
|
is_pinned: bool,
|
|
}
|
|
|
|
impl Day {
|
|
pub async fn new(db: &SqlitePool, day: NaiveDate, is_pinned: bool) -> Self {
|
|
let planned_events = match is_pinned {
|
|
true => PlannedEvent::get_pinned_for_day(db, day).await,
|
|
false => PlannedEvent::get_for_day(db, day).await,
|
|
};
|
|
Self {
|
|
day,
|
|
planned_events,
|
|
trips: Trip::get_for_day(db, day).await,
|
|
is_pinned,
|
|
}
|
|
}
|
|
pub async fn new_guest(db: &SqlitePool, day: NaiveDate, is_pinned: bool) -> Self {
|
|
let mut day = Self::new(db, day, is_pinned).await;
|
|
|
|
day.planned_events.retain(|e| e.planned_event.allow_guests);
|
|
day.trips.retain(|t| t.trip.allow_guests);
|
|
|
|
day
|
|
}
|
|
}
|