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:
parent
3db069c60d
commit
7dca9183c5
1 changed files with 22 additions and 0 deletions
22
src/db.rs
22
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![]))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue