From e130e15b79c0a77c7759ec24e44310eebc013417 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 15 Apr 2018 23:23:13 +0200 Subject: [PATCH] feat(db): Support UpdatePost message Simple message intended to be used for post editing. --- src/db.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/db.rs b/src/db.rs index 4ac658a5c..3641bddb5 100644 --- a/src/db.rs +++ b/src/db.rs @@ -87,6 +87,29 @@ impl Handler for DbExecutor { } } +/// Message used to update the content of a post. +#[derive(Deserialize)] +pub struct UpdatePost { + post_id: i32, + post: String, +} + +message!(UpdatePost, Result); + +impl Handler for DbExecutor { + type Result = Result; + + fn handle(&mut self, msg: UpdatePost, _: &mut Self::Context) -> Self::Result { + use schema::posts::dsl::*; + let conn = self.0.get()?; + let updated = diesel::update(posts.find(msg.post_id)) + .set(body.eq(msg.post)) + .get_result(&conn)?; + + Ok(updated) + } +} + /// Message used to create a new thread pub struct CreateThread { pub new_thread: NewThread,