adds initial user defined panels
This commit is contained in:
67
server/src/http/api/panels.rs
Normal file
67
server/src/http/api/panels.rs
Normal file
@@ -0,0 +1,67 @@
|
||||
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;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct CreateParam {
|
||||
name: String,
|
||||
data: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct IdParam {
|
||||
id: String,
|
||||
}
|
||||
|
||||
#[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.value))
|
||||
}
|
||||
|
||||
#[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.clone().into()).await?;
|
||||
match result {
|
||||
Some(result) => Ok(web::Json(result)),
|
||||
None => Err(HttpServerResultError::PanelUuidNotFound {
|
||||
uuid: path.id.clone(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
#[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.clone().into(), 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.clone().into()).await?;
|
||||
Ok(web::Json(()))
|
||||
}
|
||||
Reference in New Issue
Block a user