aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2017-12-23 13:03:23 +0100
committerHarald Eilertsen <haraldei@anduin.net>2017-12-23 13:03:23 +0100
commit33b5c759c18b249f85d06d08e3228e0d1e8e2182 (patch)
treef1259fcfa5c9b02965d4d067ea9ea3f540524fc8 /src
parent6109a230ca65cd9a113df72d36247235fe934de4 (diff)
downloadrocket-blog-33b5c759c18b249f85d06d08e3228e0d1e8e2182.tar.gz
rocket-blog-33b5c759c18b249f85d06d08e3228e0d1e8e2182.tar.bz2
rocket-blog-33b5c759c18b249f85d06d08e3228e0d1e8e2182.zip
Move get_post into impl and rename.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs4
-rw-r--r--src/models.rs14
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)]