Add authentication layer

This commit is contained in:
2024-06-29 14:43:56 +02:00
parent 738c53c8b9
commit e1739d9818
26 changed files with 1038 additions and 90 deletions

View File

@ -0,0 +1,23 @@
use crate::energy::{consumption, energy_actor};
use crate::server::custom_error::HttpResult;
use crate::server::WebEnergyActor;
use actix_web::HttpResponse;
#[derive(serde::Serialize)]
struct Consumption {
consumption: i32,
}
/// Get current energy consumption
pub async fn curr_consumption() -> HttpResult {
let consumption = consumption::get_curr_consumption().await?;
Ok(HttpResponse::Ok().json(Consumption { consumption }))
}
/// Get cached energy consumption
pub async fn cached_consumption(energy_actor: WebEnergyActor) -> HttpResult {
let consumption = energy_actor.send(energy_actor::GetCurrConsumption).await?;
Ok(HttpResponse::Ok().json(Consumption { consumption }))
}