about summary refs log tree commit diff
path: root/src/db.rs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-04-08T15·42+0200
committerVincent Ambo <tazjin@gmail.com>2018-04-08T15·42+0200
commit7dca9183c581f803f7b456712dfed655722986e8 (patch)
tree4ce54ac0fffaaa4c73565d8db436ee9a3832c2ed /src/db.rs
parent3db069c60d5696efc3d8772e07fec65d876b45e2 (diff)
feat(db): Add initial GetThread message
Adds a GetThread message that returns a thread by ID. This does not
yet load posts.
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs22
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![]))
+    }
+}