diff options
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/db.rs b/src/db.rs index 17eecc938a82..c3a05a32372b 100644 --- a/src/db.rs +++ b/src/db.rs @@ -33,3 +33,25 @@ impl Handler<ListThreads> for DbExecutor { Ok(results) } } + +/// Message used to fetch a specific thread. Returns the thread and +/// its posts. +pub struct GetThread(pub i32); + +impl Message for GetThread { + type Result = Result<(Thread, Vec<Post>), Error>; +} + +impl Handler<GetThread> for DbExecutor { + type Result = <GetThread as Message>::Result; + + fn handle(&mut self, msg: GetThread, _: &mut Self::Context) -> Self::Result { + use schema::threads::dsl::*; + let conn = self.0.get().unwrap(); + let result: Thread = threads + .find(msg.0).first(&conn) + .expect("Error loading thread"); + + Ok((result, vec![])) + } +} |