35 lines
1.1 KiB
Rust
35 lines
1.1 KiB
Rust
use crate::error::AppError;
|
|
use crate::models::prs::PrFile;
|
|
use crate::service::PrService;
|
|
use crate::session::Session;
|
|
|
|
use super::util::clamp_limit_offset;
|
|
|
|
impl PrService {
|
|
pub async fn pr_files(
|
|
&self,
|
|
ctx: &Session,
|
|
wk_name: &str,
|
|
repo_name: &str,
|
|
number: i64,
|
|
limit: i64,
|
|
offset: i64,
|
|
) -> Result<Vec<PrFile>, AppError> {
|
|
let user_uid = ctx.user().ok_or(AppError::Unauthorized)?;
|
|
let pr = self.resolve_pr(wk_name, repo_name, number).await?;
|
|
self.ensure_pr_readable(user_uid, &pr).await?;
|
|
let (limit, offset) = clamp_limit_offset(limit, offset);
|
|
sqlx::query_as::<_, PrFile>(
|
|
"SELECT id, pull_request_id, path, old_path, status, additions, deletions, changes, \
|
|
patch, created_at, updated_at \
|
|
FROM pr_file WHERE pull_request_id = $1 ORDER BY path ASC LIMIT $2 OFFSET $3",
|
|
)
|
|
.bind(pr.id)
|
|
.bind(limit)
|
|
.bind(offset)
|
|
.fetch_all(self.ctx.db.reader())
|
|
.await
|
|
.map_err(AppError::Database)
|
|
}
|
|
}
|