diff options
Diffstat (limited to 'src/routes/devices.rs')
-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 | } | ||