omni_orchestrator/schemas/v1/api/
metadata.rs1use crate::schemas::v1::db::queries::{self as db};
2use rocket::{get, post, State};
3use sqlx::MySql;
4
5#[get("/meta/<key>")]
6pub async fn get_meta_value(
7 pool: &State<sqlx::Pool<MySql>>,
8 key: String,
9) -> (rocket::http::Status, String) {
10 let result = db::metadata::get_meta_value(pool, &key).await;
11 match result {
12 Ok(value) => (rocket::http::Status::Ok, value),
13 Err(e) => (rocket::http::Status::NotFound, format!("{e:#}")),
14 }
15}
16
17#[post("/meta/<key>", format = "json", data = "<value>")]
18pub async fn set_meta_value(
19 pool: &State<sqlx::Pool<MySql>>,
20 key: String,
21 value: String,
22) -> (rocket::http::Status, String) {
23 let result = db::metadata::set_meta_value(&**pool, &key, &value).await;
24 match result {
25 Ok(_) => (
26 rocket::http::Status::Ok,
27 "Meta value has been successfully set".to_string(),
28 ),
29 Err(e) => (rocket::http::Status::InternalServerError, format!("{e:#}")),
30 }
31}