Skip to content

Commit 49c5a45

Browse files
committed
spaces
1 parent c17a705 commit 49c5a45

File tree

5 files changed

+82
-21
lines changed

5 files changed

+82
-21
lines changed

src/jira/models.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub mod jira_models {
2+
pub struct Issue {
3+
pub id: String,
4+
pub key: String,
5+
pub proj_key: String,
6+
pub summary: String,
7+
pub description: String,
8+
}
9+
}

src/main.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ async fn main() -> Result<(), Error> {
2020
println!("{}", "[ *** ] Starting");
2121

2222
// data
23-
let token = base64::engine::encode(b"admin:admin");
23+
let token = base64::encode(b"admin:admin");
2424
let conf_url = "http://localhost:8110";
2525

26+
2627
// =============== get page
2728
// let pages = get_descendants(conf_url, token, "1213317".to_string()).await;
2829
// pages.results.iter().for_each(|p| println!("{:?}", p.title));
@@ -33,14 +34,14 @@ async fn main() -> Result<(), Error> {
3334

3435
// =============== get spaces
3536
let mut space_service = SpaceService { spaces: vec![] };
36-
let vec1 = space_service.get_spaces(conf_url, token).await;
37+
let vec1 = space_service.get_spaces(&conf_url, &token).await;
3738
println!("{:?}", vec1);
3839

39-
// =============== CREATE PAGE
40-
// let space_key = "dev16";
41-
// let parent = 1213317;
40+
// =============== CREATE PAGEs
41+
// let space_key = "dev3";
42+
// let parent = 1212664;
4243
//
43-
// for a in 40..42 {
44+
// for a in 1..20 {
4445
// let title = format!("Rust page {a}");
4546
//
4647
// let req = CreatePage {

src/model.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
pub(crate) mod space;
22

33
pub mod models {
4+
use reqwest::Body;
45
use serde_json::{json, Value};
56
use serde::{Deserialize, Serialize};
7+
use crate::model::space::space::Space;
68

79
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
810
#[allow(non_snake_case)]
@@ -14,20 +16,39 @@ pub mod models {
1416
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
1517
#[allow(non_snake_case)]
1618
pub struct Content {
17-
id: String,
19+
pub id: String,
1820
#[serde(rename(serialize = "type"))]
1921
#[serde(rename(deserialize = "type"))]
20-
Type: String,
21-
status: String,
22-
title: String,
22+
pub Type: String,
23+
pub status: String,
24+
pub title: String,
25+
pub body: PageBody,
2326
#[serde(skip_serializing_if = "Option::is_none")]
24-
extensions: Option<Extentions<String>>,
27+
pub extensions: Option<Extentions<String>>,
2528
#[serde(rename(deserialize = "_expandable"))]
26-
_expandable: Expandable,
27-
version: Version,
29+
pub _expandable: Expandable,
30+
pub version: Version,
31+
pub space: Space,
2832
#[serde(rename(deserialize = "history"))]
29-
history: Option<CntHistory>,
30-
_links: ContentLinks,
33+
pub history: Option<CntHistory>,
34+
pub _links: ContentLinks,
35+
pub ancetors: Vec<CntAncestor>,
36+
}
37+
38+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
39+
#[allow(non_snake_case)]
40+
pub struct CntAncestor {
41+
pub id: String,
42+
#[serde(rename(serialize = "type"))]
43+
#[serde(rename(deserialize = "type"))]
44+
pub Type: String,
45+
pub status: String,
46+
pub title: String,
47+
#[serde(skip_serializing_if = "Option::is_none")]
48+
pub extensions: Option<Extentions<String>>,
49+
#[serde(rename(deserialize = "_expandable"))]
50+
pub _expandable: Expandable,
51+
pub _links: ContentLinks,
3152
}
3253

3354
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]

src/pages.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
pub mod page_service {
22
use reqwest::Response;
3-
use crate::model::models::{Content, CreatePage, ContentResponse, SearchResults};
4-
3+
use crate::model::models::{Content, CreatePage, ContentResponse, SearchResults, CreatePageSpace, PageBody, Storage};
54

65
pub async fn get_page(url: &str, token: String, id: String) -> Content {
7-
let request_url = format!("{url}/rest/api/content/{id}");
6+
let request_url = format!("{url}/rest/api/content/{id}?expand=body.storage.value,ancestors");
87
let client = reqwest::Client::new();
98
let resp: Response = client.get(&request_url)
109
.header("Authorization", format!("Basic {token}"))
@@ -61,13 +60,44 @@ pub mod page_service {
6160
}
6261

6362
// todo
64-
pub async fn copy_page(conf_url: &str, token: &str, page: CreatePage) -> String {
65-
return String::from("");
63+
pub async fn copy_page(conf_url: &str, token: &str, page_id: String) -> String {
64+
let req_url = format!("{conf_url}/rest/api/content/");
65+
let page = get_page(conf_url, token.to_string(), page_id).await;
66+
let client = reqwest::Client::new();
67+
let res = client.post(&req_url)
68+
.json(&CreatePage {
69+
title: page.id,
70+
ctype: String::from("page"),
71+
space: CreatePageSpace {
72+
key: page.space.key,
73+
},
74+
body: PageBody {
75+
storage: Storage {
76+
representation: String::from("storage"),
77+
value: page.body.storage.value,
78+
},
79+
},
80+
ancestors: page.a,
81+
})
82+
.header("Content-Type", "application/json")
83+
.header("Authorization", format!("Basic {token}"))
84+
.send()
85+
.await.unwrap();
86+
return res.text().await.unwrap();
6687
}
88+
6789
// todo
6890
pub async fn move_page(conf_url: &str, token: &str, page: CreatePage) -> String {
6991
return String::from("");
7092
}
7193

94+
// todo
95+
// {url}/rest/api/content/{id}/child/attachment
96+
pub async fn get_page_attachments() {
97+
// /download/attachments/{page_id}/{file]?version=1&modificationDate=1679505520993&api=v2
98+
99+
}
100+
}
101+
72102

73103
}

src/spaces.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub mod spaces {
99
}
1010

1111
impl SpaceService {
12-
pub async fn get_spaces(&self, url: &str, token: String) -> Vec<SpaceResult> {
12+
pub async fn get_spaces(&self, url: &str, token: &String) -> Vec<SpaceResult> {
1313
let request_url = format!("{url}/rest/api/space/");
1414
let client = reqwest::Client::new();
1515
let resp: Response = client.get(&request_url)

0 commit comments

Comments
 (0)