Parse sync response from server

This commit is contained in:
2024-09-28 16:35:05 +02:00
parent 5704f2b57f
commit 58abf4ec9b
10 changed files with 205 additions and 23 deletions

View File

@ -2,6 +2,7 @@ use crate::app_config::AppConfig;
use crate::crypto::pki;
use crate::devices::device::{DeviceId, DeviceInfo};
use crate::energy::energy_actor;
use crate::energy::energy_actor::RelaySyncStatus;
use crate::server::custom_error::HttpResult;
use crate::server::WebEnergyActor;
use actix_web::{web, HttpResponse};
@ -138,6 +139,11 @@ struct Claims {
info: DeviceInfo,
}
#[derive(serde::Serialize)]
struct SyncResult {
relays: Vec<RelaySyncStatus>,
}
/// Synchronize device
pub async fn sync_device(body: web::Json<SyncRequest>, actor: WebEnergyActor) -> HttpResult {
// First, we need to extract device kid from query
@ -199,9 +205,9 @@ pub async fn sync_device(body: web::Json<SyncRequest>, actor: WebEnergyActor) ->
}
};
let res = actor
let relays = actor
.send(energy_actor::SynchronizeDevice(device.id, c.claims.info))
.await??;
Ok(HttpResponse::Ok().json(res))
Ok(HttpResponse::Ok().json(SyncResult { relays }))
}

View File

@ -1,3 +1,3 @@
pub mod files_utils;
pub mod math_utils;
pub mod math_utils;
pub mod time_utils;