feat: init

This commit is contained in:
zhenyi
2026-06-07 11:30:56 +08:00
commit 563381c1ca
361 changed files with 41327 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
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)
}
}