use db::conn::sea_orm::*; use db::repo::repo_watch as watch_entity; use crate::error::RepoResult; use crate::features::RepoService; use super::types::{ListSubscriberQuery, SubscriberPage, SubscriberView}; pub async fn list_subscribers( svc: &RepoService, actor: uuid::Uuid, repo_id: uuid::Uuid, q: ListSubscriberQuery, ) -> RepoResult { let _ = actor; let limit = q.limit.unwrap_or(svc.config.default_pagination); let offset = q.page.unwrap_or(0).saturating_mul(limit); let limit = std::cmp::min(limit, svc.config.max_pagination); let db = svc.db.reader(); let query = watch_entity::Entity::find().filter(watch_entity::Column::RepoId.eq(repo_id)); let total = query.clone().count(&db).await?; let items = query .limit(Some(limit)) .offset(Some(offset)) .all(&db) .await? .into_iter() .map(SubscriberView::from) .collect(); Ok(SubscriberPage { items, total: total as i64, }) }