feagi_api/endpoints/
simulation.rs1use crate::common::ApiState;
12use crate::common::{ApiError, ApiResult, Json, State};
13use serde_json::{json, Value};
15use std::collections::HashMap;
16
17#[utoipa::path(
23 post,
24 path = "/v1/simulation/upload/string",
25 tag = "simulation",
26 responses(
27 (status = 200, description = "Stimulation script uploaded", body = HashMap<String, String>),
28 (status = 500, description = "Internal server error")
29 )
30)]
31pub async fn post_stimulation_upload(
32 State(_state): State<ApiState>,
33 Json(request): Json<HashMap<String, Value>>,
34) -> ApiResult<Json<HashMap<String, String>>> {
35 let _script = request
37 .get("stimulation_script")
38 .ok_or_else(|| ApiError::invalid_input("Missing 'stimulation_script' field"))?;
39
40 tracing::info!(target: "feagi-api", "Stimulation script upload requested");
42
43 Ok(Json(HashMap::from([(
44 "message".to_string(),
45 "Stimulation script uploaded successfully".to_string(),
46 )])))
47}
48
49#[utoipa::path(
51 post,
52 path = "/v1/simulation/reset",
53 tag = "simulation",
54 responses(
55 (status = 200, description = "Simulation reset", body = HashMap<String, String>),
56 (status = 500, description = "Internal server error")
57 )
58)]
59pub async fn post_reset(
60 State(_state): State<ApiState>,
61) -> ApiResult<Json<HashMap<String, String>>> {
62 Ok(Json(HashMap::from([(
65 "message".to_string(),
66 "Simulation reset successfully".to_string(),
67 )])))
68}
69
70#[utoipa::path(
72 get,
73 path = "/v1/simulation/status",
74 tag = "simulation",
75 responses(
76 (status = 200, description = "Simulation status", body = HashMap<String, serde_json::Value>),
77 (status = 500, description = "Internal server error")
78 )
79)]
80pub async fn get_status(State(_state): State<ApiState>) -> ApiResult<Json<HashMap<String, Value>>> {
81 let mut response = HashMap::new();
83 response.insert("active".to_string(), json!(false));
84 response.insert("stimulation_running".to_string(), json!(false));
85
86 Ok(Json(response))
87}
88
89#[utoipa::path(
91 get,
92 path = "/v1/simulation/stats",
93 tag = "simulation",
94 responses(
95 (status = 200, description = "Simulation statistics", body = HashMap<String, serde_json::Value>),
96 (status = 500, description = "Internal server error")
97 )
98)]
99pub async fn get_stats(State(_state): State<ApiState>) -> ApiResult<Json<HashMap<String, Value>>> {
100 let mut response = HashMap::new();
102 response.insert("total_stimulations".to_string(), json!(0));
103 response.insert("active_scripts".to_string(), json!(0));
104
105 Ok(Json(response))
106}
107
108#[utoipa::path(
110 post,
111 path = "/v1/simulation/config",
112 tag = "simulation",
113 responses(
114 (status = 200, description = "Simulation configured", body = HashMap<String, String>),
115 (status = 500, description = "Internal server error")
116 )
117)]
118pub async fn post_config(
119 State(_state): State<ApiState>,
120 Json(_request): Json<HashMap<String, Value>>,
121) -> ApiResult<Json<HashMap<String, String>>> {
122 Ok(Json(HashMap::from([(
125 "message".to_string(),
126 "Simulation configured successfully".to_string(),
127 )])))
128}