use axum::Json; use axum::extract::{Path, State}; use export::rest::AppResponseData; use jwt::Session; use serde::{Deserialize, Serialize}; use crate::errors::{ApiError, GitApiError}; use crate::handler; use crate::service::GitService; use crate::service::refs::UpdateRefResultDto; #[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)] pub struct RefPath { pub space_name: String, pub repo_name: String, pub name: String, } #[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)] pub struct RefUpdateBody { pub new_oid: String, pub expected_oid: Option, } #[utoipa::path( patch, path = "/repos/{space_name}/{repo_name}/refs/{name}", tag = "refs", description = "更新完全限定引用的目标对象,可选 expected_oid 提供 CAS 语义。", params(RefPath), request_body = RefUpdateBody, responses( (status = 200, description = "update ref", body = AppResponseData) ) )] pub async fn refs_update( State(service): State, session: Session, Path(path): Path, Json(body): Json, ) -> Result, ApiError> { let _ = handler::require_writer( &service, &session, path.space_name.clone(), path.repo_name.clone(), ) .await?; let out = service .refs_update( path.space_name, path.repo_name, path.name, body.new_oid, body.expected_oid, ) .await .map_err(GitApiError::from)?; Ok(AppResponseData::ok(out)) }