From 25492f14292afc0fbfd442cd188bc93ffc3d293e Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Tue, 9 Apr 2024 14:41:15 +0200 Subject: Closes #21. Api desc are useful now... --- src/main.rs | 3 +-- src/routes/device.rs | 45 +++++++++++++++++++-------------------------- src/routes/start.rs | 10 +++++----- 3 files changed, 25 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index a8acc5f..70c67cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,9 +50,8 @@ mod wol; start::PayloadOld, start::Payload, start::Response, - device::PutDevicePayload, + device::DevicePayload, device::GetDevicePayload, - device::PostDevicePayload, db::DeviceSchema, ) ), diff --git a/src/routes/device.rs b/src/routes/device.rs index bbc832d..40b5cd8 100644 --- a/src/routes/device.rs +++ b/src/routes/device.rs @@ -49,9 +49,9 @@ pub async fn get_payload( (status = 200, description = "Get `Device` information", body = [Device]) ), params( - ("id" = String, Path, description = "Device id") + ("id" = String, Path, description = "device id") ), - security(("api_key" = [])) + security((), ("api_key" = [])) )] pub async fn get( State(state): State>, @@ -76,22 +76,31 @@ pub async fn get( } #[derive(Deserialize, ToSchema)] +#[deprecated] pub struct GetDevicePayload { id: String, } +#[derive(Deserialize, ToSchema)] +pub struct DevicePayload { + id: String, + mac: String, + broadcast_addr: String, + ip: String, +} + #[utoipa::path( put, path = "/device", - request_body = PutDevicePayload, + request_body = DevicePayload, responses( - (status = 200, description = "List matching todos by query", body = [DeviceSchema]) + (status = 200, description = "add device to storage", body = [DeviceSchema]) ), - security(("api_key" = [])) + security((), ("api_key" = [])) )] pub async fn put( State(state): State>, - Json(payload): Json, + Json(payload): Json, ) -> Result, Error> { info!( "add device {} ({}, {}, {})", @@ -118,26 +127,18 @@ pub async fn put( Ok(Json(json!(device))) } -#[derive(Deserialize, ToSchema)] -pub struct PutDevicePayload { - id: String, - mac: String, - broadcast_addr: String, - ip: String, -} - #[utoipa::path( post, path = "/device", - request_body = PostDevicePayload, + request_body = DevicePayload, responses( - (status = 200, description = "List matching todos by query", body = [DeviceSchema]) + (status = 200, description = "update device in storage", body = [DeviceSchema]) ), - security(("api_key" = [])) + security((), ("api_key" = [])) )] pub async fn post( State(state): State>, - Json(payload): Json, + Json(payload): Json, ) -> Result, Error> { info!( "edit device {} ({}, {}, {})", @@ -162,11 +163,3 @@ pub async fn post( Ok(Json(json!(device))) } - -#[derive(Deserialize, ToSchema)] -pub struct PostDevicePayload { - id: String, - mac: String, - broadcast_addr: String, - ip: String, -} diff --git a/src/routes/start.rs b/src/routes/start.rs index e74a943..ff3d1be 100644 --- a/src/routes/start.rs +++ b/src/routes/start.rs @@ -16,7 +16,7 @@ use uuid::Uuid; path = "/start", request_body = PayloadOld, responses( - (status = 200, description = "List matching todos by query", body = [Response]) + (status = 200, description = "DEP", body = [Response]) ), security((), ("api_key" = [])) )] @@ -65,10 +65,10 @@ pub async fn start_payload( path = "/start/{id}", request_body = Option, responses( - (status = 200, description = "Start the device with the given id", body = [Response]) + (status = 200, description = "start the device with the given id", body = [Response]) ), params( - ("id" = String, Path, description = "Device id") + ("id" = String, Path, description = "device id") ), security((), ("api_key" = [])) )] @@ -84,10 +84,10 @@ pub async fn post( get, path = "/start/{id}", responses( - (status = 200, description = "Start the device with the given id", body = [Response]) + (status = 200, description = "start the device with the given id", body = [Response]) ), params( - ("id" = String, Path, description = "Device id") + ("id" = String, Path, description = "device id") ), security((), ("api_key" = [])) )] -- cgit v1.2.3