omni_orchestrator/schemas/v1/api/instances/
get.rs1use std::sync::Arc;
2use crate::DatabaseManager;
3use rocket::get;
4use rocket::http::Status;
5use rocket::serde::json::{json, Json, Value};
6use rocket::State;
7use crate::schemas::v1::db::queries::{self as db};
8
9use libomni::types::db::v1 as types;
10use types::instance::Instance;
11
12#[get("/platform/<platform_id>/instances/<instance_id>")]
14pub async fn get_instance(
15 platform_id: i64,
16 instance_id: i64,
17 db_manager: &State<Arc<DatabaseManager>>,
18) -> Result<Json<Instance>, (Status, Json<Value>)> {
19 let platform = match db::platforms::get_platform_by_id(db_manager.get_main_pool(), platform_id).await {
21 Ok(platform) => platform,
22 Err(_) => {
23 return Err((
24 Status::NotFound,
25 Json(json!({
26 "error": "Platform not found",
27 "message": format!("Platform with ID {} does not exist", platform_id)
28 }))
29 ));
30 }
31 };
32
33 let pool = match db_manager.get_platform_pool(&platform.name, platform_id).await {
35 Ok(pool) => pool,
36 Err(_) => {
37 return Err((
38 Status::InternalServerError,
39 Json(json!({
40 "error": "Database error",
41 "message": "Failed to connect to platform database"
42 }))
43 ));
44 }
45 };
46
47 match db::instance::get_instance_by_id(&pool, instance_id).await {
48 Ok(instance) => Ok(Json(instance)),
49 Err(_) => {
50 Err((
51 Status::NotFound,
52 Json(json!({
53 "error": "Instance not found",
54 "message": format!("Instance with ID {} does not exist", instance_id)
55 }))
56 ))
57 }
58 }
59}