feat(gpodder): add admin paginated users method

signup-links
Jef Roosens 2025-06-24 13:38:12 +02:00
parent 2524eb5807
commit 4854c84601
No known key found for this signature in database
GPG Key ID: 21FD3D77D56BAF49
3 changed files with 23 additions and 1 deletions

View File

@ -1,7 +1,13 @@
use crate::models;
use crate::{AuthErr, Page, models};
/// Admin view of the repository, providing methods only allowed by admins
pub struct AdminRepository<'a> {
pub(crate) store: &'a (dyn super::GpodderStore + Send + Sync),
pub(crate) user: &'a models::User,
}
impl<'a> AdminRepository<'a> {
pub fn paginated_users(&self, page: Page) -> Result<Vec<models::User>, AuthErr> {
self.store.paginated_users(page)
}
}

View File

@ -64,6 +64,9 @@ pub trait GpodderAuthStore {
/// Remove any sessions whose last_seen timestamp is before the given minimum value
fn remove_old_sessions(&self, min_last_seen: DateTime<Utc>) -> Result<usize, AuthErr>;
/// Return the given page of users, ordered by username
fn paginated_users(&self, page: Page) -> Result<Vec<User>, AuthErr>;
}
pub trait GpodderDeviceStore {

View File

@ -142,4 +142,17 @@ impl gpodder::GpodderAuthStore for SqliteRepository {
})()
.map_err(AuthErr::from)
}
fn paginated_users(&self, page: gpodder::Page) -> Result<Vec<gpodder::User>, AuthErr> {
Ok(users::table
.select(User::as_select())
.order(users::username.asc())
.offset((page.page * page.per_page) as i64)
.limit(page.per_page as i64)
.get_results(&mut self.pool.get().map_err(DbError::from)?)
.map_err(DbError::from)?
.into_iter()
.map(gpodder::User::from)
.collect())
}
}