1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use anyhow::Context;
use monitor_types::Group;
use serde_json::{json, Value};
use crate::MonitorClient;
impl MonitorClient {
pub async fn list_groups(&self, query: impl Into<Option<Value>>) -> anyhow::Result<Vec<Group>> {
self.get("/api/group/list", query.into())
.await
.context("failed at list groups")
}
pub async fn get_group(&self, group_id: &str) -> anyhow::Result<Group> {
self.get(&format!("/api/group/{group_id}"), Option::<()>::None)
.await
}
pub async fn create_group(&self, name: &str) -> anyhow::Result<Group> {
self.post("/api/group/create", json!({ "name": name }))
.await
.context(format!("failed at create group with name {name}"))
}
pub async fn create_full_group(&self, group: &Group) -> anyhow::Result<Group> {
self.post::<&Group, _>("/api/group/create_full", group)
.await
.context(format!("failed at creating full group"))
}
pub async fn delete_group(&self, id: &str) -> anyhow::Result<Group> {
self.delete::<(), _>(&format!("/api/group/{id}/delete"), None)
.await
.context(format!("failed at deleting group {id}"))
}
pub async fn update_group(&self, group: Group) -> anyhow::Result<Group> {
self.patch("/api/group/update", group)
.await
.context("failed at updating group")
}
}