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:
34
server/src/http/api/cmd.rs
Normal file
34
server/src/http/api/cmd.rs
Normal 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()),
|
||||
))
|
||||
}
|
||||
Reference in New Issue
Block a user