Skip to content

Commit 88c7b04

Browse files
committed
labels
1 parent 37abd01 commit 88c7b04

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/labels.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
pub mod labels {
2+
use reqwest::Response;
3+
use serde_json::{json, Value};
4+
use serde::{Deserialize, Serialize};
5+
6+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
7+
#[allow(non_snake_case)]
8+
pub struct Label {
9+
#[serde(skip_serializing_if = "Option::is_none")]
10+
pub name: Option<String>,
11+
}
12+
13+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
14+
#[allow(non_snake_case)]
15+
pub struct AddLabel {
16+
pub prefix: String,
17+
pub name: String,
18+
}
19+
20+
pub struct LabelService {
21+
pub labels: Vec<Label>,
22+
}
23+
24+
impl LabelService {
25+
pub async fn add_label(url: &str, token: String, id: String, labels: Vec<String>) -> String {
26+
let mut labels_vec: Vec<AddLabel> = vec![];
27+
for label in labels {
28+
labels_vec.push(AddLabel {
29+
prefix: String::from("global"),
30+
name: label,
31+
});
32+
}
33+
let request_url = format!("{url}/rest/api/content/{id}/label/");
34+
let client = reqwest::Client::new();
35+
let resp: Response = client.post(&request_url)
36+
.body(labels_vec)
37+
.header("Authorization", format!("Basic {token}"))
38+
.header("Accept", "application/json")
39+
.header("Content-Type", "application/json")
40+
.send().await.unwrap();
41+
let body = resp.text().await.unwrap();
42+
return serde_json::from_str(body.as_str()).unwrap();
43+
}
44+
}
45+
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mod pages;
22
mod helpers;
33
mod model;
44
mod spaces;
5+
mod labels;
56

67
use std::fmt::format;
78
use std::future::Future;
@@ -23,7 +24,6 @@ async fn main() -> Result<(), Error> {
2324
let token = base64::encode(b"admin:admin");
2425
let conf_url = "http://localhost:8110";
2526

26-
2727
// =============== get page
2828
// let pages = get_descendants(conf_url, token, "1213317".to_string()).await;
2929
// pages.results.iter().for_each(|p| println!("{:?}", p.title));

0 commit comments

Comments
 (0)