feat(db): Add initial GetThread message

Adds a GetThread message that returns a thread by ID. This does not
yet load posts.
This commit is contained in:
Vincent Ambo 2018-04-08 17:42:14 +02:00
parent 3db069c60d
commit 7dca9183c5

View file

@ -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![]))
}
}