feat(gpodder): add admin paginated users method
parent
2524eb5807
commit
4854c84601
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue