about summary refs log tree commit diff
path: root/src/db.rs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-05-01T18·49+0200
committerVincent Ambo <github@tazj.in>2018-05-01T22·33+0200
commit9b1f6d3628884059753169f4dd6e018bab74c40f (patch)
tree5d608b4fa35cc935a7372985d211e2f9835ff2b5 /src/db.rs
parent9d5830e9a724d04b2f6fd410c7ae2b56ceea576f (diff)
refactor(db/render/schema): Use SimplePost type for thread views
This uses the simplified view for querying posts instead of the post
table directly to display posts.
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/db.rs b/src/db.rs
index cde4642d4b14..a04b3382447a 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -55,22 +55,22 @@ impl Handler<ListThreads> for DbExecutor {
 /// Message used to fetch a specific thread. Returns the thread and
 /// its posts.
 pub struct GetThread(pub i32);
-message!(GetThread, Result<(Thread, Vec<Post>)>);
+message!(GetThread, Result<(Thread, Vec<SimplePost>)>);
 
 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::*;
-        use schema::posts::dsl::id;
+        use schema::simple_posts::dsl::id;
 
         let conn = self.0.get()?;
         let thread_result: Thread = threads
             .find(msg.0).first(&conn)?;
 
-        let post_list = Post::belonging_to(&thread_result)
+        let post_list = SimplePost::belonging_to(&thread_result)
             .order_by(id.asc())
-            .load::<Post>(&conn)?;
+            .load::<SimplePost>(&conn)?;
 
         Ok((thread_result, post_list))
     }
@@ -80,15 +80,15 @@ impl Handler<GetThread> for DbExecutor {
 #[derive(Deserialize, Debug)]
 pub struct GetPost { pub id: i32 }
 
-message!(GetPost, Result<Post>);
+message!(GetPost, Result<SimplePost>);
 
 impl Handler<GetPost> for DbExecutor {
     type Result = <GetPost as Message>::Result;
 
     fn handle(&mut self, msg: GetPost, _: &mut Self::Context) -> Self::Result {
-        use schema::posts::dsl::*;
+        use schema::simple_posts::dsl::*;
         let conn = self.0.get()?;
-        Ok(posts.find(msg.id).first(&conn)?)
+        Ok(simple_posts.find(msg.id).first(&conn)?)
     }
 }
 
@@ -141,8 +141,7 @@ impl Handler<CreateThread> for DbExecutor {
             let new_post = NewPost {
                 thread_id: thread.id,
                 body: msg.post,
-                author_name: msg.new_thread.author_name.clone(),
-                author_email: msg.new_thread.author_email.clone(),
+                user_id: msg.new_thread.user_id,
             };
 
             diesel::insert_into(posts::table)