56417bd
use axum::Json;
use axum::extract::{Path, State};
use export::rest::AppResponseData;
use serde::{Deserialize, Serialize};
use session::Session;
use crate::errors::{ApiError, GitApiError};
use crate::handler::require_writer;
use crate::service::GitService;
use crate::service::refs::UpdateRefResultDto;
#[derive(Debug, Clone, serde::Deserialize)]
pub struct RefPath {
pub space_name: String,
pub repo_name: String,
pub name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RefUpdateBody {
pub new_oid: String,
pub expected_oid: Option<String>,
}
pub async fn refs_update(
State(service): State<GitService>,
session: Session,
Path(path): Path<RefPath>,
Json(body): Json<RefUpdateBody>,
) -> Result<AppResponseData<UpdateRefResultDto>, ApiError> {
let _ = require_writer(&service, &session, path.space_name.clone(), path.repo_name.clone()).await?;
let out = service
.refs_update(
path.space_name,
path.repo_name,
path.name,
body.new_oid,
body.expected_oid,
)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}