Can update device general information

This commit is contained in:
2024-07-22 22:19:48 +02:00
parent baf341d505
commit 4d5ba939d1
18 changed files with 546 additions and 147 deletions

View File

@ -1,4 +1,4 @@
use crate::devices::device::DeviceId;
use crate::devices::device::{DeviceGeneralInfo, DeviceId};
use crate::energy::energy_actor;
use crate::server::custom_error::HttpResult;
use crate::server::WebEnergyActor;
@ -54,6 +54,26 @@ pub async fn validate_device(actor: WebEnergyActor, id: web::Path<DeviceInPath>)
Ok(HttpResponse::Accepted().finish())
}
/// Update a device information
pub async fn update_device(
actor: WebEnergyActor,
id: web::Path<DeviceInPath>,
update: web::Json<DeviceGeneralInfo>,
) -> HttpResult {
if let Some(e) = update.error() {
return Ok(HttpResponse::BadRequest().json(e));
}
actor
.send(energy_actor::UpdateDeviceGeneralInfo(
id.id.clone(),
update.0.clone(),
))
.await??;
Ok(HttpResponse::Accepted().finish())
}
/// Delete a device
pub async fn delete_device(actor: WebEnergyActor, id: web::Path<DeviceInPath>) -> HttpResult {
actor