about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-04-15T21·09+0200
committerVincent Ambo <tazjin@gmail.com>2018-04-15T21·09+0200
commitf4ca632c003e318f6b86b601557d345db32bdf03 (patch)
tree7f7000d7c9e092c44c278dedc19081d90b25e2b6 /src
parentce18cfa2d67ccf6ec560d59da1753930e86d169c (diff)
feat(db): Support GetPost message
Very simple message that retrieves a post from the DB.
Diffstat (limited to 'src')
-rw-r--r--src/db.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/db.rs b/src/db.rs
index 202f6c1609ca..4ac658a5ce64 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -71,6 +71,22 @@ impl Handler<GetThread> for DbExecutor {
     }
 }
 
+/// Message used to fetch a specific post.
+#[derive(Deserialize, Debug)]
+pub struct GetPost { pub id: i32 }
+
+message!(GetPost, Result<Post>);
+
+impl Handler<GetPost> for DbExecutor {
+    type Result = <GetPost as Message>::Result;
+
+    fn handle(&mut self, msg: GetPost, _: &mut Self::Context) -> Self::Result {
+        use schema::posts::dsl::*;
+        let conn = self.0.get()?;
+        Ok(posts.find(msg.id).first(&conn)?)
+    }
+}
+
 /// Message used to create a new thread
 pub struct CreateThread {
     pub new_thread: NewThread,