default duration in cal of trips with type Lange Ausfahrt -> 6 hrs (instead of 3); Fixes #939
This commit is contained in:
		| @@ -2,8 +2,8 @@ use std::io::Write; | |||||||
|  |  | ||||||
| use chrono::{Duration, NaiveDate, NaiveTime}; | use chrono::{Duration, NaiveDate, NaiveTime}; | ||||||
| use ics::{ | use ics::{ | ||||||
|     ICalendar, |  | ||||||
|     properties::{DtEnd, DtStart, Summary}, |     properties::{DtEnd, DtStart, Summary}, | ||||||
|  |     ICalendar, | ||||||
| }; | }; | ||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| use sqlx::{FromRow, Row, SqlitePool}; | use sqlx::{FromRow, Row, SqlitePool}; | ||||||
| @@ -142,6 +142,14 @@ WHERE planned_event.id like ? | |||||||
|         .ok() |         .ok() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     async fn trip_type(&self, db: &SqlitePool) -> Option<TripType> { | ||||||
|  |         if let Some(trip_type_id) = self.trip_type_id { | ||||||
|  |             TripType::find_by_id(db, trip_type_id).await | ||||||
|  |         } else { | ||||||
|  |             None | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     pub async fn get_pinned_for_day(db: &SqlitePool, day: NaiveDate) -> Vec<EventWithDetails> { |     pub async fn get_pinned_for_day(db: &SqlitePool, day: NaiveDate) -> Vec<EventWithDetails> { | ||||||
|         let mut events = Self::get_for_day(db, day).await; |         let mut events = Self::get_for_day(db, day).await; | ||||||
|         events.retain(|e| e.event.always_show); |         events.retain(|e| e.event.always_show); | ||||||
| @@ -485,7 +493,16 @@ WHERE trip_details.id=? | |||||||
|  |  | ||||||
|         let original_time = NaiveTime::parse_from_str(&self.planned_starting_time, "%H:%M") |         let original_time = NaiveTime::parse_from_str(&self.planned_starting_time, "%H:%M") | ||||||
|             .expect("Failed to parse time"); |             .expect("Failed to parse time"); | ||||||
|         let later_time = original_time + Duration::hours(3); |  | ||||||
|  |         let long_trip = match self.trip_type(db).await { | ||||||
|  |             Some(a) if a.name == "Lange Ausfahrt" => true, | ||||||
|  |             _ => false, | ||||||
|  |         }; | ||||||
|  |         let later_time = if long_trip { | ||||||
|  |             original_time + Duration::hours(6) | ||||||
|  |         } else { | ||||||
|  |             original_time + Duration::hours(3) | ||||||
|  |         }; | ||||||
|         if later_time > original_time { |         if later_time > original_time { | ||||||
|             // Check if no day-overflow |             // Check if no day-overflow | ||||||
|             let time_three_hours_later = later_time.format("%H%M").to_string(); |             let time_three_hours_later = later_time.format("%H%M").to_string(); | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| use std::io::Write; | use std::io::Write; | ||||||
|  |  | ||||||
| use ics::{ICalendar, components::Property}; | use ics::{components::Property, ICalendar}; | ||||||
| use sqlx::SqlitePool; | use sqlx::SqlitePool; | ||||||
|  |  | ||||||
| use crate::model::{event::Event, trip::Trip, user::User}; | use crate::model::{event::Event, trip::Trip, user::User}; | ||||||
| @@ -19,7 +19,7 @@ pub(crate) async fn get_personal_cal(db: &SqlitePool, user: &User) -> String { | |||||||
|  |  | ||||||
|     let trips = Trip::all_with_user(db, user).await; |     let trips = Trip::all_with_user(db, user).await; | ||||||
|     for trip in trips { |     for trip in trips { | ||||||
|         calendar.add_event(trip.get_vevent(user).await); |         calendar.add_event(trip.get_vevent(db, user).await); | ||||||
|     } |     } | ||||||
|     let mut buf = Vec::new(); |     let mut buf = Vec::new(); | ||||||
|     write!(&mut buf, "{}", calendar).unwrap(); |     write!(&mut buf, "{}", calendar).unwrap(); | ||||||
|   | |||||||
| @@ -145,7 +145,15 @@ WHERE trip_details.id=? | |||||||
|         .ok() |         .ok() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     pub(crate) async fn get_vevent(self, user: &User) -> ics::Event { |     async fn trip_type(&self, db: &SqlitePool) -> Option<TripType> { | ||||||
|  |         if let Some(trip_type_id) = self.trip_type_id { | ||||||
|  |             TripType::find_by_id(db, trip_type_id).await | ||||||
|  |         } else { | ||||||
|  |             None | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     pub(crate) async fn get_vevent<'a>(self, db: &'a SqlitePool, user: &'a User) -> ics::Event<'a> { | ||||||
|         let mut vevent = |         let mut vevent = | ||||||
|             ics::Event::new(format!("trip-{}@rudernlinz.at", self.id), "19900101T180000"); |             ics::Event::new(format!("trip-{}@rudernlinz.at", self.id), "19900101T180000"); | ||||||
|         let time_str = self.planned_starting_time.replace(':', ""); |         let time_str = self.planned_starting_time.replace(':', ""); | ||||||
| @@ -163,7 +171,15 @@ WHERE trip_details.id=? | |||||||
|  |  | ||||||
|         let original_time = NaiveTime::parse_from_str(&self.planned_starting_time, "%H:%M") |         let original_time = NaiveTime::parse_from_str(&self.planned_starting_time, "%H:%M") | ||||||
|             .expect("Failed to parse time"); |             .expect("Failed to parse time"); | ||||||
|         let later_time = original_time + Duration::hours(3); |         let long_trip = match self.trip_type(db).await { | ||||||
|  |             Some(a) if a.name == "Lange Ausfahrt" => true, | ||||||
|  |             _ => false, | ||||||
|  |         }; | ||||||
|  |         let later_time = if long_trip { | ||||||
|  |             original_time + Duration::hours(6) | ||||||
|  |         } else { | ||||||
|  |             original_time + Duration::hours(3) | ||||||
|  |         }; | ||||||
|         if later_time > original_time { |         if later_time > original_time { | ||||||
|             // Check if no day-overflow |             // Check if no day-overflow | ||||||
|             let time_three_hours_later = later_time.format("%H%M").to_string(); |             let time_three_hours_later = later_time.format("%H%M").to_string(); | ||||||
| @@ -567,11 +583,9 @@ mod test { | |||||||
|  |  | ||||||
|         let last_notification = &Notification::for_user(&pool, &cox).await[0]; |         let last_notification = &Notification::for_user(&pool, &cox).await[0]; | ||||||
|  |  | ||||||
|         assert!( |         assert!(last_notification | ||||||
|             last_notification |             .message | ||||||
|                 .message |             .starts_with("cox2 hat eine Ausfahrt zur selben Zeit")); | ||||||
|                 .starts_with("cox2 hat eine Ausfahrt zur selben Zeit") |  | ||||||
|         ); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     #[sqlx::test] |     #[sqlx::test] | ||||||
|   | |||||||
| @@ -1,5 +1,4 @@ | |||||||
| use rocket::{ | use rocket::{ | ||||||
|     FromForm, Request, Route, State, |  | ||||||
|     form::Form, |     form::Form, | ||||||
|     get, |     get, | ||||||
|     http::{Cookie, CookieJar}, |     http::{Cookie, CookieJar}, | ||||||
| @@ -9,12 +8,13 @@ use rocket::{ | |||||||
|     response::{Flash, Redirect}, |     response::{Flash, Redirect}, | ||||||
|     routes, |     routes, | ||||||
|     time::{Duration, OffsetDateTime}, |     time::{Duration, OffsetDateTime}, | ||||||
|  |     FromForm, Request, Route, State, | ||||||
| }; | }; | ||||||
| use rocket_dyn_templates::{Template, context, tera}; | use rocket_dyn_templates::{context, tera, Template}; | ||||||
| use sqlx::SqlitePool; | use sqlx::SqlitePool; | ||||||
|  |  | ||||||
| use crate::model::{ | use crate::model::{ | ||||||
|     activity::{self, ActivityBuilder, ReasonAuth}, |     activity::{ActivityBuilder, ReasonAuth}, | ||||||
|     log::Log, |     log::Log, | ||||||
|     user::{LoginError, User}, |     user::{LoginError, User}, | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user