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.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/models/post.rs b/src/models/post.rs
index bde8e54..c057775 100644
--- a/src/models/post.rs
+++ b/src/models/post.rs
@@ -20,12 +20,12 @@ pub struct NewPost {
}
impl Post {
- pub fn get_all(conn: DbConn) -> Vec<Post> {
+ pub fn get_all(conn: &DbConn) -> Vec<Post> {
use schema::posts::dsl::*;
posts
.filter(published.eq(false))
.limit(5)
- .load::<Post>(&*conn)
+ .load::<Post>(&**conn)
.expect("Error loading posts")
}
@@ -34,33 +34,33 @@ impl Post {
posts
.find(post_id)
.get_result(&**conn)
- .expect(&format!("Unable to find post with id={}", post_id))
+ .unwrap_or_else(|_| panic!("Unable to find post with id={}", post_id))
}
- pub fn get(post_id: i32, conn: DbConn) -> Post {
+ pub fn get(post_id: i32, conn: &DbConn) -> Post {
Post::get_internal(post_id, &conn)
}
- pub fn create(new_post: &NewPost, conn: DbConn) {
+ pub fn create(new_post: &NewPost, conn: &DbConn) {
use schema::posts::dsl::*;
diesel::insert_into(posts)
.values(new_post)
- .execute(&*conn)
+ .execute(&**conn)
.expect("Error saving post.");
}
- pub fn update(updated_post: &Post, conn: DbConn) {
+ pub fn update(updated_post: &Post, conn: &DbConn) {
let p = Post::get_internal(updated_post.id, &conn);
diesel::update(&p)
.set(updated_post)
- .execute(&*conn)
+ .execute(&**conn)
.expect("Error saving post.");
}
- pub fn delete(post_id: i32, conn: DbConn) {
+ pub fn delete(post_id: i32, conn: &DbConn) {
use schema::posts::dsl::*;
diesel::delete(posts.filter(id.eq(post_id)))
- .execute(&*conn)
- .expect(&format!("Could not delete post with id {}", post_id));
+ .execute(&**conn)
+ .unwrap_or_else(|_| panic!("Could not delete post with id {}", post_id));
}
}