e8fa433588
- Replace 15 occurrences of unwrap_or("HEAD") with
unwrap_or(DEFAULT_REVISION) across 10 files
- All git API handlers and service methods now reference the shared
constant from models::common
57 lines
1.7 KiB
Rust
57 lines
1.7 KiB
Rust
use crate::models::common::DEFAULT_REVISION;
|
|
use actix_web::{HttpResponse, web};
|
|
use serde::Deserialize;
|
|
use utoipa::IntoParams;
|
|
|
|
use crate::api::response::{ApiErrorResponse, ApiResponse};
|
|
use crate::error::AppError;
|
|
use crate::service::AppService;
|
|
use crate::session::Session;
|
|
|
|
#[derive(Debug, Deserialize, IntoParams)]
|
|
pub struct PathParams {
|
|
pub workspace_name: String,
|
|
pub repo_name: String,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
|
pub struct CreateBranchBody {
|
|
pub name: String,
|
|
pub start_point: Option<String>,
|
|
}
|
|
|
|
#[utoipa::path(
|
|
post,
|
|
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/branches",
|
|
tag = "Repos",
|
|
operation_id = "repoCreateBranch",
|
|
params(PathParams),
|
|
request_body(content = CreateBranchBody),
|
|
responses(
|
|
(status = 201, description = "Branch created", body = ApiResponse<crate::pb::repo::Branch>),
|
|
(status = 400, description = "Invalid parameters", body = ApiErrorResponse),
|
|
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
|
(status = 404, description = "Repository not found", body = ApiErrorResponse),
|
|
),
|
|
security(("session_cookie" = []))
|
|
)]
|
|
pub async fn create_branch(
|
|
service: web::Data<AppService>,
|
|
session: Session,
|
|
path: web::Path<PathParams>,
|
|
body: web::Json<CreateBranchBody>,
|
|
) -> Result<HttpResponse, AppError> {
|
|
let start_point = body.start_point.as_deref().unwrap_or(DEFAULT_REVISION);
|
|
let result = service
|
|
.repo
|
|
.git_create_branch(
|
|
&session,
|
|
&path.workspace_name,
|
|
&path.repo_name,
|
|
&body.name,
|
|
start_point,
|
|
)
|
|
.await?;
|
|
Ok(HttpResponse::Created().json(ApiResponse::new(result)))
|
|
}
|