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/routes/device.rs | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) (limited to 'src/routes/device.rs') 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, -} -- cgit v1.2.3