]> Untitled Git - lemmy.git/blobdiff - crates/db_views/src/local_user_view.rs
Make functions work with both connection and pool (#3420)
[lemmy.git] / crates / db_views / src / local_user_view.rs
index 65d25160500e07b73426c26b976a8dcd5873886a..567ca3feb336e267bd675c6d179ab3480db6c2d6 100644 (file)
@@ -13,7 +13,7 @@ use lemmy_db_schema::{
 type LocalUserViewTuple = (LocalUser, Person, PersonAggregates);
 
 impl LocalUserView {
-  pub async fn read(pool: &DbPool, local_user_id: LocalUserId) -> Result<Self, Error> {
+  pub async fn read(pool: &mut DbPool<'_>, local_user_id: LocalUserId) -> Result<Self, Error> {
     let conn = &mut get_conn(pool).await?;
 
     let (local_user, person, counts) = local_user::table
@@ -34,7 +34,7 @@ impl LocalUserView {
     })
   }
 
-  pub async fn read_person(pool: &DbPool, person_id: PersonId) -> Result<Self, Error> {
+  pub async fn read_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Self, Error> {
     let conn = &mut get_conn(pool).await?;
     let (local_user, person, counts) = local_user::table
       .filter(person::id.eq(person_id))
@@ -54,11 +54,10 @@ impl LocalUserView {
     })
   }
 
-  // TODO check where this is used
-  pub async fn read_from_name(pool: &DbPool, name: &str) -> Result<Self, Error> {
+  pub async fn read_from_name(pool: &mut DbPool<'_>, name: &str) -> Result<Self, Error> {
     let conn = &mut get_conn(pool).await?;
     let (local_user, person, counts) = local_user::table
-      .filter(person::name.eq(name))
+      .filter(lower(person::name).eq(name.to_lowercase()))
       .inner_join(person::table)
       .inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
       .select((
@@ -75,7 +74,10 @@ impl LocalUserView {
     })
   }
 
-  pub async fn find_by_email_or_name(pool: &DbPool, name_or_email: &str) -> Result<Self, Error> {
+  pub async fn find_by_email_or_name(
+    pool: &mut DbPool<'_>,
+    name_or_email: &str,
+  ) -> Result<Self, Error> {
     let conn = &mut get_conn(pool).await?;
     let (local_user, person, counts) = local_user::table
       .inner_join(person::table)
@@ -99,7 +101,7 @@ impl LocalUserView {
     })
   }
 
-  pub async fn find_by_email(pool: &DbPool, from_email: &str) -> Result<Self, Error> {
+  pub async fn find_by_email(pool: &mut DbPool<'_>, from_email: &str) -> Result<Self, Error> {
     let conn = &mut get_conn(pool).await?;
     let (local_user, person, counts) = local_user::table
       .inner_join(person::table)
@@ -119,7 +121,7 @@ impl LocalUserView {
     })
   }
 
-  pub async fn list_admins_with_emails(pool: &DbPool) -> Result<Vec<Self>, Error> {
+  pub async fn list_admins_with_emails(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
     let conn = &mut get_conn(pool).await?;
     let res = local_user::table
       .filter(person::admin.eq(true))