Reviewed-on: #6 Co-authored-by: Sergey Savelyev <sergeysav.nn@gmail.com> Co-committed-by: Sergey Savelyev <sergeysav.nn@gmail.com>
35 lines
1.1 KiB
Rust
35 lines
1.1 KiB
Rust
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()),
|
|
))
|
|
}
|