From 36fc91d676a1bcbc04144232ede62587d9c79dd4 Mon Sep 17 00:00:00 2001 From: Tarek Date: Sat, 10 Feb 2024 14:31:26 +0200 Subject: [PATCH] feat(httpd): add endpoints for coffee enable and disable Signed-off-by: Tarek --- coffee_httpd/src/httpd/server.rs | 30 ++++++++++++++++++++++++++++++ coffee_lib/src/types/mod.rs | 12 ++++++++++++ 2 files changed, 42 insertions(+) diff --git a/coffee_httpd/src/httpd/server.rs b/coffee_httpd/src/httpd/server.rs index 32a6fe33..dc429fd5 100644 --- a/coffee_httpd/src/httpd/server.rs +++ b/coffee_httpd/src/httpd/server.rs @@ -62,6 +62,8 @@ pub async fn run_httpd( .service(coffee_show) .service(coffee_search) .service(coffee_list_plugins_in_remote) + .service(coffee_disable) + .service(coffee_enable) .with_json_spec_at("/api/v1") .build() }) @@ -198,6 +200,34 @@ async fn coffee_search( handle_httpd_response!(result) } +#[api_v2_operation] +#[post("/disable")] +async fn coffee_disable( + data: web::Data, + body: Json, +) -> Result { + let plugin = &body.plugin; + + let mut coffee = data.coffee.lock().await; + let result = coffee.disable(plugin).await; + + handle_httpd_response!(result, "Plugin '{plugin}' disabled successfully") +} + +#[api_v2_operation] +#[post("/enable")] +async fn coffee_enable( + data: web::Data, + body: Json, +) -> Result { + let plugin = &body.plugin; + + let mut coffee = data.coffee.lock().await; + let result = coffee.enable(plugin).await; + + handle_httpd_response!(result, "Plugin '{plugin}' enabled successfully") +} + // this is just a hack to support swagger UI with https://paperclip-rs.github.io/paperclip/ // and the raw html is taken from https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/installation.md#unpkg #[get("/")] diff --git a/coffee_lib/src/types/mod.rs b/coffee_lib/src/types/mod.rs index 794dc53a..addca3d6 100644 --- a/coffee_lib/src/types/mod.rs +++ b/coffee_lib/src/types/mod.rs @@ -49,6 +49,18 @@ pub mod request { pub struct Search { pub plugin: String, } + + #[cfg(feature = "open-api")] + #[derive(Debug, Deserialize, Apiv2Schema, Serialize)] + pub struct Disable { + pub plugin: String, + } + + #[cfg(feature = "open-api")] + #[derive(Debug, Deserialize, Apiv2Schema, Serialize)] + pub struct Enable { + pub plugin: String, + } } // Definition of the response types.