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 RemotePath { pub space_name: String, pub repo_name: String, pub name: String, } #[derive(Debug, Clone, serde::Deserialize, utoipa::ToSchema)] pub struct RemoteAddBody { pub url: String, } #[utoipa::path( put, path = "/repos/{space_name}/{repo_name}/remotes/{name}", tag = "remotes", description = "新增或幂等更新远程地址,并校验 URL 协议与内网访问限制。", params(RemotePath), request_body = RemoteAddBody, responses( (status = 200, description = "remote created or url updated (idempotent)", body = AppResponseData) ) )] pub async fn upsert_remote( State(service): State, session: Session, Path(path): Path, Json(body): Json, ) -> Result, ApiError> { handler::require_writer( &service, &session, path.space_name.clone(), path.repo_name.clone(), ) .await?; service .remote_upsert(path.space_name, path.repo_name, path.name, body.url) .await .map_err(GitApiError::from)?; Ok(AppResponseData::ok(NoData)) }