omni_orchestrator/schemas/v1/api/apps/
update.rs1use super::super::super::db::queries as db;
2use super::types::UpdateAppRequest;
3use rocket::http::Status;
4use rocket::serde::json::{json, Json, Value};
5use rocket::{post, State};
6use std::sync::Arc;
7
8use crate::DatabaseManager;
9
10use libomni::types::db::v1 as types;
11use types::app::App;
12
13#[post("/platform/<platform_id>/apps/<app_id>", format = "json", data = "<app_request>")]
26pub async fn update_app(
27 platform_id: i64,
28 app_request: Json<UpdateAppRequest>,
29 db_manager: &State<Arc<DatabaseManager>>,
30 app_id: i64,
31) -> Result<Json<App>, (Status, Json<Value>)> {
32 let platform = match db::platforms::get_platform_by_id(db_manager.get_main_pool(), platform_id).await {
34 Ok(platform) => platform,
35 Err(_) => {
36 return Err((
37 Status::NotFound,
38 Json(json!({
39 "error": "Platform not found",
40 "message": format!("Platform with ID {} does not exist", platform_id)
41 }))
42 ));
43 }
44 };
45
46 let pool = match db_manager.get_platform_pool(&platform.name, platform_id).await {
48 Ok(pool) => pool,
49 Err(_) => {
50 return Err((
51 Status::InternalServerError,
52 Json(json!({
53 "error": "Database error",
54 "message": "Failed to connect to platform database"
55 }))
56 ));
57 }
58 };
59
60 match db::app::update_app(
61 &pool,
62 app_id,
63 Some(&app_request.name),
64 None,
65 None,
66 None,
67 None,
68 None,
69 ).await {
70 Ok(app) => Ok(Json(app)),
71 Err(_) => {
72 Err((
73 Status::InternalServerError,
74 Json(json!({
75 "error": "Database error",
76 "message": "Failed to update application"
77 }))
78 ))
79 }
80 }
81}