add is_pinned functionality

This commit is contained in:
2023-06-08 10:57:42 +02:00
parent c264b70e26
commit 87ed710f66
6 changed files with 67 additions and 15 deletions

View File

@ -20,18 +20,24 @@ 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) -> Self {
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: PlannedEvent::get_for_day(db, day).await,
planned_events,
trips: Trip::get_for_day(db, day).await,
is_pinned,
}
}
pub async fn new_guest(db: &SqlitePool, day: NaiveDate) -> Self {
let mut day = Self::new(db, day).await;
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);