aboutsummaryrefslogtreecommitdiffstats
path: root/src/models/post.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/models/post.rs')
-rw-r--r--src/models/post.rs13
1 files changed, 7 insertions, 6 deletions
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<Post> {
+ pub fn get_all(conn: utils::DbConn) -> Vec<Post> {
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)