From a91a2ca5c88403e905bf0f798393587fc4d900fa Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Mon, 8 Apr 2024 15:44:31 +0200 Subject: Closes #26. Addtional GET request for /start --- src/routes/start.rs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/routes') 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; responses( (status = 200, description = "List matching todos by query", body = [Response]) ), - security(("api_key" = [])) + security((), ("api_key" = [])) )] #[deprecated] pub async fn start_payload( @@ -70,12 +70,38 @@ pub async fn start_payload( params( ("id" = String, Path, description = "Device id") ), - security(("api_key" = [])) + security((), ("api_key" = [])) )] -pub async fn start( +pub async fn post( State(state): State>, Path(id): Path, payload: Option>, +) -> Result, Error> { + send_wol(state, &id, payload).await +} + +#[utoipa::path( + get, + path = "/start/{id}", + responses( + (status = 200, description = "Start the device with the given id", body = [Response]) + ), + params( + ("id" = String, Path, description = "Device id") + ), + security((), ("api_key" = [])) +)] +pub async fn get( + State(state): State>, + Path(id): Path, +) -> Result, Error> { + send_wol(state, &id, None).await +} + +async fn send_wol( + state: Arc, + id: &str, + payload: Option>, ) -> Result, Error> { info!("Start request for {id}"); let device = sqlx::query_as!( -- cgit v1.2.3