diff options
author | fxqnlr <[email protected]> | 2024-08-10 21:21:34 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-08-10 21:21:34 +0200 |
commit | 76c89b47fd74e069f9db73503a5131a5a60b8516 (patch) | |
tree | 5c6beb74abe986554b9b56cac4673b8e0c743e92 /src/routes | |
parent | 3e8866c07fbd6c2819ff3833e52ede9158a9862d (diff) | |
download | webol-76c89b47fd74e069f9db73503a5131a5a60b8516.tar webol-76c89b47fd74e069f9db73503a5131a5a60b8516.tar.gz webol-76c89b47fd74e069f9db73503a5131a5a60b8516.zip |
add 'devices' path to request all available devices
Diffstat (limited to 'src/routes')
-rw-r--r-- | src/routes/devices.rs | 24 |
1 files changed, 24 insertions, 0 deletions
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 @@ | |||
1 | use crate::error::Error; | ||
2 | use crate::storage::Device; | ||
3 | use axum::Json; | ||
4 | use serde_json::{json, Value}; | ||
5 | use tracing::{debug, info}; | ||
6 | |||
7 | #[utoipa::path( | ||
8 | get, | ||
9 | path = "/devices", | ||
10 | responses( | ||
11 | (status = 200, description = "Get an array of all `Device`s", body = [Vec<Device>]) | ||
12 | ), | ||
13 | security((), ("api_key" = [])) | ||
14 | )] | ||
15 | pub async fn get( | ||
16 | ) -> Result<Json<Value>, Error> { | ||
17 | info!("get all devices"); | ||
18 | |||
19 | let devices = Device::read_all()?; | ||
20 | |||
21 | debug!("got devices"); | ||
22 | |||
23 | Ok(Json(json!(devices))) | ||
24 | } | ||