aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/controllers/screening.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/controllers/screening.rs b/src/controllers/screening.rs
index aca8e32..40eefd3 100644
--- a/src/controllers/screening.rs
+++ b/src/controllers/screening.rs
@@ -68,20 +68,30 @@ pub fn new_screening(db: db::Connection) -> Result<Template, Box<dyn Error>> {
pub struct NewScreeningForm {
film_id: i32,
room_id: i32,
+ date: String,
start_time: String,
end_time: String,
}
+fn parse_datetime(date: &str, time: &str) -> Result<chrono::DateTime<chrono::Utc>, Box<dyn Error>> {
+ let dts = format!("{}T{}:00+02:00", &date, &time);
+ Ok(chrono::DateTime::parse_from_rfc3339(&dts)?.with_timezone(&chrono::Utc))
+}
+
#[post("/", format = "application/x-www-form-urlencoded", data = "<screening>")]
pub fn create_screening(db: db::Connection, screening: Form<NewScreeningForm>) -> Result<Redirect, Box<dyn Error>> {
- let start_time = chrono::DateTime::parse_from_rfc3339(dbg!(&screening.start_time))?;
- let end_time = chrono::DateTime::parse_from_rfc3339(dbg!(&screening.end_time))?;
+ let start_time = parse_datetime(&screening.date, &screening.start_time)?;
+ let mut end_time = parse_datetime(&screening.date, &screening.end_time)?;
+
+ if end_time < start_time {
+ end_time = end_time + chrono::Duration::days(1);
+ }
db.create_screening(
- dbg!(screening.room_id),
- dbg!(screening.film_id),
- start_time.with_timezone(&chrono::Utc),
- end_time.with_timezone(&chrono::Utc))?;
+ screening.room_id,
+ screening.film_id,
+ start_time,
+ end_time)?;
Ok(Redirect::to("/screenings"))
}