use crate::orchestrate::deployer;
use axum::Json;
use axum::http::StatusCode;
use axum::response::IntoResponse;
use serde::Deserialize;
use serde_json::json;
use std::path::PathBuf;
#[derive(Deserialize)]
pub struct DeployBody {
pub pack_path: PathBuf,
#[serde(default = "default_name")]
pub name: String,
}
fn default_name() -> String {
"flow".to_string()
}
pub async fn post_deploy(Json(body): Json<DeployBody>) -> impl IntoResponse {
match deployer::build_bundle(&body.pack_path, &body.name, None) {
Ok(result) => (
StatusCode::OK,
Json(json!({
"bundle_path": result.bundle_path.display().to_string(),
"workspace_path": result.workspace_path.display().to_string(),
"bundle_id": result.bundle_id,
})),
)
.into_response(),
Err(e) => (
StatusCode::INTERNAL_SERVER_ERROR,
Json(json!({"error": e.to_string()})),
)
.into_response(),
}
}