Skip to content

Commit b2e30dc

Browse files
committed
spaces
1 parent 7b7541b commit b2e30dc

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

src/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use serde_json::{json, Value};
1111
use tokio::time::Instant;
1212
use crate::model::models::{Ancestor, CreatePage, CreatePageSpace, PageBody, Storage};
1313
use crate::pages::page_service::{create_page, get_children, get_descendants, get_page};
14-
use crate::spaces::spaces::get_space;
14+
use crate::spaces::spaces::{get_space, get_spaces};
1515

1616

1717
#[tokio::main]
@@ -28,8 +28,12 @@ async fn main() -> Result<(), Error> {
2828
// pages.results.iter().for_each(|p| println!("{:?}", p.title));
2929

3030
// get space
31-
let space = get_space(conf_url, token, "dev16".to_string()).await;
32-
println!("{:?}", space);
31+
// let space = get_space(conf_url, token, "dev16".to_string()).await;
32+
// println!("{:?}", space);
33+
34+
// get spaces
35+
let spaces = get_spaces(conf_url, token).await;
36+
println!("{:?}", spaces);
3337

3438
// CREATE PAGE
3539
// let space_key = "dev16";

src/model/space.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@ pub mod space {
1313
pub _expandable: SpaceExpandable
1414
}
1515

16+
#[derive(Deserialize, Serialize, Debug)]
17+
pub struct Spaces {
18+
pub results: Vec<SpaceResult>,
19+
pub start: i8,
20+
pub limit: i8,
21+
pub size: i8,
22+
pub _links: SpacesLinks,
23+
}
24+
25+
#[derive(Deserialize, Serialize, Debug)]
26+
pub struct SpaceResult {
27+
pub id: i64,
28+
pub key: String,
29+
pub name: String,
30+
#[serde(rename(serialize = "type"))]
31+
#[serde(rename(deserialize = "type"))]
32+
pub ttype: String,
33+
pub _links: SpaceResultLinks,
34+
pub _expandable: SpaceExpandable
35+
}
36+
1637
#[derive(Deserialize, Serialize, Debug)]
1738
pub struct SpaceLinks {
1839
pub webui: String,
@@ -26,6 +47,27 @@ pub mod space {
2647
pub sself: String,
2748
}
2849

50+
#[derive(Deserialize, Serialize, Debug)]
51+
pub struct SpaceResultLinks {
52+
pub webui: String,
53+
#[serde(rename(serialize = "self"))]
54+
#[serde(rename(deserialize = "self"))]
55+
#[serde(skip_serializing_if = "String::is_empty")]
56+
pub sself: String,
57+
}
58+
59+
#[derive(Deserialize, Serialize, Debug)]
60+
pub struct SpacesLinks {
61+
#[serde(rename(serialize = "self"))]
62+
#[serde(rename(deserialize = "self"))]
63+
#[serde(skip_serializing_if = "String::is_empty")]
64+
pub sself: String,
65+
pub next: String,
66+
pub base: String,
67+
#[serde(skip_serializing_if = "String::is_empty")]
68+
pub context: String,
69+
}
70+
2971
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
3072
#[allow(non_snake_case)]
3173
pub struct SpaceExpandable {

src/spaces.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub mod spaces {
22
use reqwest::Response;
33
use crate::model::models::{Content, CreatePage, ContentResponse, SearchResults};
4-
use crate::model::space::space::{Space, CreateSpace};
4+
use crate::model::space::space::{Space, CreateSpace, Spaces};
55

66
pub async fn get_space(url: &str, token: String, key: String) -> Space {
77
let request_url = format!("{url}/rest/api/space/{key}");
@@ -14,6 +14,17 @@ pub mod spaces {
1414
return serde_json::from_str(body.as_str()).unwrap();
1515
}
1616

17+
pub async fn get_spaces(url: &str, token: String) -> Spaces {
18+
let request_url = format!("{url}/rest/api/space/");
19+
let client = reqwest::Client::new();
20+
let resp: Response = client.get(&request_url)
21+
.header("Authorization", format!("Basic {token}"))
22+
.header("Accept", "application/json")
23+
.send().await.unwrap();
24+
let body = resp.text().await.unwrap();
25+
return serde_json::from_str(body.as_str()).unwrap();
26+
}
27+
1728
pub async fn create_space(conf_url: &str, token: &str, page: CreateSpace) -> Space {
1829
let request_url = format!("{conf_url}/rest/api/content/");
1930
let client = reqwest::Client::new();

0 commit comments

Comments
 (0)