]> Untitled Git - lemmy.git/blobdiff - crates/db_schema/src/aggregates/site_aggregates.rs
First pass at adding comment trees. (#2362)
[lemmy.git] / crates / db_schema / src / aggregates / site_aggregates.rs
index 745097dfeb9c3d0952d5e197274ebf9a10ae81de..86a46e83f0e63263470aa25fe6b0c9a143c0725b 100644 (file)
@@ -1,23 +1,5 @@
-use crate::schema::site_aggregates;
+use crate::{aggregates::structs::SiteAggregates, schema::site_aggregates};
 use diesel::{result::Error, *};
-use serde::{Deserialize, Serialize};
-
-#[derive(
-  Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize, Clone,
-)]
-#[table_name = "site_aggregates"]
-pub struct SiteAggregates {
-  pub id: i32,
-  pub site_id: i32,
-  pub users: i64,
-  pub posts: i64,
-  pub comments: i64,
-  pub communities: i64,
-  pub users_active_day: i64,
-  pub users_active_week: i64,
-  pub users_active_month: i64,
-  pub users_active_half_year: i64,
-}
 
 impl SiteAggregates {
   pub fn read(conn: &PgConnection) -> Result<Self, Error> {
@@ -29,7 +11,6 @@ impl SiteAggregates {
 mod tests {
   use crate::{
     aggregates::site_aggregates::SiteAggregates,
-    establish_unpooled_connection,
     source::{
       comment::{Comment, CommentForm},
       community::{Community, CommunityForm},
@@ -38,6 +19,7 @@ mod tests {
       site::{Site, SiteForm},
     },
     traits::Crud,
+    utils::establish_unpooled_connection,
   };
   use serial_test::serial;
 
@@ -48,6 +30,7 @@ mod tests {
 
     let new_person = PersonForm {
       name: "thommy_site_agg".into(),
+      public_key: Some("pubkey".to_string()),
       ..PersonForm::default()
     };
 
@@ -55,6 +38,7 @@ mod tests {
 
     let site_form = SiteForm {
       name: "test_site".into(),
+      public_key: Some("pubkey".to_string()),
       ..Default::default()
     };
 
@@ -63,6 +47,7 @@ mod tests {
     let new_community = CommunityForm {
       name: "TIL_site_agg".into(),
       title: "nada".to_owned(),
+      public_key: Some("pubkey".to_string()),
       ..CommunityForm::default()
     };
 
@@ -87,17 +72,17 @@ mod tests {
     };
 
     // Insert two of those comments
-    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 site_aggregates_before_delete = SiteAggregates::read(&conn).unwrap();