diff --git a/crates/backend/src/controller/node.rs b/crates/backend/src/controller/node.rs index 3c3bf74..6c638c2 100644 --- a/crates/backend/src/controller/node.rs +++ b/crates/backend/src/controller/node.rs @@ -1,8 +1,9 @@ -use actix_web::{error::ErrorInternalServerError, http::header::ACCEPT, web, Responder}; +use std::os::linux::raw::stat; +use actix_web::{error::ErrorInternalServerError, http::header::ACCEPT, web, HttpResponse, Responder}; use entity::node_group; use sea_orm::{ActiveModelTrait, ActiveValue, EntityTrait, IntoActiveModel}; use serde::{Deserialize, Serialize}; - +use uuid::Uuid; use crate::AppState; #[derive(Deserialize)] @@ -85,7 +86,10 @@ pub async fn create_node( coord_la: ActiveValue::Set(node.coord_la), coord_lo: ActiveValue::Set(node.coord_lo), temperature: ActiveValue::NotSet, - battery: ActiveValue::NotSet, + battery_minimum: ActiveValue::NotSet, + battery_current: ActiveValue::NotSet, + battery_maximum: ActiveValue::NotSet, + voltage: ActiveValue::NotSet, uptime: ActiveValue::NotSet, group: ActiveValue::Set(node.group), }; @@ -94,3 +98,19 @@ pub async fn create_node( Ok(web::Json(result)) } + +pub async fn delete_node( + state: web::Data, + path: web::Path, +) -> actix_web::Result { + let id = path.into_inner(); + + let db = &state.db; + + entity::node::Entity::delete_by_id(id) + .exec(db) + .await + .map_err(ErrorInternalServerError)?; + + Ok(HttpResponse::Ok().finish()) +} \ No newline at end of file diff --git a/crates/backend/src/routes.rs b/crates/backend/src/routes.rs index 42aebff..9e6d66d 100644 --- a/crates/backend/src/routes.rs +++ b/crates/backend/src/routes.rs @@ -19,6 +19,10 @@ pub fn config(cfg: &mut web::ServiceConfig) { .get(node::get_nodes) .post(node::create_node), ) + .service( + web::resource("/nodes/{id}") + .delete(node::delete_node) + ) .service(web::resource("/groups").post(node::create_group)), ); }