- )
- .select((
- local_user::all_columns,
- person::all_columns,
- person_aggregates::all_columns,
- ))
- .first::<LocalUserViewTuple>(conn)?;
- Ok(Self {
- local_user,
- person,
- counts,
- })
+ ),
+ _ => query,
+ };
+ query
+ .inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
+ .select(selection)
+ .first::<LocalUserViewTuple>(&mut conn)
+ .await
+ };
+
+ let list = move |mut conn: DbConn<'a>, mode: ListMode| async move {
+ match mode {
+ ListMode::AdminsWithEmails => {
+ local_user::table
+ .filter(local_user::email.is_not_null())
+ .filter(person::admin.eq(true))
+ .inner_join(person::table)
+ .inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
+ .select(selection)
+ .load::<LocalUserViewTuple>(&mut conn)
+ .await
+ }
+ }
+ };
+
+ Queries::new(read, list)
+}
+
+impl LocalUserView {
+ pub async fn read(pool: &mut DbPool<'_>, local_user_id: LocalUserId) -> Result<Self, Error> {
+ queries().read(pool, ReadBy::Id(local_user_id)).await