omni_orchestrator/schemas/v1/api/deployments/
get.rs1use 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::{get, State};
7
8use libomni::types::db::v1 as types;
9use types::deployment::Deployment;
10
11#[get("/platform/<platform_id>/deployments/<deployment_id>")]
13pub async fn get_deployment(
14 platform_id: i64,
15 deployment_id: i64,
16 db_manager: &State<Arc<DatabaseManager>>
17) -> Result<Json<Deployment>, (Status, Json<Value>)> {
18 let platform = match db::platforms::get_platform_by_id(db_manager.get_main_pool(), platform_id).await {
20 Ok(platform) => platform,
21 Err(_) => {
22 return Err((
23 Status::NotFound,
24 Json(json!({
25 "error": "Platform not found",
26 "message": format!("Platform with ID {} does not exist", platform_id)
27 }))
28 ));
29 }
30 };
31
32 let pool = match db_manager.get_platform_pool(&platform.name, platform_id).await {
34 Ok(pool) => pool,
35 Err(_) => {
36 return Err((
37 Status::InternalServerError,
38 Json(json!({
39 "error": "Database error",
40 "message": "Failed to connect to platform database"
41 }))
42 ));
43 }
44 };
45
46 match db::deployment::get_deployment_by_id(&pool, deployment_id).await {
47 Ok(deployment) => Ok(Json(deployment)),
48 Err(_) => Err((
49 Status::NotFound,
50 Json(json!({
51 "error": "Deployment not found",
52 "message": format!("Deployment with ID {} could not be found", deployment_id)
53 }))
54 )),
55 }
56}