Skip to content

Commit 36fc91d

Browse files
tareknaservincenzopalazzo
authored andcommitted
feat(httpd): add endpoints for coffee enable and disable
Signed-off-by: Tarek <[email protected]>
1 parent d002a26 commit 36fc91d

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

coffee_httpd/src/httpd/server.rs

+30
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ pub async fn run_httpd<T: ToSocketAddrs>(
6262
.service(coffee_show)
6363
.service(coffee_search)
6464
.service(coffee_list_plugins_in_remote)
65+
.service(coffee_disable)
66+
.service(coffee_enable)
6567
.with_json_spec_at("/api/v1")
6668
.build()
6769
})
@@ -198,6 +200,34 @@ async fn coffee_search(
198200
handle_httpd_response!(result)
199201
}
200202

203+
#[api_v2_operation]
204+
#[post("/disable")]
205+
async fn coffee_disable(
206+
data: web::Data<AppState>,
207+
body: Json<Disable>,
208+
) -> Result<HttpResponse, Error> {
209+
let plugin = &body.plugin;
210+
211+
let mut coffee = data.coffee.lock().await;
212+
let result = coffee.disable(plugin).await;
213+
214+
handle_httpd_response!(result, "Plugin '{plugin}' disabled successfully")
215+
}
216+
217+
#[api_v2_operation]
218+
#[post("/enable")]
219+
async fn coffee_enable(
220+
data: web::Data<AppState>,
221+
body: Json<Enable>,
222+
) -> Result<HttpResponse, Error> {
223+
let plugin = &body.plugin;
224+
225+
let mut coffee = data.coffee.lock().await;
226+
let result = coffee.enable(plugin).await;
227+
228+
handle_httpd_response!(result, "Plugin '{plugin}' enabled successfully")
229+
}
230+
201231
// this is just a hack to support swagger UI with https://paperclip-rs.github.io/paperclip/
202232
// and the raw html is taken from https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/installation.md#unpkg
203233
#[get("/")]

coffee_lib/src/types/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ pub mod request {
4949
pub struct Search {
5050
pub plugin: String,
5151
}
52+
53+
#[cfg(feature = "open-api")]
54+
#[derive(Debug, Deserialize, Apiv2Schema, Serialize)]
55+
pub struct Disable {
56+
pub plugin: String,
57+
}
58+
59+
#[cfg(feature = "open-api")]
60+
#[derive(Debug, Deserialize, Apiv2Schema, Serialize)]
61+
pub struct Enable {
62+
pub plugin: String,
63+
}
5264
}
5365

5466
// Definition of the response types.

0 commit comments

Comments
 (0)