Files
telemetry_visualization/server/src/http/api/panels.rs
Sergey Savelyev 788dd10a91 Replace gRPC Backend (#10)
**Rationale:**

Having two separate servers and communication methods resulted in additional maintenance & the need to convert often between backend & frontend data types.
By moving the backend communication off of gRPC and to just use websockets it both gives more control & allows for simplification of the implementation.

#8

**Changes:**

- Replaces gRPC backend.
  - New implementation automatically handles reconnect logic
- Implements an api layer
- Migrates examples to the api layer
- Implements a proc macro to make command handling easier
- Implements unit tests for the api layer (90+% coverage)
- Implements integration tests for the proc macro (90+% coverage)

Reviewed-on: #10
Co-authored-by: Sergey Savelyev <sergeysav.nn@gmail.com>
Co-committed-by: Sergey Savelyev <sergeysav.nn@gmail.com>
2026-01-01 10:11:53 -08:00

67 lines
1.7 KiB
Rust

use crate::http::error::HttpServerResultError;
use crate::panels::panel::PanelUpdate;
use crate::panels::PanelService;
use actix_web::{delete, get, post, put, web, Responder};
use serde::Deserialize;
use std::sync::Arc;
use uuid::Uuid;
#[derive(Deserialize)]
struct CreateParam {
name: String,
data: String,
}
#[derive(Deserialize)]
struct IdParam {
id: Uuid,
}
#[post("/panel")]
pub(super) async fn new(
panels: web::Data<Arc<PanelService>>,
data: web::Json<CreateParam>,
) -> Result<impl Responder, HttpServerResultError> {
let uuid = panels.create(&data.name, &data.data).await?;
Ok(web::Json(uuid))
}
#[get("/panel")]
pub(super) async fn get_all(
panels: web::Data<Arc<PanelService>>,
) -> Result<impl Responder, HttpServerResultError> {
let result = panels.read_all().await?;
Ok(web::Json(result))
}
#[get("/panel/{id}")]
pub(super) async fn get_one(
panels: web::Data<Arc<PanelService>>,
path: web::Path<IdParam>,
) -> Result<impl Responder, HttpServerResultError> {
let result = panels.read(path.id).await?;
match result {
Some(result) => Ok(web::Json(result)),
None => Err(HttpServerResultError::PanelUuidNotFound { uuid: path.id }),
}
}
#[put("/panel/{id}")]
pub(super) async fn set(
panels: web::Data<Arc<PanelService>>,
path: web::Path<IdParam>,
data: web::Json<PanelUpdate>,
) -> Result<impl Responder, HttpServerResultError> {
panels.update(path.id, data.0).await?;
Ok(web::Json(()))
}
#[delete("/panel/{id}")]
pub(super) async fn delete(
panels: web::Data<Arc<PanelService>>,
path: web::Path<IdParam>,
) -> Result<impl Responder, HttpServerResultError> {
panels.delete(path.id).await?;
Ok(web::Json(()))
}