Implement Commanding (#6)

Reviewed-on: #6
Co-authored-by: Sergey Savelyev <sergeysav.nn@gmail.com>
Co-committed-by: Sergey Savelyev <sergeysav.nn@gmail.com>
This commit was merged in pull request #6.
This commit is contained in:
2025-12-28 13:39:12 -08:00
committed by sergeysav
parent 8cfaf468e9
commit f658b55586
33 changed files with 1389 additions and 98 deletions

View File

@@ -0,0 +1,34 @@
use crate::command::service::CommandManagementService;
use crate::http::error::HttpServerResultError;
use actix_web::{get, post, web, Responder};
use std::sync::Arc;
#[post("/cmd/{name:[\\w\\d/_-]+}")]
pub(super) async fn send_command(
command_service: web::Data<Arc<CommandManagementService>>,
name: web::Path<String>,
parameters: web::Json<serde_json::Map<String, serde_json::Value>>,
) -> Result<impl Responder, HttpServerResultError> {
let result = command_service
.send_command(name.to_string(), parameters.into_inner())
.await?;
Ok(web::Json(result))
}
#[get("/cmd")]
pub(super) async fn get_all(
command_service: web::Data<Arc<CommandManagementService>>,
) -> Result<impl Responder, HttpServerResultError> {
Ok(web::Json(command_service.get_commands()?))
}
#[get("/cmd/{name:[\\w\\d/_-]+}")]
pub(super) async fn get_one(
command_service: web::Data<Arc<CommandManagementService>>,
name: web::Path<String>,
) -> Result<impl Responder, HttpServerResultError> {
Ok(web::Json(
command_service.get_command_definition(&name.to_string()),
))
}