summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2024-04-09 14:41:15 +0200
committerFxQnLr <[email protected]>2024-04-09 14:41:15 +0200
commit25492f14292afc0fbfd442cd188bc93ffc3d293e (patch)
tree7289b06b79fbd2e25cbce2d4412c3390c8a12bf2
parenta91a2ca5c88403e905bf0f798393587fc4d900fa (diff)
downloadwebol-25492f14292afc0fbfd442cd188bc93ffc3d293e.tar
webol-25492f14292afc0fbfd442cd188bc93ffc3d293e.tar.gz
webol-25492f14292afc0fbfd442cd188bc93ffc3d293e.zip
Closes #21. Api desc are useful now...
-rw-r--r--src/main.rs3
-rw-r--r--src/routes/device.rs45
-rw-r--r--src/routes/start.rs10
3 files changed, 25 insertions, 33 deletions
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;
50 start::PayloadOld, 50 start::PayloadOld,
51 start::Payload, 51 start::Payload,
52 start::Response, 52 start::Response,
53 device::PutDevicePayload, 53 device::DevicePayload,
54 device::GetDevicePayload, 54 device::GetDevicePayload,
55 device::PostDevicePayload,
56 db::DeviceSchema, 55 db::DeviceSchema,
57 ) 56 )
58 ), 57 ),
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(
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)]
56pub async fn get( 56pub async fn get(
57 State(state): State<Arc<crate::AppState>>, 57 State(state): State<Arc<crate::AppState>>,
@@ -76,22 +76,31 @@ pub async fn get(
76} 76}
77 77
78#[derive(Deserialize, ToSchema)] 78#[derive(Deserialize, ToSchema)]
79#[deprecated]
79pub struct GetDevicePayload { 80pub struct GetDevicePayload {
80 id: String, 81 id: String,
81} 82}
82 83
84#[derive(Deserialize, ToSchema)]
85pub 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)]
92pub async fn put( 101pub 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)]
122pub 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)]
138pub async fn post( 139pub 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)]
167pub struct PostDevicePayload {
168 id: String,
169 mac: String,
170 broadcast_addr: String,
171 ip: String,
172}
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;
16 path = "/start", 16 path = "/start",
17 request_body = PayloadOld, 17 request_body = PayloadOld,
18 responses( 18 responses(
19 (status = 200, description = "List matching todos by query", body = [Response]) 19 (status = 200, description = "DEP", body = [Response])
20 ), 20 ),
21 security((), ("api_key" = [])) 21 security((), ("api_key" = []))
22)] 22)]
@@ -65,10 +65,10 @@ pub async fn start_payload(
65 path = "/start/{id}", 65 path = "/start/{id}",
66 request_body = Option<Payload>, 66 request_body = Option<Payload>,
67 responses( 67 responses(
68 (status = 200, description = "Start the device with the given id", body = [Response]) 68 (status = 200, description = "start the device with the given id", body = [Response])
69 ), 69 ),
70 params( 70 params(
71 ("id" = String, Path, description = "Device id") 71 ("id" = String, Path, description = "device id")
72 ), 72 ),
73 security((), ("api_key" = [])) 73 security((), ("api_key" = []))
74)] 74)]
@@ -84,10 +84,10 @@ pub async fn post(
84 get, 84 get,
85 path = "/start/{id}", 85 path = "/start/{id}",
86 responses( 86 responses(
87 (status = 200, description = "Start the device with the given id", body = [Response]) 87 (status = 200, description = "start the device with the given id", body = [Response])
88 ), 88 ),
89 params( 89 params(
90 ("id" = String, Path, description = "Device id") 90 ("id" = String, Path, description = "device id")
91 ), 91 ),
92 security((), ("api_key" = [])) 92 security((), ("api_key" = []))
93)] 93)]