From ad0e585abed7a189b6117e9187c9afff809d1414 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Mon, 8 Apr 2019 15:55:14 +0200 Subject: Move functions to query/modify db to connection object. Makes tha API a bit nicer by asking the database rather than passing the database on to each model. Reserve models for method/functions that work on the model structs themselves. --- src/models/screening.rs | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) (limited to 'src/models/screening.rs') diff --git a/src/models/screening.rs b/src/models/screening.rs index cd08e88..5058d65 100644 --- a/src/models/screening.rs +++ b/src/models/screening.rs @@ -16,12 +16,7 @@ along with this program. If not, see . */ -use crate::{ - db::Connection, - models::{film::Film, room::Room}, - schema::*, -}; -use diesel::prelude::*; +use crate::schema::*; use serde_derive::{Deserialize, Serialize}; joinable!(screenings -> rooms (room_id)); @@ -46,32 +41,3 @@ pub struct NewScreening { pub start_time: chrono::NaiveTime, pub end_time: chrono::NaiveTime, } - -pub fn get_all(db: &Connection) -> QueryResult, Option)>> { - use crate::schema::screenings::dsl::*; - screenings - .left_join(films::table) - .left_join(rooms::table) - .get_results::<(Screening, Option, Option)>(&**db) -} - -pub fn create( - room: &Room, - film: &Film, - date: chrono::NaiveDate, - start_time: chrono::NaiveTime, - end_time: chrono::NaiveTime, - db: &Connection) -> QueryResult -{ - let s = NewScreening { - room_id: room.id, - film_id: film.id, - date: date, - start_time: start_time, - end_time: end_time, - }; - - diesel::insert_into(screenings::table) - .values(&s) - .execute(&**db) -} -- cgit v1.2.3