From d8060da1180545df5d03a76cd2860191ecf87507 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Mon, 8 Apr 2024 10:42:47 +0200 Subject: Closes #23. Start request id parameter put in path --- src/routes/device.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/routes/device.rs') diff --git a/src/routes/device.rs b/src/routes/device.rs index d01d9f0..bbc832d 100644 --- a/src/routes/device.rs +++ b/src/routes/device.rs @@ -20,7 +20,7 @@ use utoipa::ToSchema; security(("api_key" = [])) )] #[deprecated] -pub async fn get( +pub async fn get_payload( State(state): State>, Json(payload): Json, ) -> Result, Error> { @@ -53,7 +53,7 @@ pub async fn get( ), security(("api_key" = [])) )] -pub async fn get_path( +pub async fn get( State(state): State>, Path(path): Path, ) -> Result, Error> { -- cgit v1.2.3 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/routes/device.rs') 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