Anticipate relay ID collision

This commit is contained in:
Pierre HUBERT 2024-08-27 22:35:07 +02:00
parent 87fb3360fb
commit 6028be92ef

View File

@ -39,6 +39,15 @@ pub async fn create(actor: WebEnergyActor, req: web::Json<CreateDeviceRelayReque
return Ok(HttpResponse::BadRequest().json("Too many relays for the target device!"));
}
if actor
.send(energy_actor::GetSingleRelay(req.relay.id))
.await?
.is_some()
{
log::error!("Invalid relay create query: A relay with the same ID already exists!");
return Ok(HttpResponse::BadRequest().json("A relay with the same ID already exists!"));
}
// Create the device
actor
.send(energy_actor::CreateDeviceRelay(