Skip to content
Clone
2f5d35e
43 lines 1.2 KB Rust
use axum::extract::{Path, State};
use export::rest::{AppResponseData, NoData};
use session_layer::Session;
use crate::errors::{ApiError, GitApiError};
use crate::handler::require_writer;
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<NoData>)
)
)]
pub async fn set_default_branch(
State(service): State<GitService>,
session: Session,
Path(path): Path<BranchPath>,
) -> Result<AppResponseData<NoData>, ApiError> {
let _ = 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))
}