added delete node endpoint
This commit is contained in:
parent
190861da13
commit
db902f5549
|
@ -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<AppState>,
|
||||
path: web::Path<Uuid>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
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())
|
||||
}
|
|
@ -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)),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue