Can delete a pending device

This commit is contained in:
2024-07-03 21:10:15 +02:00
parent 716af6219a
commit 2502ed6bcf
6 changed files with 120 additions and 9 deletions

View File

@ -1,7 +1,8 @@
use crate::devices::device::DeviceId;
use crate::energy::energy_actor;
use crate::server::custom_error::HttpResult;
use crate::server::WebEnergyActor;
use actix_web::HttpResponse;
use actix_web::{web, HttpResponse};
/// Get the list of pending (not accepted yet) devices
pub async fn list_pending(actor: WebEnergyActor) -> HttpResult {
@ -26,3 +27,17 @@ pub async fn list_validated(actor: WebEnergyActor) -> HttpResult {
Ok(HttpResponse::Ok().json(list))
}
#[derive(serde::Deserialize)]
pub struct DeviceInPath {
id: DeviceId,
}
/// Delete a device
pub async fn delete_device(actor: WebEnergyActor, id: web::Path<DeviceInPath>) -> HttpResult {
actor
.send(energy_actor::DeleteDevice(id.id.clone()))
.await??;
Ok(HttpResponse::Accepted().finish())
}