aboutsummaryrefslogtreecommitdiffstats
path: root/src/models
diff options
context:
space:
mode:
Diffstat (limited to 'src/models')
-rw-r--r--src/models/film.rs18
-rw-r--r--src/models/room.rs18
-rw-r--r--src/models/screening.rs36
3 files changed, 3 insertions, 69 deletions
diff --git a/src/models/film.rs b/src/models/film.rs
index 8207e5d..8f17d42 100644
--- a/src/models/film.rs
+++ b/src/models/film.rs
@@ -16,11 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-use crate::{
- db::Connection,
- schema::films,
-};
-use diesel::prelude::*;
+use crate::schema::films;
use serde_derive::{Deserialize, Serialize};
#[derive(Deserialize, Identifiable, PartialEq, Serialize, Queryable)]
@@ -36,15 +32,3 @@ pub struct NewFilm<'a> {
pub title: &'a str,
pub url: Option<&'a str>,
}
-
-pub fn get_all(db: &Connection) -> QueryResult<Vec<Film>> {
- use crate::schema::films::dsl::*;
- films.load::<Film>(&**db)
-}
-
-pub fn by_title(ftitle: &str, db: &Connection) -> QueryResult<Film> {
- use crate::schema::films::dsl::*;
- films
- .filter(title.eq(&ftitle))
- .get_result::<Film>(&**db)
-}
diff --git a/src/models/room.rs b/src/models/room.rs
index 6360c88..d475901 100644
--- a/src/models/room.rs
+++ b/src/models/room.rs
@@ -16,11 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-use crate::{
- db::Connection,
- schema::rooms,
-};
-use diesel::prelude::*;
+use crate::schema::rooms;
use serde_derive::{Deserialize, Serialize};
#[derive(Deserialize, Identifiable, PartialEq, Serialize, Queryable)]
@@ -28,15 +24,3 @@ pub struct Room {
pub id: i32,
pub name: String,
}
-
-pub fn get_all(db: &Connection) -> QueryResult<Vec<Room>> {
- use crate::schema::rooms::dsl::*;
- rooms.load::<Room>(&**db)
-}
-
-pub fn by_name(rname: &str, db: &Connection) -> QueryResult<Room> {
- use crate::schema::rooms::dsl::*;
- rooms
- .filter(name.eq(&rname))
- .get_result::<Room>(&**db)
-}
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 <https://www.gnu.org/licenses/>.
*/
-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<Vec<(Screening, Option<Film>, Option<Room>)>> {
- use crate::schema::screenings::dsl::*;
- screenings
- .left_join(films::table)
- .left_join(rooms::table)
- .get_results::<(Screening, Option<Film>, Option<Room>)>(&**db)
-}
-
-pub fn create(
- room: &Room,
- film: &Film,
- date: chrono::NaiveDate,
- start_time: chrono::NaiveTime,
- end_time: chrono::NaiveTime,
- db: &Connection) -> QueryResult<usize>
-{
- 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)
-}