]> Untitled Git - lemmy.git/blobdiff - crates/db_views/src/post_report_view.rs
Make functions work with both connection and pool (#3420)
[lemmy.git] / crates / db_views / src / post_report_view.rs
index 29136a351b1147fb005c63a3a0d39baab9b2eaf2..1219e0db514acc0cf6fffdfacc05c72efd9834c1 100644 (file)
@@ -49,7 +49,7 @@ impl PostReportView {
   ///
   /// * `report_id` - the report id to obtain
   pub async fn read(
-    pool: &DbPool,
+    pool: &mut DbPool<'_>,
     report_id: PostReportId,
     my_person_id: PersonId,
   ) -> Result<Self, Error> {
@@ -121,7 +121,7 @@ impl PostReportView {
 
   /// returns the current unresolved post report count for the communities you mod
   pub async fn get_report_count(
-    pool: &DbPool,
+    pool: &mut DbPool<'_>,
     my_person_id: PersonId,
     admin: bool,
     community_id: Option<CommunityId>,
@@ -161,9 +161,9 @@ impl PostReportView {
 
 #[derive(TypedBuilder)]
 #[builder(field_defaults(default))]
-pub struct PostReportQuery<'a> {
+pub struct PostReportQuery<'a, 'b: 'a> {
   #[builder(!default)]
-  pool: &'a DbPool,
+  pool: &'a mut DbPool<'b>,
   #[builder(!default)]
   my_person_id: PersonId,
   #[builder(!default)]
@@ -174,7 +174,7 @@ pub struct PostReportQuery<'a> {
   unresolved_only: Option<bool>,
 }
 
-impl<'a> PostReportQuery<'a> {
+impl<'a, 'b: 'a> PostReportQuery<'a, 'b> {
   pub async fn list(self) -> Result<Vec<PostReportView>, Error> {
     let conn = &mut get_conn(self.pool).await?;
     let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
@@ -219,7 +219,7 @@ impl<'a> PostReportQuery<'a> {
       query = query.filter(post::community_id.eq(community_id));
     }
 
-    if self.unresolved_only.unwrap_or(true) {
+    if self.unresolved_only.unwrap_or(false) {
       query = query.filter(post_report::resolved.eq(false));
     }
 
@@ -288,6 +288,7 @@ mod tests {
   #[serial]
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
+    let pool = &mut pool.into();
 
     let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
       .await
@@ -468,6 +469,8 @@ mod tests {
         newest_comment_time: inserted_post.published,
         featured_community: false,
         featured_local: false,
+        hot_rank: 1728,
+        hot_rank_active: 1728,
       },
       resolver: None,
     };
@@ -581,6 +584,7 @@ mod tests {
       .pool(pool)
       .my_person_id(inserted_timmy.id)
       .admin(false)
+      .unresolved_only(Some(true))
       .build()
       .list()
       .await