diff options
author | FxQnLr <[email protected]> | 2024-04-08 15:44:31 +0200 |
---|---|---|
committer | FxQnLr <[email protected]> | 2024-04-08 15:44:31 +0200 |
commit | a91a2ca5c88403e905bf0f798393587fc4d900fa (patch) | |
tree | 12b141ac2a50ec02e87c8d02ba06d7bec3f4c0e4 /src/routes/start.rs | |
parent | 52851787329c48c1e70f98a3610ad52fe1fa4aa4 (diff) | |
download | webol-a91a2ca5c88403e905bf0f798393587fc4d900fa.tar webol-a91a2ca5c88403e905bf0f798393587fc4d900fa.tar.gz webol-a91a2ca5c88403e905bf0f798393587fc4d900fa.zip |
Closes #26. Addtional GET request for /start
Diffstat (limited to 'src/routes/start.rs')
-rw-r--r-- | src/routes/start.rs | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/routes/start.rs b/src/routes/start.rs index c61d5a3..e74a943 100644 --- a/src/routes/start.rs +++ b/src/routes/start.rs | |||
@@ -18,7 +18,7 @@ use uuid::Uuid; | |||
18 | responses( | 18 | responses( |
19 | (status = 200, description = "List matching todos by query", body = [Response]) | 19 | (status = 200, description = "List matching todos by query", body = [Response]) |
20 | ), | 20 | ), |
21 | security(("api_key" = [])) | 21 | security((), ("api_key" = [])) |
22 | )] | 22 | )] |
23 | #[deprecated] | 23 | #[deprecated] |
24 | pub async fn start_payload( | 24 | pub async fn start_payload( |
@@ -70,13 +70,39 @@ pub async fn start_payload( | |||
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 | )] |
75 | pub async fn start( | 75 | pub async fn post( |
76 | State(state): State<Arc<crate::AppState>>, | 76 | State(state): State<Arc<crate::AppState>>, |
77 | Path(id): Path<String>, | 77 | Path(id): Path<String>, |
78 | payload: Option<Json<Payload>>, | 78 | payload: Option<Json<Payload>>, |
79 | ) -> Result<Json<Value>, Error> { | 79 | ) -> Result<Json<Value>, Error> { |
80 | send_wol(state, &id, payload).await | ||
81 | } | ||
82 | |||
83 | #[utoipa::path( | ||
84 | get, | ||
85 | path = "/start/{id}", | ||
86 | responses( | ||
87 | (status = 200, description = "Start the device with the given id", body = [Response]) | ||
88 | ), | ||
89 | params( | ||
90 | ("id" = String, Path, description = "Device id") | ||
91 | ), | ||
92 | security((), ("api_key" = [])) | ||
93 | )] | ||
94 | pub async fn get( | ||
95 | State(state): State<Arc<crate::AppState>>, | ||
96 | Path(id): Path<String>, | ||
97 | ) -> Result<Json<Value>, Error> { | ||
98 | send_wol(state, &id, None).await | ||
99 | } | ||
100 | |||
101 | async fn send_wol( | ||
102 | state: Arc<crate::AppState>, | ||
103 | id: &str, | ||
104 | payload: Option<Json<Payload>>, | ||
105 | ) -> Result<Json<Value>, Error> { | ||
80 | info!("Start request for {id}"); | 106 | info!("Start request for {id}"); |
81 | let device = sqlx::query_as!( | 107 | let device = sqlx::query_as!( |
82 | Device, | 108 | Device, |