From 22bac37fcaa1b1cdf8755754184ec8b3ace313b1 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 11 Jan 2018 22:41:09 +0100 Subject: Drop the lib. The misc stuff from the lib root was moved to the utils module (terrible name, it's meant to be temporary.) The modules under the lib has been moved directly under the app. --- src/models/post.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/models/post.rs') diff --git a/src/models/post.rs b/src/models/post.rs index b8453ce..922dbca 100644 --- a/src/models/post.rs +++ b/src/models/post.rs @@ -1,6 +1,7 @@ -use ::schema::posts; +use schema::posts; use diesel::prelude::*; use diesel::{self, ExecuteDsl}; +use utils; #[derive(AsChangeset, FromForm, Identifiable, Serialize, Queryable)] pub struct Post { @@ -19,7 +20,7 @@ pub struct NewPost { } impl Post { - pub fn get_all(conn: ::DbConn) -> Vec { + pub fn get_all(conn: utils::DbConn) -> Vec { use ::schema::posts::dsl::*; posts.filter(published.eq(false)) .limit(5) @@ -27,25 +28,25 @@ impl Post { .expect("Error loading posts") } - fn get_internal(post_id: i32, conn: &::DbConn) -> Post { + fn get_internal(post_id: i32, conn: &utils::DbConn) -> Post { use ::schema::posts::dsl::*; posts.find(post_id) .get_result(&**conn) .expect(&format!("Unable to find post with id={}", post_id)) } - pub fn get(post_id: i32, conn: ::DbConn) -> Post { + pub fn get(post_id: i32, conn: utils::DbConn) -> Post { Post::get_internal(post_id, &conn) } - pub fn create(new_post: &NewPost, conn: ::DbConn) { + pub fn create(new_post: &NewPost, conn: utils::DbConn) { diesel::insert(new_post) .into(posts::table) .execute(&*conn) .expect("Error saving post."); } - pub fn update(updated_post: &Post, conn: ::DbConn) { + pub fn update(updated_post: &Post, conn: utils::DbConn) { let p = Post::get_internal(updated_post.id, &conn); diesel::update(&p) .set(updated_post) -- cgit v1.2.3