From f4ca632c003e318f6b86b601557d345db32bdf03 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 15 Apr 2018 23:09:00 +0200 Subject: [PATCH] feat(db): Support GetPost message Very simple message that retrieves a post from the DB. --- src/db.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/db.rs b/src/db.rs index 202f6c160..4ac658a5c 100644 --- a/src/db.rs +++ b/src/db.rs @@ -71,6 +71,22 @@ impl Handler for DbExecutor { } } +/// Message used to fetch a specific post. +#[derive(Deserialize, Debug)] +pub struct GetPost { pub id: i32 } + +message!(GetPost, Result); + +impl Handler for DbExecutor { + type Result = ::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,