]> Untitled Git - lemmy.git/blobdiff - crates/db_views_moderator/src/mod_add_community_view.rs
Make functions work with both connection and pool (#3420)
[lemmy.git] / crates / db_views_moderator / src / mod_add_community_view.rs
index bad3a1de16863743c1641ed437911bdc9cc93c7b..c1166b6dd359b4927305ab1c99716adc9d1a04c7 100644 (file)
@@ -12,24 +12,15 @@ use diesel_async::RunQueryDsl;
 use lemmy_db_schema::{
   newtypes::PersonId,
   schema::{community, mod_add_community, person},
-  source::{
-    community::{Community, CommunitySafe},
-    moderator::ModAddCommunity,
-    person::{Person, PersonSafe},
-  },
-  traits::{ToSafe, ViewToVec},
+  source::{community::Community, moderator::ModAddCommunity, person::Person},
+  traits::JoinView,
   utils::{get_conn, limit_and_offset, DbPool},
 };
 
-type ModAddCommunityViewTuple = (
-  ModAddCommunity,
-  Option<PersonSafe>,
-  CommunitySafe,
-  PersonSafe,
-);
+type ModAddCommunityViewTuple = (ModAddCommunity, Option<Person>, Community, Person);
 
 impl ModAddCommunityView {
-  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 person_alias_1 = diesel::alias!(person as person1);
     let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
@@ -47,9 +38,9 @@ impl ModAddCommunityView {
       )
       .select((
         mod_add_community::all_columns,
-        Person::safe_columns_tuple().nullable(),
-        Community::safe_columns_tuple(),
-        person_alias_1.fields(Person::safe_columns_tuple()),
+        person::all_columns.nullable(),
+        community::all_columns,
+        person_alias_1.fields(person::all_columns),
       ))
       .into_boxed();
 
@@ -74,22 +65,19 @@ impl ModAddCommunityView {
       .load::<ModAddCommunityViewTuple>(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 ModAddCommunityView {
-  type DbTuple = ModAddCommunityViewTuple;
-  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
-    items
-      .into_iter()
-      .map(|a| Self {
-        mod_add_community: a.0,
-        moderator: a.1,
-        community: a.2,
-        modded_person: a.3,
-      })
-      .collect::<Vec<Self>>()
+impl JoinView for ModAddCommunityView {
+  type JoinTuple = ModAddCommunityViewTuple;
+  fn from_tuple(a: Self::JoinTuple) -> Self {
+    Self {
+      mod_add_community: a.0,
+      moderator: a.1,
+      community: a.2,
+      modded_person: a.3,
+    }
   }
 }