From 76c89b47fd74e069f9db73503a5131a5a60b8516 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sat, 10 Aug 2024 21:21:34 +0200 Subject: add 'devices' path to request all available devices --- src/routes/devices.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/routes/devices.rs (limited to 'src/routes/devices.rs') diff --git a/src/routes/devices.rs b/src/routes/devices.rs new file mode 100644 index 0000000..616441c --- /dev/null +++ b/src/routes/devices.rs @@ -0,0 +1,24 @@ +use crate::error::Error; +use crate::storage::Device; +use axum::Json; +use serde_json::{json, Value}; +use tracing::{debug, info}; + +#[utoipa::path( + get, + path = "/devices", + responses( + (status = 200, description = "Get an array of all `Device`s", body = [Vec]) + ), + security((), ("api_key" = [])) +)] +pub async fn get( +) -> Result, Error> { + info!("get all devices"); + + let devices = Device::read_all()?; + + debug!("got devices"); + + Ok(Json(json!(devices))) +} -- cgit v1.2.3