]> Untitled Git - lemmy.git/blobdiff - crates/db_schema/src/aggregates/comment_aggregates.rs
First pass at adding comment trees. (#2362)
[lemmy.git] / crates / db_schema / src / aggregates / comment_aggregates.rs
index d47899bbffb11f766008faa19ba9b8b401c27011..679efeac0f2cd73f23e62ff07e4ecdfd7dcf5aae 100644 (file)
@@ -1,19 +1,9 @@
-use crate::{newtypes::CommentId, schema::comment_aggregates};
+use crate::{
+  aggregates::structs::CommentAggregates,
+  newtypes::CommentId,
+  schema::comment_aggregates,
+};
 use diesel::{result::Error, *};
-use serde::{Deserialize, Serialize};
-
-#[derive(
-  Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize, Clone,
-)]
-#[table_name = "comment_aggregates"]
-pub struct CommentAggregates {
-  pub id: i32,
-  pub comment_id: CommentId,
-  pub score: i64,
-  pub upvotes: i64,
-  pub downvotes: i64,
-  pub published: chrono::NaiveDateTime,
-}
 
 impl CommentAggregates {
   pub fn read(conn: &PgConnection, comment_id: CommentId) -> Result<Self, Error> {
@@ -27,7 +17,6 @@ impl CommentAggregates {
 mod tests {
   use crate::{
     aggregates::comment_aggregates::CommentAggregates,
-    establish_unpooled_connection,
     source::{
       comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
       community::{Community, CommunityForm},
@@ -35,6 +24,7 @@ mod tests {
       post::{Post, PostForm},
     },
     traits::{Crud, Likeable},
+    utils::establish_unpooled_connection,
   };
   use serial_test::serial;
 
@@ -45,6 +35,7 @@ mod tests {
 
     let new_person = PersonForm {
       name: "thommy_comment_agg".into(),
+      public_key: Some("pubkey".to_string()),
       ..PersonForm::default()
     };
 
@@ -52,6 +43,7 @@ mod tests {
 
     let another_person = PersonForm {
       name: "jerry_comment_agg".into(),
+      public_key: Some("pubkey".to_string()),
       ..PersonForm::default()
     };
 
@@ -60,6 +52,7 @@ mod tests {
     let new_community = CommunityForm {
       name: "TIL_comment_agg".into(),
       title: "nada".to_owned(),
+      public_key: Some("pubkey".to_string()),
       ..CommunityForm::default()
     };
 
@@ -81,17 +74,17 @@ mod tests {
       ..CommentForm::default()
     };
 
-    let inserted_comment = Comment::create(&conn, &comment_form).unwrap();
+    let inserted_comment = Comment::create(&conn, &comment_form, None).unwrap();
 
     let child_comment_form = CommentForm {
       content: "A test comment".into(),
       creator_id: inserted_person.id,
       post_id: inserted_post.id,
-      parent_id: Some(inserted_comment.id),
       ..CommentForm::default()
     };
 
-    let _inserted_child_comment = Comment::create(&conn, &child_comment_form).unwrap();
+    let _inserted_child_comment =
+      Comment::create(&conn, &child_comment_form, Some(&inserted_comment.path)).unwrap();
 
     let comment_like = CommentLikeForm {
       comment_id: inserted_comment.id,