aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/controllers/screening.rs13
-rw-r--r--src/db.rs14
-rw-r--r--src/models/screening.rs16
-rw-r--r--src/schema.rs5
4 files changed, 22 insertions, 26 deletions
diff --git a/src/controllers/screening.rs b/src/controllers/screening.rs
index 9e78130..aca8e32 100644
--- a/src/controllers/screening.rs
+++ b/src/controllers/screening.rs
@@ -68,18 +68,21 @@ 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,
}
#[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 date = chrono::NaiveDate::parse_from_str(dbg!(&screening.date), "%Y-%m-%d")?;
- let start_time = chrono::NaiveTime::parse_from_str(dbg!(&screening.start_time), "%H:%M")?;
- let end_time = chrono::NaiveTime::parse_from_str(dbg!(&screening.end_time), "%H:%M")?;
+ let start_time = chrono::DateTime::parse_from_rfc3339(dbg!(&screening.start_time))?;
+ let end_time = chrono::DateTime::parse_from_rfc3339(dbg!(&screening.end_time))?;
+
+ db.create_screening(
+ dbg!(screening.room_id),
+ dbg!(screening.film_id),
+ start_time.with_timezone(&chrono::Utc),
+ end_time.with_timezone(&chrono::Utc))?;
- db.create_screening(dbg!(screening.room_id), dbg!(screening.film_id), date, start_time, end_time)?;
Ok(Redirect::to("/screenings"))
}
diff --git a/src/db.rs b/src/db.rs
index 4297d25..4c562ef 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -36,11 +36,10 @@ impl Connection {
&self,
room_id: i32,
film_id: i32,
- date: chrono::NaiveDate,
- start_time: chrono::NaiveTime,
- end_time: chrono::NaiveTime) -> QueryResult<usize>
+ start_time: chrono::DateTime<chrono::Utc>,
+ end_time: chrono::DateTime<chrono::Utc>) -> QueryResult<usize>
{
- let s = models::NewScreening { room_id, film_id, date, start_time, end_time };
+ let s = models::NewScreening { room_id, film_id, start_time, end_time };
diesel::insert_into(screenings::table)
.values(&s)
.execute(&**self)
@@ -50,11 +49,10 @@ impl Connection {
&self,
room: &models::Room,
film: &models::Film,
- date: chrono::NaiveDate,
- start_time: chrono::NaiveTime,
- end_time: chrono::NaiveTime) -> QueryResult<usize>
+ start_time: chrono::DateTime<chrono::Utc>,
+ end_time: chrono::DateTime<chrono::Utc>) -> QueryResult<usize>
{
- self.create_screening(room.id, film.id, date, start_time, end_time)
+ self.create_screening(room.id, film.id, start_time, end_time)
}
pub fn get_screenings(&self) -> QueryResult<Vec<models::Screening>> {
diff --git a/src/models/screening.rs b/src/models/screening.rs
index b111218..1426605 100644
--- a/src/models/screening.rs
+++ b/src/models/screening.rs
@@ -28,9 +28,8 @@ joinable!(screenings -> films (film_id));
pub struct NewScreening {
pub film_id: i32,
pub room_id: i32,
- pub date: chrono::NaiveDate,
- pub start_time: chrono::NaiveTime,
- pub end_time: chrono::NaiveTime,
+ pub start_time: chrono::DateTime<chrono::Utc>,
+ pub end_time: chrono::DateTime<chrono::Utc>,
}
#[derive(Deserialize, Identifiable, PartialEq, Serialize, Queryable)]
@@ -39,9 +38,8 @@ pub struct Screening {
pub id: i32,
pub film_id: i32,
pub room_id: i32,
- pub date: chrono::NaiveDate,
- pub start_time: chrono::NaiveTime,
- pub end_time: chrono::NaiveTime,
+ pub start_time: chrono::DateTime<chrono::Utc>,
+ pub end_time: chrono::DateTime<chrono::Utc>,
}
/// Aggregate screening, room and film info into one struct.
@@ -50,9 +48,8 @@ pub struct AggregatedScreening {
pub id: i32,
pub film: Film,
pub room: Room,
- pub date: chrono::NaiveDate,
- pub start_time: chrono::NaiveTime,
- pub end_time: chrono::NaiveTime,
+ pub start_time: chrono::DateTime<chrono::Utc>,
+ pub end_time: chrono::DateTime<chrono::Utc>,
}
impl AggregatedScreening {
@@ -62,7 +59,6 @@ impl AggregatedScreening {
id: s.id,
film: f.as_ref().unwrap().clone().to_owned(),
room: r.as_ref().unwrap().clone().to_owned(),
- date: s.date,
start_time: s.start_time,
end_time: s.end_time,
}
diff --git a/src/schema.rs b/src/schema.rs
index 88e1e00..8931558 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -18,9 +18,8 @@ table! {
id -> Int4,
film_id -> Int4,
room_id -> Int4,
- date -> Date,
- start_time -> Time,
- end_time -> Time,
+ start_time -> Timestamptz,
+ end_time -> Timestamptz,
}
}