Add the route to delete a relay
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
use crate::devices::device::{DeviceId, DeviceRelay};
|
||||
use crate::devices::device::{DeviceId, DeviceRelay, DeviceRelayID};
|
||||
use crate::energy::energy_actor;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
use crate::server::WebEnergyActor;
|
||||
@ -48,7 +48,7 @@ pub async fn create(actor: WebEnergyActor, req: web::Json<CreateDeviceRelayReque
|
||||
return Ok(HttpResponse::BadRequest().json("A relay with the same ID already exists!"));
|
||||
}
|
||||
|
||||
// Create the device
|
||||
// Create the device relay
|
||||
actor
|
||||
.send(energy_actor::CreateDeviceRelay(
|
||||
req.device_id.clone(),
|
||||
@ -58,3 +58,17 @@ pub async fn create(actor: WebEnergyActor, req: web::Json<CreateDeviceRelayReque
|
||||
|
||||
Ok(HttpResponse::Accepted().finish())
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct RelayIDInPath {
|
||||
id: DeviceRelayID,
|
||||
}
|
||||
|
||||
/// Delete an existing relay
|
||||
pub async fn delete(actor: WebEnergyActor, path: web::Path<RelayIDInPath>) -> HttpResult {
|
||||
actor
|
||||
.send(energy_actor::DeleteDeviceRelay(path.id))
|
||||
.await??;
|
||||
|
||||
Ok(HttpResponse::Accepted().finish())
|
||||
}
|
||||
|
Reference in New Issue
Block a user