diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 4 | ||||
-rw-r--r-- | src/models.rs | 14 |
2 files changed, 10 insertions, 8 deletions
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<Vec<models::Post>> { - 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<Post> { - use super::schema::posts::dsl::*; - posts.filter(published.eq(false)) - .limit(5) - .load::<Post>(&*conn) - .expect("Error loading posts") +impl Post { + pub fn get_all(conn: ::DbConn) -> Vec<Post> { + use super::schema::posts::dsl::*; + posts.filter(published.eq(false)) + .limit(5) + .load::<Post>(&*conn) + .expect("Error loading posts") + } } #[derive(Default, FromForm, Insertable)] |