From 7dca9183c581f803f7b456712dfed655722986e8 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 8 Apr 2018 17:42:14 +0200 Subject: feat(db): Add initial GetThread message Adds a GetThread message that returns a thread by ID. This does not yet load posts. --- src/db.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index 17eecc938a..c3a05a3237 100644 --- a/src/db.rs +++ b/src/db.rs @@ -33,3 +33,25 @@ impl Handler 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), Error>; +} + +impl Handler for DbExecutor { + type Result = ::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![])) + } +} -- cgit 1.4.1