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