From 4854c84601a248c431a4deadc16821cc3f6485b5 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 24 Jun 2025 13:38:12 +0200 Subject: [PATCH] feat(gpodder): add admin paginated users method --- gpodder/src/repository/admin.rs | 8 +++++++- gpodder/src/store.rs | 3 +++ gpodder_sqlite/src/repository/auth.rs | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gpodder/src/repository/admin.rs b/gpodder/src/repository/admin.rs index 98fb08a..8a3e845 100644 --- a/gpodder/src/repository/admin.rs +++ b/gpodder/src/repository/admin.rs @@ -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, AuthErr> { + self.store.paginated_users(page) + } +} diff --git a/gpodder/src/store.rs b/gpodder/src/store.rs index 0cc45ae..1daa3c2 100644 --- a/gpodder/src/store.rs +++ b/gpodder/src/store.rs @@ -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) -> Result; + + /// Return the given page of users, ordered by username + fn paginated_users(&self, page: Page) -> Result, AuthErr>; } pub trait GpodderDeviceStore { diff --git a/gpodder_sqlite/src/repository/auth.rs b/gpodder_sqlite/src/repository/auth.rs index 26e5ad3..ced2606 100644 --- a/gpodder_sqlite/src/repository/auth.rs +++ b/gpodder_sqlite/src/repository/auth.rs @@ -142,4 +142,17 @@ impl gpodder::GpodderAuthStore for SqliteRepository { })() .map_err(AuthErr::from) } + + fn paginated_users(&self, page: gpodder::Page) -> Result, 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()) + } }