+ };
+
+ let read = move |mut conn: DbConn<'a>, person_id: PersonId| async move {
+ all_joins(person::table.find(person_id).into_boxed())
+ .first::<PersonViewTuple>(&mut conn)
+ .await
+ };
+
+ let list = move |mut conn: DbConn<'a>, mode: ListMode| async move {
+ let mut query = all_joins(person::table.into_boxed());
+ match mode {
+ ListMode::Admins => {
+ query = query
+ .filter(person::admin.eq(true))
+ .filter(person::deleted.eq(false))
+ .order_by(person::published);
+ }
+ ListMode::Banned => {
+ query = query
+ .filter(
+ person::banned.eq(true).and(
+ person::ban_expires
+ .is_null()
+ .or(person::ban_expires.gt(now)),
+ ),
+ )
+ .filter(person::deleted.eq(false));
+ }
+ ListMode::Query(options) => {
+ if let Some(search_term) = options.search_term {
+ let searcher = fuzzy_search(&search_term);
+ query = query
+ .filter(person::name.ilike(searcher.clone()))
+ .or_filter(person::display_name.ilike(searcher));
+ }
+
+ query = match options.sort.unwrap_or(PersonSortType::CommentScore) {
+ PersonSortType::New => query.order_by(person::published.desc()),
+ PersonSortType::Old => query.order_by(person::published.asc()),
+ PersonSortType::MostComments => query.order_by(person_aggregates::comment_count.desc()),
+ PersonSortType::CommentScore => query.order_by(person_aggregates::comment_score.desc()),
+ PersonSortType::PostScore => query.order_by(person_aggregates::post_score.desc()),
+ PersonSortType::PostCount => query.order_by(person_aggregates::post_count.desc()),
+ };
+
+ let (limit, offset) = limit_and_offset(options.page, options.limit)?;
+ query = query.limit(limit).offset(offset);
+ }
+ }
+ query.load::<PersonViewTuple>(&mut conn).await
+ };
+
+ Queries::new(read, list)
+}
+
+impl PersonView {
+ pub async fn read(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Self, Error> {
+ queries().read(pool, person_id).await