use export::http::{Path, State}; use export::rest::{AppResponseData, NoData}; use token::Session; 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, } #[utoipa::path( put, path = "/repos/{space_name}/{repo_name}/branches/{name}/default", tag = "branches", description = "将指定分支设置为仓库默认分支,并同步 Git 与数据库。", params(BranchPath), responses( (status = 200, description = "set default branch", body = AppResponseData) ) )] pub async fn set_default_branch( State(service): State, session: Session, Path(path): Path, ) -> Result, ApiError> { let _ = handler::require_writer( &service, &session, path.space_name.clone(), path.repo_name.clone(), ) .await?; service .set_default_branch(path.space_name, path.repo_name, path.name) .await .map_err(GitApiError::from)?; Ok(AppResponseData::ok(NoData)) }