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, pub branch_name: String, } #[utoipa::path( put, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/branches/{branch_name}/default", tag = "Repos", operation_id = "repoSetDefaultBranch", params(PathParams), responses( (status = 200, description = "Default branch set", body = ApiResponse), (status = 401, description = "Authentication required", body = ApiErrorResponse), (status = 404, description = "Branch not found", body = ApiErrorResponse), ), security(("session_cookie" = [])) )] pub async fn set_default_branch( service: web::Data, session: Session, path: web::Path, ) -> Result { // 1. Call gRPC to update the actual git HEAD ref let _ = service .repo .git_set_default_branch( &session, &path.workspace_name, &path.repo_name, &path.branch_name, ) .await; // 2. Update DB metadata (platform-level default branch tracking) service .repo .repo_set_default_branch_by_name( &session, &path.workspace_name, &path.repo_name, &path.branch_name, ) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new("Default branch set".to_string()))) }