This commit is contained in:
2023-09-24 15:04:44 +00:00
parent 3b8926fb61
commit 25655b7bcb
5 changed files with 39 additions and 2 deletions

View File

@@ -84,6 +84,19 @@ async fn get_value(device_id: web::Path<String>, data: web::Data<AppState>) -> i
HttpResponse::Ok().json(messages)
}
#[get("/device/")]
async fn get_devices(data: web::Data<AppState>) -> impl Responder {
info!("GET - devices - Processing");
let devices = match data.db.get_devices().await {
Ok(devs) => devs,
Err(e) => {
error!("Getting Devices from DB failed \n{}", e);
return HttpResponse::InternalServerError().finish();
}
};
HttpResponse::Ok().json(devices)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init();
@@ -100,8 +113,9 @@ async fn main() -> std::io::Result<()> {
.service(get_telemetry)
.service(receive_value)
.service(get_value)
.service(get_devices)
})
.bind(("127.0.0.1", 8080))?
.bind(("0.0.0.0", 8080))?
.run()
.await
}