Can get the full list of relays through the API

This commit is contained in:
2024-07-24 23:35:58 +02:00
parent 4d5ba939d1
commit 73163e6e69
5 changed files with 43 additions and 2 deletions

View File

@ -107,10 +107,12 @@ pub async fn secure_server(energy_actor: EnergyActorAddr) -> anyhow::Result<()>
}))
.route("/", web::get().to(server_controller::secure_home))
// Web API
// Server controller
.route(
"/web_api/server/config",
web::get().to(server_controller::config),
)
// Auth controller
.route(
"/web_api/auth/password_auth",
web::post().to(auth_controller::password_auth),
@ -123,6 +125,7 @@ pub async fn secure_server(energy_actor: EnergyActorAddr) -> anyhow::Result<()>
"/web_api/auth/sign_out",
web::get().to(auth_controller::sign_out),
)
// Energy controller
.route(
"/web_api/energy/curr_consumption",
web::get().to(energy_controller::curr_consumption),
@ -131,6 +134,7 @@ pub async fn secure_server(energy_actor: EnergyActorAddr) -> anyhow::Result<()>
"/web_api/energy/cached_consumption",
web::get().to(energy_controller::cached_consumption),
)
// Devices controller
.route(
"/web_api/devices/list_pending",
web::get().to(devices_controller::list_pending),
@ -155,6 +159,11 @@ pub async fn secure_server(energy_actor: EnergyActorAddr) -> anyhow::Result<()>
"/web_api/device/{id}",
web::delete().to(devices_controller::delete_device),
)
// Relays API
.route(
"/web_api/relays/list",
web::get().to(relays_controller::get_list),
)
// Devices API
.route(
"/devices_api/utils/time",

View File

@ -1,4 +1,5 @@
pub mod auth_controller;
pub mod devices_controller;
pub mod energy_controller;
pub mod relays_controller;
pub mod server_controller;

View File

@ -0,0 +1,10 @@
use crate::energy::energy_actor;
use crate::server::custom_error::HttpResult;
use crate::server::WebEnergyActor;
use actix_web::HttpResponse;
/// Get the full list of relays
pub async fn get_list(actor: WebEnergyActor) -> HttpResult {
let list = actor.send(energy_actor::GetRelaysList).await?;
Ok(HttpResponse::Ok().json(list))
}