1098df8
ZhenYi
refactor: streamline context handling by replacing space and repo name parameters with context references for improved clarity and consistency
1098df8
use ::session::Session;
use export::http::{Json, Path, State};
use export::rest::{AppResponseData, NoData};
use crate::errors::{ApiError, GitApiError};
use crate::handler;
use crate::service::GitService;
#[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)]
pub struct BranchPath {
pub space_name: String,
pub repo_name: String,
pub name: String,
}
#[derive(Debug, Clone, serde::Deserialize, utoipa::ToSchema)]
pub struct RenameBranchCmd {
pub new_name: String,
}
#[utoipa::path(
patch,
path = "/repos/{space_name}/{repo_name}/branches/{name}",
tag = "branches",
description = "重命名分支引用并同步更新分支元数据记录。",
params(BranchPath),
request_body = RenameBranchCmd,
responses(
(status = 200, description = "rename branch", body = AppResponseData<NoData>)
)
)]
pub async fn rename_branch(
State(service): State<GitService>,
session: Session,
Path(path): Path<BranchPath>,
Json(cmd): Json<RenameBranchCmd>,
) -> Result<AppResponseData<NoData>, ApiError> {
let (ctx, _) = handler::require_writer(
&service,
&session,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
service
.rename_branch(&ctx, path.name, cmd.new_name)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(NoData))
}