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>, data: web::Json, ) -> Result { let uuid = panels.create(&data.name, &data.data).await?; Ok(web::Json(uuid)) } #[get("/panel")] pub(super) async fn get_all( panels: web::Data>, ) -> Result { let result = panels.read_all().await?; Ok(web::Json(result)) } #[get("/panel/{id}")] pub(super) async fn get_one( panels: web::Data>, path: web::Path, ) -> Result { 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>, path: web::Path, data: web::Json, ) -> Result { panels.update(path.id, data.0).await?; Ok(web::Json(())) } #[delete("/panel/{id}")] pub(super) async fn delete( panels: web::Data>, path: web::Path, ) -> Result { panels.delete(path.id).await?; Ok(web::Json(())) }