feat(db): Support UpdatePost message
Simple message intended to be used for post editing.
This commit is contained in:
parent
705097dab9
commit
e130e15b79
1 changed files with 23 additions and 0 deletions
23
src/db.rs
23
src/db.rs
|
@ -87,6 +87,29 @@ impl Handler<GetPost> for DbExecutor {
|
|||
}
|
||||
}
|
||||
|
||||
/// Message used to update the content of a post.
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdatePost {
|
||||
post_id: i32,
|
||||
post: String,
|
||||
}
|
||||
|
||||
message!(UpdatePost, Result<Post>);
|
||||
|
||||
impl Handler<UpdatePost> for DbExecutor {
|
||||
type Result = Result<Post>;
|
||||
|
||||
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,
|
||||
|
|
Loading…
Reference in a new issue