use std::path::PathBuf; use crate::rpcgit::commit::types::CommitStats; use axum::extract::{Path, Query, State}; use export::rest::AppResponseData; use jwt::Session; use crate::errors::{ApiError, GitApiError}; use crate::handler::resolve_reader; use crate::service::GitService; #[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)] pub struct StatsQuery { pub revision: String, #[serde(default)] pub path: Option, } #[utoipa::path( get, path = "/repos/{space_name}/{repo_name}/commits/stats", tag = "commits", description = "统计指定提交的文件变更与增删行数,可限定到单个路径。", params(crate::handler::RepoPath, StatsQuery), responses( (status = 200, description = "commit stats") ) )] pub async fn commit_stats( State(service): State, session: Session, Path(path): Path, Query(query): Query, ) -> Result, ApiError> { let _ = resolve_reader( &service, &session, path.space_name.clone(), path.repo_name.clone(), ) .await?; let out = service .commit_stats( path.space_name, path.repo_name, query.revision, query.path.map(PathBuf::from), ) .await .map_err(GitApiError::from)?; Ok(AppResponseData::ok(out)) }