aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/controllers/screening.rs22
-rw-r--r--templates/screening/new.tera7
2 files changed, 21 insertions, 8 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"))
}
diff --git a/templates/screening/new.tera b/templates/screening/new.tera
index fd6be2f..0c3eb73 100644
--- a/templates/screening/new.tera
+++ b/templates/screening/new.tera
@@ -20,11 +20,14 @@
<option value="{{ room.id }}">{{ room.name }}</option>
{% endfor %}
+ <label for="date">Date: </label>
+ <input name="date" type="date">
+
<label for="start_time">Start time: </label>
- <input name="start_time" type="datetime">
+ <input name="start_time" type="time">
<label for="end_time">End time: </label>
- <input name="end_time" type="datetime">
+ <input name="end_time" type="time">
</select>
<input type="submit" value="Save">