aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2019-04-08 16:25:54 +0200
committerHarald Eilertsen <haraldei@anduin.net>2019-04-08 16:25:54 +0200
commit30f65b62e84fcd9975643716d61fa21bc8495291 (patch)
tree28839044ab6acac3d94f0b0280c036b16d3bfddf
parentad0e585abed7a189b6117e9187c9afff809d1414 (diff)
downloadramaskrik-social-30f65b62e84fcd9975643716d61fa21bc8495291.tar.gz
ramaskrik-social-30f65b62e84fcd9975643716d61fa21bc8495291.tar.bz2
ramaskrik-social-30f65b62e84fcd9975643716d61fa21bc8495291.zip
Import model structs to main models module.
-rw-r--r--src/controllers/film.rs4
-rw-r--r--src/controllers/room.rs4
-rw-r--r--src/controllers/screening.rs2
-rw-r--r--src/db.rs16
-rw-r--r--src/lib.rs2
-rw-r--r--src/models.rs4
-rw-r--r--tests/apitests.rs8
7 files changed, 20 insertions, 20 deletions
diff --git a/src/controllers/film.rs b/src/controllers/film.rs
index e61a543..827b3ab 100644
--- a/src/controllers/film.rs
+++ b/src/controllers/film.rs
@@ -18,7 +18,7 @@
use crate::{
db,
- models::film,
+ models,
};
use rocket::get;
@@ -27,6 +27,6 @@ use rocket_contrib::{
};
#[get("/")]
-pub fn get_films(db: db::Connection) -> Json<Vec<film::Film>> {
+pub fn get_films(db: db::Connection) -> Json<Vec<models::Film>> {
Json(db.get_films().unwrap())
}
diff --git a/src/controllers/room.rs b/src/controllers/room.rs
index a203454..419afae 100644
--- a/src/controllers/room.rs
+++ b/src/controllers/room.rs
@@ -18,7 +18,7 @@
use crate::{
db,
- models::room,
+ models,
};
use rocket::get;
@@ -27,6 +27,6 @@ use rocket_contrib::{
};
#[get("/")]
-pub fn get_rooms(db: db::Connection) -> Json<Vec<room::Room>> {
+pub fn get_rooms(db: db::Connection) -> Json<Vec<models::Room>> {
Json(db.get_rooms().unwrap())
}
diff --git a/src/controllers/screening.rs b/src/controllers/screening.rs
index 622e9cb..29b6afa 100644
--- a/src/controllers/screening.rs
+++ b/src/controllers/screening.rs
@@ -18,7 +18,7 @@
use crate::{
db,
- models::{screening::Screening, film::Film, room::Room},
+ models::{Film, Room, Screening},
};
use rocket::get;
diff --git a/src/db.rs b/src/db.rs
index 53c4ea4..d7a12b0 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -34,13 +34,13 @@ pub struct Connection(diesel::PgConnection);
impl Connection {
pub fn create_screening(
&self,
- room: &models::room::Room,
- film: &models::film::Film,
+ room: &models::Room,
+ film: &models::Film,
date: chrono::NaiveDate,
start_time: chrono::NaiveTime,
end_time: chrono::NaiveTime) -> QueryResult<usize>
{
- let s = models::screening::NewScreening {
+ let s = models::NewScreening {
room_id: room.id,
film_id: film.id,
date: date,
@@ -53,7 +53,7 @@ impl Connection {
.execute(&**self)
}
- pub fn get_screenings(&self) -> QueryResult<Vec<(models::screening::Screening, Option<models::film::Film>, Option<models::room::Room>)>> {
+ pub fn get_screenings(&self) -> QueryResult<Vec<(models::Screening, Option<models::Film>, Option<models::Room>)>> {
use crate::schema::screenings::dsl::*;
screenings
.left_join(films::table)
@@ -61,24 +61,24 @@ impl Connection {
.get_results(&**self)
}
- pub fn get_rooms(&self) -> QueryResult<Vec<models::room::Room>> {
+ pub fn get_rooms(&self) -> QueryResult<Vec<models::Room>> {
use crate::schema::rooms::dsl::*;
rooms.load(&**self)
}
- pub fn get_room_by_name(&self, room_name: &str) -> QueryResult<models::room::Room> {
+ pub fn get_room_by_name(&self, room_name: &str) -> QueryResult<models::Room> {
use crate::schema::rooms::dsl::*;
rooms
.filter(name.eq(&room_name))
.get_result(&**self)
}
- pub fn get_films(&self) -> QueryResult<Vec<models::film::Film>> {
+ pub fn get_films(&self) -> QueryResult<Vec<models::Film>> {
use crate::schema::films::dsl::*;
films.load(&**self)
}
- pub fn get_film_by_title(&self, film_title: &str) -> QueryResult<models::film::Film> {
+ pub fn get_film_by_title(&self, film_title: &str) -> QueryResult<models::Film> {
use crate::schema::films::dsl::*;
films
.filter(title.eq(&film_title))
diff --git a/src/lib.rs b/src/lib.rs
index 6554e7c..9ae797d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -15,7 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-#![feature(proc_macro_hygiene, decl_macro)]
+#![feature(proc_macro_hygiene, decl_macro, uniform_paths)]
#[macro_use] extern crate diesel;
diff --git a/src/models.rs b/src/models.rs
index 40d910c..fc45d88 100644
--- a/src/models.rs
+++ b/src/models.rs
@@ -19,3 +19,7 @@
pub mod film;
pub mod room;
pub mod screening;
+
+pub use film::{Film, NewFilm};
+pub use room::Room;
+pub use screening::{NewScreening, Screening};
diff --git a/tests/apitests.rs b/tests/apitests.rs
index 54b7961..a488c33 100644
--- a/tests/apitests.rs
+++ b/tests/apitests.rs
@@ -17,11 +17,7 @@
*/
use ramaskrik;
-use ramaskrik::models::{
- film::{ Film, NewFilm },
- room::Room,
- screening,
-};
+use ramaskrik::models::{Film, NewFilm, Room, Screening};
use lazy_static::lazy_static;
use rocket::http::ContentType;
@@ -136,7 +132,7 @@ fn getting_screenings_from_api() {
let mut response = client.get("/screenings").dispatch();
assert_eq!(response.content_type(), Some(ContentType::JSON));
- let fetched_screenings: Vec<(screening::Screening, Film, Room)> =
+ let fetched_screenings: Vec<(Screening, Film, Room)> =
serde_json::from_str(&response.body_string().unwrap()).unwrap();
assert_eq!(fetched_screenings.len(), 1);