1098df8
ZhenYi
refactor: streamline context handling by replacing space and repo name parameters with context references for improved clarity and consistency
1098df8
use ::session::Session;
use export::http::{Json, Path, State};
use export::rest::AppResponseData;
use crate::errors::{ApiError, GitApiError};
use crate::handler;
use crate::service::GitService;
use crate::service::patches::AppliedPatchDto;
#[derive(Debug, Clone, serde::Deserialize, utoipa::ToSchema)]
pub struct PatchApplyBody {
pub patch: String,
pub base: String,
}
#[utoipa::path(
post,
path = "/repos/{space_name}/{repo_name}/patch/apply",
tag = "patches",
description = "预演补丁在指定基线上能否应用,不修改仓库。",
params(crate::handler::RepoPath),
request_body = PatchApplyBody,
responses(
(status = 200, description = "apply patch", body = AppResponseData<AppliedPatchDto>)
)
)]
pub async fn patch_apply(
State(service): State<GitService>,
session: Session,
Path(path): Path<crate::handler::RepoPath>,
Json(body): Json<PatchApplyBody>,
) -> Result<AppResponseData<AppliedPatchDto>, ApiError> {
let (ctx, _) = handler::resolve_reader(
&service,
&session,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
let out = service
.patch_apply(&ctx, body.patch, body.base)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}