Skip to content

Commit 7b7541b

Browse files
committed
spaces
1 parent f4b2bc3 commit 7b7541b

File tree

4 files changed

+49
-39
lines changed

4 files changed

+49
-39
lines changed

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ async fn main() -> Result<(), Error> {
2929

3030
// get space
3131
let space = get_space(conf_url, token, "dev16".to_string()).await;
32+
println!("{:?}", space);
3233

3334
// CREATE PAGE
3435
// let space_key = "dev16";

src/model.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mod space;
1+
pub(crate) mod space;
22

33
pub mod models {
44
use serde_json::{json, Value};
@@ -11,12 +11,6 @@ pub mod models {
1111
pub position: Option<T>,
1212
}
1313

14-
// impl Extentions {
15-
// pub fn is_empty(option: Option<Extentions>) -> bool {
16-
// if option == None { true} else { false }
17-
// }
18-
// }
19-
2014
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
2115
#[allow(non_snake_case)]
2216
pub struct Content {

src/model/space.rs

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
1-
use serde::{Deserialize, Serialize};
2-
use crate::model::models::{Links};
1+
pub mod space {
2+
use serde::{Deserialize, Serialize};
33

4-
#[derive(Deserialize, Serialize, Debug)]
5-
pub struct Space {
6-
id: i16,
7-
key: String,
8-
name: String,
9-
#[serde(rename(serialize = "type"))]
10-
#[serde(rename(deserialize = "type"))]
11-
ttype: String,
12-
_links: Links,
13-
_expandable: SpaceExpandable
14-
}
4+
#[derive(Deserialize, Serialize, Debug)]
5+
pub struct Space {
6+
pub id: i64,
7+
pub key: String,
8+
pub name: String,
9+
#[serde(rename(serialize = "type"))]
10+
#[serde(rename(deserialize = "type"))]
11+
pub ttype: String,
12+
pub _links: SpaceLinks,
13+
pub _expandable: SpaceExpandable
14+
}
1515

16-
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
17-
#[allow(non_snake_case)]
18-
pub struct SpaceExpandable {
19-
pub metadata: String,
20-
pub icon: String,
21-
pub description: String,
22-
#[serde(rename(serialize = "retentionPolicy"))]
23-
#[serde(rename(deserialize = "retentionPolicy"))]
24-
pub retention_policy: String,
25-
pub homepage: String,
26-
}
16+
#[derive(Deserialize, Serialize, Debug)]
17+
pub struct SpaceLinks {
18+
pub webui: String,
19+
pub collection: String,
20+
pub base: String,
21+
#[serde(skip_serializing_if = "String::is_empty")]
22+
pub context: String,
23+
#[serde(rename(serialize = "self"))]
24+
#[serde(rename(deserialize = "self"))]
25+
#[serde(skip_serializing_if = "String::is_empty")]
26+
pub sself: String,
27+
}
2728

28-
#[derive(Deserialize, Serialize, Debug)]
29-
pub struct CreateSpace {
30-
key: String,
31-
name: String,
32-
}
29+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
30+
#[allow(non_snake_case)]
31+
pub struct SpaceExpandable {
32+
pub metadata: String,
33+
pub icon: String,
34+
pub description: String,
35+
#[serde(rename(serialize = "retentionPolicy"))]
36+
#[serde(rename(deserialize = "retentionPolicy"))]
37+
pub retention_policy: String,
38+
pub homepage: String,
39+
}
40+
41+
#[derive(Deserialize, Serialize, Debug)]
42+
pub struct CreateSpace {
43+
pub key: String,
44+
pub name: String,
45+
}
46+
47+
}

src/spaces.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub mod spaces {
2-
32
use reqwest::Response;
43
use crate::model::models::{Content, CreatePage, ContentResponse, SearchResults};
4+
use crate::model::space::space::{Space, CreateSpace};
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,7 +14,7 @@ pub mod spaces {
1414
return serde_json::from_str(body.as_str()).unwrap();
1515
}
1616

17-
pub async fn create_space(conf_url: &str, token: &str, page: CreateSpace) -> String {
17+
pub async fn create_space(conf_url: &str, token: &str, page: CreateSpace) -> Space {
1818
let request_url = format!("{conf_url}/rest/api/content/");
1919
let client = reqwest::Client::new();
2020
let res = client.post(&request_url)
@@ -24,6 +24,6 @@ pub mod spaces {
2424
.send()
2525
.await.unwrap();
2626
let created: String = res.text().await.unwrap();
27-
return created;
27+
return serde_json::from_str(created.as_str()).unwrap();
2828
}
2929
}

0 commit comments

Comments
 (0)