fixes
This commit is contained in:
@@ -7,6 +7,8 @@ services:
|
||||
volumes:
|
||||
- ..:/workspace:cached
|
||||
command: sleep infinity
|
||||
ports:
|
||||
- 1234:8080
|
||||
|
||||
db:
|
||||
image: postgres
|
||||
@@ -16,6 +18,7 @@ services:
|
||||
POSTGRES_DB: iot
|
||||
ports:
|
||||
- 5432:5432
|
||||
restart: always
|
||||
command: ["postgres", "-c", "log_statement=all"]
|
||||
|
||||
adminer:
|
||||
|
||||
1
.gitea/workflows/release_actions.yaml
Normal file
1
.gitea/workflows/release_actions.yaml
Normal file
@@ -0,0 +1 @@
|
||||
name: Pull Request Created Action
|
||||
@@ -4,7 +4,7 @@ use log::{error, info};
|
||||
use sqlx::{migrate, pool, postgres::PgPoolOptions, query, query_as, PgPool, Pool, Postgres};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::schemas::{TelemetryMessage, TelemetryMessageFromDevice, ValueMessageFromDevice, ValueMessage};
|
||||
use crate::schemas::{TelemetryMessage, TelemetryMessageFromDevice, ValueMessageFromDevice, ValueMessage, Device};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Database {
|
||||
@@ -140,4 +140,17 @@ impl Database {
|
||||
|
||||
Ok(values)
|
||||
}
|
||||
|
||||
pub async fn get_devices(&self) -> Result<Vec<Device>, DatabaseError> {
|
||||
info!("Getting all devices");
|
||||
let devices = query_as!(
|
||||
Device,
|
||||
"SELECT id, display_name
|
||||
FROM Devices;",
|
||||
)
|
||||
.fetch_all(&self.conn_pool)
|
||||
.await?;
|
||||
|
||||
Ok(devices)
|
||||
}
|
||||
}
|
||||
|
||||
16
src/main.rs
16
src/main.rs
@@ -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
|
||||
}
|
||||
|
||||
@@ -31,3 +31,9 @@ pub struct ValueMessage {
|
||||
pub value_id: i32,
|
||||
pub timestamp: NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Serialize)]
|
||||
pub struct Device {
|
||||
pub display_name: Option<String>,
|
||||
pub id: String
|
||||
}
|
||||
Reference in New Issue
Block a user