Skip to content
Clone
1098df8
62 lines 1.9 KB Rust
use ::session::Session;
use export::http::{Path, State};
use export::rest::AppResponseData;
use crate::errors::{ApiError, GitApiError};
use crate::handler::{RepoPath, ensure_caller};
use crate::service::GitService;
use crate::service::repos::RepoDto;
#[utoipa::path(
post,
path = "/repos/{space_name}/{repo_name}/archive",
tag = "repos",
description = "将仓库标记为归档状态,禁止继续作为常规写入目标。",
params(RepoPath),
responses(
(status = 200, description = "archive repo", body = AppResponseData<RepoDto>)
)
)]
pub async fn archive_repo(
State(service): State<GitService>,
session: Session,
Path(path): Path<RepoPath>,
) -> Result<AppResponseData<RepoDto>, ApiError> {
let caller = ensure_caller(&session)?;
let ctx = service
.context(path.space_name, path.repo_name)
.await
.map_err(GitApiError::from)?;
let out = service
.set_repo_archived(&ctx, caller, true)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}
#[utoipa::path(
post,
path = "/repos/{space_name}/{repo_name}/unarchive",
tag = "repos",
description = "清除仓库的归档状态,使仓库恢复为可常规使用。",
params(RepoPath),
responses(
(status = 200, description = "unarchive repo", body = AppResponseData<RepoDto>)
)
)]
pub async fn unarchive_repo(
State(service): State<GitService>,
session: Session,
Path(path): Path<RepoPath>,
) -> Result<AppResponseData<RepoDto>, ApiError> {
let caller = ensure_caller(&session)?;
let ctx = service
.context(path.space_name, path.repo_name)
.await
.map_err(GitApiError::from)?;
let out = service
.set_repo_archived(&ctx, caller, false)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}