]> Untitled Git - lemmy.git/blobdiff - crates/db_views_moderator/src/mod_hide_community_view.rs
Make functions work with both connection and pool (#3420)
[lemmy.git] / crates / db_views_moderator / src / mod_hide_community_view.rs
index 4b382d518966fb111e24fd0b5ef290bd2d09e2f2..66de2a9deece1bd041393cccd8d94344d630a47a 100644 (file)
@@ -12,20 +12,16 @@ use diesel_async::RunQueryDsl;
 use lemmy_db_schema::{
   newtypes::PersonId,
   schema::{community, mod_hide_community, person},
-  source::{
-    community::{Community, CommunitySafe},
-    moderator::ModHideCommunity,
-    person::{Person, PersonSafe},
-  },
-  traits::{ToSafe, ViewToVec},
+  source::{community::Community, moderator::ModHideCommunity, person::Person},
+  traits::JoinView,
   utils::{get_conn, limit_and_offset, DbPool},
 };
 
-type ModHideCommunityViewTuple = (ModHideCommunity, Option<PersonSafe>, CommunitySafe);
+type ModHideCommunityViewTuple = (ModHideCommunity, Option<Person>, Community);
 
 impl ModHideCommunityView {
   // Pass in mod_id as admin_id because only admins can do this action
-  pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+  pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
     let conn = &mut get_conn(pool).await?;
 
     let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
@@ -40,8 +36,8 @@ impl ModHideCommunityView {
       .inner_join(community::table.on(mod_hide_community::community_id.eq(community::id)))
       .select((
         mod_hide_community::all_columns,
-        Person::safe_columns_tuple().nullable(),
-        Community::safe_columns_tuple(),
+        person::all_columns.nullable(),
+        community::all_columns,
       ))
       .into_boxed();
 
@@ -62,21 +58,18 @@ impl ModHideCommunityView {
       .load::<ModHideCommunityViewTuple>(conn)
       .await?;
 
-    let results = Self::from_tuple_to_vec(res);
+    let results = res.into_iter().map(Self::from_tuple).collect();
     Ok(results)
   }
 }
 
-impl ViewToVec for ModHideCommunityView {
-  type DbTuple = ModHideCommunityViewTuple;
-  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
-    items
-      .into_iter()
-      .map(|a| Self {
-        mod_hide_community: a.0,
-        admin: a.1,
-        community: a.2,
-      })
-      .collect::<Vec<Self>>()
+impl JoinView for ModHideCommunityView {
+  type JoinTuple = ModHideCommunityViewTuple;
+  fn from_tuple(a: Self::JoinTuple) -> Self {
+    Self {
+      mod_hide_community: a.0,
+      admin: a.1,
+      community: a.2,
+    }
   }
 }