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 logbook; pub mod logtype; pub mod planned_event; pub mod rower; 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, trips: Vec, 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, }; let trips = match is_pinned { true => Trip::get_pinned_for_day(db, day).await, false => Trip::get_for_day(db, day).await, }; Self { day, planned_events, trips, 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 } }