Add the route to update a relay
This commit is contained in:
@ -169,6 +169,10 @@ pub async fn secure_server(energy_actor: EnergyActorAddr) -> anyhow::Result<()>
|
||||
"/web_api/relay/create",
|
||||
web::post().to(relays_controller::create),
|
||||
)
|
||||
.route(
|
||||
"/web_api/relay/{id}",
|
||||
web::put().to(relays_controller::update),
|
||||
)
|
||||
.route(
|
||||
"/web_api/relay/{id}",
|
||||
web::delete().to(relays_controller::delete),
|
||||
|
@ -64,6 +64,27 @@ pub struct RelayIDInPath {
|
||||
id: DeviceRelayID,
|
||||
}
|
||||
|
||||
/// Update a relay configuration
|
||||
pub async fn update(
|
||||
actor: WebEnergyActor,
|
||||
mut req: web::Json<DeviceRelay>,
|
||||
path: web::Path<RelayIDInPath>,
|
||||
) -> HttpResult {
|
||||
req.id = path.id;
|
||||
|
||||
let list = actor.send(energy_actor::GetRelaysList).await?;
|
||||
|
||||
if let Some(e) = req.error(&list) {
|
||||
log::error!("Invalid relay update query: {e}");
|
||||
return Ok(HttpResponse::BadRequest().json(e));
|
||||
}
|
||||
|
||||
// Create the device relay
|
||||
actor.send(energy_actor::UpdateDeviceRelay(req.0)).await??;
|
||||
|
||||
Ok(HttpResponse::Accepted().finish())
|
||||
}
|
||||
|
||||
/// Delete an existing relay
|
||||
pub async fn delete(actor: WebEnergyActor, path: web::Path<RelayIDInPath>) -> HttpResult {
|
||||
actor
|
||||
|
Reference in New Issue
Block a user