diff options
author | Vincent Ambo <tazjin@gmail.com> | 2018-04-08T18·19+0200 |
---|---|---|
committer | Vincent Ambo <tazjin@gmail.com> | 2018-04-08T18·19+0200 |
commit | 148dfc39c80266e9c3077737e4258739dba7d86a (patch) | |
tree | bbb175bac396c889376dc04286a17773c3d82a67 /src/db.rs | |
parent | 55b28f81369b6ea35ea08b67958674198fe94a4d (diff) |
feat(db/models): Add handling of CreatePost message
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/db.rs b/src/db.rs index 8c828d9c60c8..baf404af2a2f 100644 --- a/src/db.rs +++ b/src/db.rs @@ -75,7 +75,28 @@ impl Handler<CreateThread> for DbExecutor { let conn = self.0.get()?; Ok(diesel::insert_into(threads::table) - .values(&msg.0) - .get_result(&conn)?) + .values(&msg.0) + .get_result(&conn)?) + } +} + +/// Message used to create a new reply +pub struct CreatePost(pub NewPost); + +impl Message for CreatePost { + type Result = Result<Post>; +} + +impl Handler<CreatePost> for DbExecutor { + type Result = <CreatePost as Message>::Result; + + fn handle(&mut self, msg: CreatePost, _: &mut Self::Context) -> Self::Result { + use schema::posts; + + let conn = self.0.get()?; + + Ok(diesel::insert_into(posts::table) + .values(&msg.0) + .get_result(&conn)?) } } |