omni_orchestrator/schemas/v1/api/deployments/
delete.rs

1use std::sync::Arc;
2use crate::DatabaseManager;
3use super::super::super::db::queries as db;
4use rocket::http::Status;
5use rocket::serde::json::{json, Json, Value};
6use rocket::{delete, State};
7
8/// Delete a specific deployment.
9#[delete("/platform/<platform_id>/deployments/<deployment_id>")]
10pub async fn delete_deployment(
11    platform_id: i64,
12    deployment_id: i64,
13    db_manager: &State<Arc<DatabaseManager>>,
14) -> Result<Json<Value>, (Status, Json<Value>)> {
15    // Get platform information
16    let platform = match db::platforms::get_platform_by_id(db_manager.get_main_pool(), platform_id).await {
17        Ok(platform) => platform,
18        Err(_) => {
19            return Err((
20                Status::NotFound,
21                Json(json!({
22                    "error": "Platform not found",
23                    "message": format!("Platform with ID {} does not exist", platform_id)
24                }))
25            ));
26        }
27    };
28
29    // Get platform-specific database pool
30    let pool = match db_manager.get_platform_pool(&platform.name, platform_id).await {
31        Ok(pool) => pool,
32        Err(_) => {
33            return Err((
34                Status::InternalServerError,
35                Json(json!({
36                    "error": "Database error",
37                    "message": "Failed to connect to platform database"
38                }))
39            ));
40        }
41    };
42
43    match db::deployment::delete_deployment(&pool, deployment_id).await {
44        Ok(_) => Ok(Json(json!({ "status": "deleted" }))),
45        Err(e) => Err((
46            Status::InternalServerError, 
47            Json(json!({
48                "error": "Database error",
49                "message": e.to_string()
50            }))
51        )),
52    }
53}