aboutsummaryrefslogtreecommitdiffstats
path: root/src/models
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2019-04-28 13:47:58 +0200
committerHarald Eilertsen <haraldei@anduin.net>2019-04-28 13:47:58 +0200
commitcaa7b4429e68135404ad5a01aa1d7f530abae090 (patch)
tree2f2b2331de7e126bc2552c4e285cd75f69256cf4 /src/models
parent30f65b62e84fcd9975643716d61fa21bc8495291 (diff)
downloadramaskrik-social-caa7b4429e68135404ad5a01aa1d7f530abae090.tar.gz
ramaskrik-social-caa7b4429e68135404ad5a01aa1d7f530abae090.tar.bz2
ramaskrik-social-caa7b4429e68135404ad5a01aa1d7f530abae090.zip
Update /screenings endpoint to return full info on screenings.
This makes each screening record self-contained, and the json payload more consistent with how it semantically fit together.
Diffstat (limited to 'src/models')
-rw-r--r--src/models/film.rs2
-rw-r--r--src/models/room.rs2
-rw-r--r--src/models/screening.rs37
3 files changed, 34 insertions, 7 deletions
diff --git a/src/models/film.rs b/src/models/film.rs
index 8f17d42..f280cf6 100644
--- a/src/models/film.rs
+++ b/src/models/film.rs
@@ -19,7 +19,7 @@
use crate::schema::films;
use serde_derive::{Deserialize, Serialize};
-#[derive(Deserialize, Identifiable, PartialEq, Serialize, Queryable)]
+#[derive(Clone, Default, Deserialize, Identifiable, PartialEq, Serialize, Queryable)]
pub struct Film {
pub id: i32,
pub title: String,
diff --git a/src/models/room.rs b/src/models/room.rs
index d475901..40c5d19 100644
--- a/src/models/room.rs
+++ b/src/models/room.rs
@@ -19,7 +19,7 @@
use crate::schema::rooms;
use serde_derive::{Deserialize, Serialize};
-#[derive(Deserialize, Identifiable, PartialEq, Serialize, Queryable)]
+#[derive(Clone, Default, Deserialize, Identifiable, PartialEq, Serialize, Queryable)]
pub struct Room {
pub id: i32,
pub name: String,
diff --git a/src/models/screening.rs b/src/models/screening.rs
index 5058d65..4ae42a2 100644
--- a/src/models/screening.rs
+++ b/src/models/screening.rs
@@ -16,15 +16,16 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+use crate::models::{Film, Room};
use crate::schema::*;
use serde_derive::{Deserialize, Serialize};
joinable!(screenings -> rooms (room_id));
joinable!(screenings -> films (film_id));
-#[derive(Deserialize, Identifiable, PartialEq, Serialize, Queryable)]
-pub struct Screening {
- pub id: i32,
+#[derive(Deserialize, Insertable)]
+#[table_name = "screenings"]
+pub struct NewScreening {
pub film_id: i32,
pub room_id: i32,
pub date: chrono::NaiveDate,
@@ -32,12 +33,38 @@ pub struct Screening {
pub end_time: chrono::NaiveTime,
}
-#[derive(Deserialize, Insertable)]
+#[derive(Deserialize, Identifiable, PartialEq, Serialize, Queryable)]
#[table_name = "screenings"]
-pub struct NewScreening {
+pub struct ScreeningRecord {
+ 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,
}
+
+#[derive(Deserialize, Serialize)]
+pub struct Screening {
+ pub id: i32,
+ pub film: Film,
+ pub room: Room,
+ pub date: chrono::NaiveDate,
+ pub start_time: chrono::NaiveTime,
+ pub end_time: chrono::NaiveTime,
+}
+
+impl Screening {
+ pub fn from_query(s: Vec<(ScreeningRecord, Option<Film>, Option<Room>)>) -> Vec<Screening> {
+ s.iter().map(|(s, f, r)| {
+ Screening {
+ 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,
+ }
+ }).collect()
+ }
+}