From 33b5c759c18b249f85d06d08e3228e0d1e8e2182 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 23 Dec 2017 13:03:23 +0100 Subject: Move get_post into impl and rename. --- src/main.rs | 4 ++-- src/models.rs | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 84fe239..4aa448d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,12 +24,12 @@ implement_responder_for!(IndexTemplate<'a>); #[get("/", format = "text/html")] fn index<'a>(conn: rocket_blog::DbConn) -> IndexTemplate<'a> { - IndexTemplate { title: "Bloggen", posts: models::get_posts(conn) } + IndexTemplate { title: "Bloggen", posts: models::Post::get_all(conn) } } #[get("/", format = "application/json")] fn index_json(conn: rocket_blog::DbConn) -> Json> { - Json(models::get_posts(conn)) + Json(models::Post::get_all(conn)) } fn main() { diff --git a/src/models.rs b/src/models.rs index 8bf933e..4259d2c 100644 --- a/src/models.rs +++ b/src/models.rs @@ -9,12 +9,14 @@ pub struct Post { pub published: bool, } -pub fn get_posts(conn: ::DbConn) -> Vec { - use super::schema::posts::dsl::*; - posts.filter(published.eq(false)) - .limit(5) - .load::(&*conn) - .expect("Error loading posts") +impl Post { + pub fn get_all(conn: ::DbConn) -> Vec { + use super::schema::posts::dsl::*; + posts.filter(published.eq(false)) + .limit(5) + .load::(&*conn) + .expect("Error loading posts") + } } #[derive(Default, FromForm, Insertable)] -- cgit v1.2.3