Skip to content
Clone
4dc6d37
44 lines 1.2 KB Rust
use axum::Json;
use axum::extract::{Path, State};
use export::rest::{AppResponseData, NoData};
use session::Session;
use crate::errors::{ApiError, GitApiError};
use crate::handler::require_writer;
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(
post,
path = "/repos/{space_name}/{repo_name}/remotes/{name}",
tag = "remotes",
params(RemotePath),
request_body = RemoteAddBody,
responses(
(status = 200, description = "add remote", body = AppResponseData<NoData>)
)
)]
pub async fn add(
State(service): State<GitService>,
session: Session,
Path(path): Path<RemotePath>,
Json(body): Json<RemoteAddBody>,
) -> Result<AppResponseData<NoData>, ApiError> {
require_writer(&service, &session, path.space_name.clone(), path.repo_name.clone()).await?;
service
.remote_add(path.space_name, path.repo_name, path.name, body.url)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(NoData))
}