f934c68
use ::session::AuthedUser;
use api::http::{Json, Path, State};
use api::rest::AppResponseData;
use crate::errors::{ApiError, GitApiError};
use crate::handler;
use crate::service::GitService;
use crate::service::branches::{BranchDto, CreateBranchCmd};
#[utoipa::path(
post,
path = "/repos/{space_name}/{repo_name}/branches",
tag = "branches",
description = "从指定起点创建新分支引用并更新分支元数据。",
params(crate::handler::RepoPath),
request_body = CreateBranchCmd,
responses(
(status = 200, description = "create branch", body = AppResponseData<BranchDto>)
)
)]
pub async fn create_branch(
State(service): State<GitService>,
AuthedUser(uid): AuthedUser,
Path(path): Path<crate::handler::RepoPath>,
Json(cmd): Json<CreateBranchCmd>,
) -> Result<AppResponseData<BranchDto>, ApiError> {
let (ctx, _) = handler::require_writer(
&service,
uid,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
let out = service
.create_branch(&ctx, cmd)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}