diff options
author | FxQnLr <[email protected]> | 2024-04-09 22:07:10 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2024-04-09 22:07:10 +0200 |
commit | 907e5cb5bc48899b444f7fedd85af7b5974d9a2e (patch) | |
tree | 7206da6c47e6c9e2da0982344c8f76f1385e0ae2 /src/routes/device.rs | |
parent | 8dca7e83519b6c3531653cdedf60b2a14e1035b7 (diff) | |
parent | d91edaf85a1a179a915ac99e7c17b5647d8d9f7d (diff) | |
download | webol-907e5cb5bc48899b444f7fedd85af7b5974d9a2e.tar webol-907e5cb5bc48899b444f7fedd85af7b5974d9a2e.tar.gz webol-907e5cb5bc48899b444f7fedd85af7b5974d9a2e.zip |
Merge pull request #28 from FxQnLr/0.3.4
0.3.4
Diffstat (limited to 'src/routes/device.rs')
-rw-r--r-- | src/routes/device.rs | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/src/routes/device.rs b/src/routes/device.rs index d01d9f0..40b5cd8 100644 --- a/src/routes/device.rs +++ b/src/routes/device.rs | |||
@@ -20,7 +20,7 @@ use utoipa::ToSchema; | |||
20 | security(("api_key" = [])) | 20 | security(("api_key" = [])) |
21 | )] | 21 | )] |
22 | #[deprecated] | 22 | #[deprecated] |
23 | pub async fn get( | 23 | pub async fn get_payload( |
24 | State(state): State<Arc<crate::AppState>>, | 24 | State(state): State<Arc<crate::AppState>>, |
25 | Json(payload): Json<GetDevicePayload>, | 25 | Json(payload): Json<GetDevicePayload>, |
26 | ) -> Result<Json<Value>, Error> { | 26 | ) -> Result<Json<Value>, Error> { |
@@ -49,11 +49,11 @@ pub async fn get( | |||
49 | (status = 200, description = "Get `Device` information", body = [Device]) | 49 | (status = 200, description = "Get `Device` information", body = [Device]) |
50 | ), | 50 | ), |
51 | params( | 51 | params( |
52 | ("id" = String, Path, description = "Device id") | 52 | ("id" = String, Path, description = "device id") |
53 | ), | 53 | ), |
54 | security(("api_key" = [])) | 54 | security((), ("api_key" = [])) |
55 | )] | 55 | )] |
56 | pub async fn get_path( | 56 | pub async fn get( |
57 | State(state): State<Arc<crate::AppState>>, | 57 | State(state): State<Arc<crate::AppState>>, |
58 | Path(path): Path<String>, | 58 | Path(path): Path<String>, |
59 | ) -> Result<Json<Value>, Error> { | 59 | ) -> Result<Json<Value>, Error> { |
@@ -76,22 +76,31 @@ pub async fn get_path( | |||
76 | } | 76 | } |
77 | 77 | ||
78 | #[derive(Deserialize, ToSchema)] | 78 | #[derive(Deserialize, ToSchema)] |
79 | #[deprecated] | ||
79 | pub struct GetDevicePayload { | 80 | pub struct GetDevicePayload { |
80 | id: String, | 81 | id: String, |
81 | } | 82 | } |
82 | 83 | ||
84 | #[derive(Deserialize, ToSchema)] | ||
85 | pub struct DevicePayload { | ||
86 | id: String, | ||
87 | mac: String, | ||
88 | broadcast_addr: String, | ||
89 | ip: String, | ||
90 | } | ||
91 | |||
83 | #[utoipa::path( | 92 | #[utoipa::path( |
84 | put, | 93 | put, |
85 | path = "/device", | 94 | path = "/device", |
86 | request_body = PutDevicePayload, | 95 | request_body = DevicePayload, |
87 | responses( | 96 | responses( |
88 | (status = 200, description = "List matching todos by query", body = [DeviceSchema]) | 97 | (status = 200, description = "add device to storage", body = [DeviceSchema]) |
89 | ), | 98 | ), |
90 | security(("api_key" = [])) | 99 | security((), ("api_key" = [])) |
91 | )] | 100 | )] |
92 | pub async fn put( | 101 | pub async fn put( |
93 | State(state): State<Arc<crate::AppState>>, | 102 | State(state): State<Arc<crate::AppState>>, |
94 | Json(payload): Json<PutDevicePayload>, | 103 | Json(payload): Json<DevicePayload>, |
95 | ) -> Result<Json<Value>, Error> { | 104 | ) -> Result<Json<Value>, Error> { |
96 | info!( | 105 | info!( |
97 | "add device {} ({}, {}, {})", | 106 | "add device {} ({}, {}, {})", |
@@ -118,26 +127,18 @@ pub async fn put( | |||
118 | Ok(Json(json!(device))) | 127 | Ok(Json(json!(device))) |
119 | } | 128 | } |
120 | 129 | ||
121 | #[derive(Deserialize, ToSchema)] | ||
122 | pub struct PutDevicePayload { | ||
123 | id: String, | ||
124 | mac: String, | ||
125 | broadcast_addr: String, | ||
126 | ip: String, | ||
127 | } | ||
128 | |||
129 | #[utoipa::path( | 130 | #[utoipa::path( |
130 | post, | 131 | post, |
131 | path = "/device", | 132 | path = "/device", |
132 | request_body = PostDevicePayload, | 133 | request_body = DevicePayload, |
133 | responses( | 134 | responses( |
134 | (status = 200, description = "List matching todos by query", body = [DeviceSchema]) | 135 | (status = 200, description = "update device in storage", body = [DeviceSchema]) |
135 | ), | 136 | ), |
136 | security(("api_key" = [])) | 137 | security((), ("api_key" = [])) |
137 | )] | 138 | )] |
138 | pub async fn post( | 139 | pub async fn post( |
139 | State(state): State<Arc<crate::AppState>>, | 140 | State(state): State<Arc<crate::AppState>>, |
140 | Json(payload): Json<PostDevicePayload>, | 141 | Json(payload): Json<DevicePayload>, |
141 | ) -> Result<Json<Value>, Error> { | 142 | ) -> Result<Json<Value>, Error> { |
142 | info!( | 143 | info!( |
143 | "edit device {} ({}, {}, {})", | 144 | "edit device {} ({}, {}, {})", |
@@ -162,11 +163,3 @@ pub async fn post( | |||
162 | 163 | ||
163 | Ok(Json(json!(device))) | 164 | Ok(Json(json!(device))) |
164 | } | 165 | } |
165 | |||
166 | #[derive(Deserialize, ToSchema)] | ||
167 | pub struct PostDevicePayload { | ||
168 | id: String, | ||
169 | mac: String, | ||
170 | broadcast_addr: String, | ||
171 | ip: String, | ||
172 | } | ||