File tree Expand file tree Collapse file tree 4 files changed +51
-21
lines changed Expand file tree Collapse file tree 4 files changed +51
-21
lines changed Original file line number Diff line number Diff line change @@ -2,8 +2,6 @@ use crate::api::ing::Ing;
2
2
use crate :: infra:: http:: { setup_auth, unit_or_err} ;
3
3
use crate :: openapi;
4
4
use anyhow:: Result ;
5
- use mime:: APPLICATION_JSON ;
6
- use reqwest:: header:: CONTENT_TYPE ;
7
5
use serde:: { Deserialize , Serialize } ;
8
6
9
7
impl Ing {
@@ -19,9 +17,7 @@ impl Ing {
19
17
let req = {
20
18
let url = openapi ! ( "/statuses/{}/comments" , ing_id) ;
21
19
let req = {
22
- let req = client
23
- . post ( url)
24
- . header ( CONTENT_TYPE , APPLICATION_JSON . to_string ( ) ) ;
20
+ let req = client. post ( url) ;
25
21
let body = {
26
22
#[ serde_with:: skip_serializing_none]
27
23
#[ derive( Clone , Debug , Serialize , Deserialize ) ]
@@ -32,14 +28,13 @@ impl Ing {
32
28
parent_comment_id : Option < usize > ,
33
29
content : String ,
34
30
}
35
- let body = Body {
31
+ Body {
36
32
reply_to,
37
33
parent_comment_id,
38
34
content,
39
- } ;
40
- serde_json:: to_string ( & body) ?
35
+ }
41
36
} ;
42
- req. body ( body)
37
+ req. json ( & body)
43
38
} ;
44
39
setup_auth ( req, & self . pat )
45
40
} ;
Original file line number Diff line number Diff line change @@ -3,8 +3,6 @@ use crate::infra::http::setup_auth;
3
3
use crate :: infra:: result:: IntoResult ;
4
4
use crate :: openapi;
5
5
use anyhow:: { bail, Result } ;
6
- use mime:: APPLICATION_JSON ;
7
- use reqwest:: header:: CONTENT_TYPE ;
8
6
use serde:: { Deserialize , Serialize } ;
9
7
use serde_json:: json;
10
8
use std:: ops:: Not ;
@@ -17,20 +15,16 @@ struct IngPubErr {
17
15
18
16
impl Ing {
19
17
pub async fn publish ( & self , content : & str ) -> Result < ( ) > {
20
- let body = json ! ( {
21
- "content" : content,
22
- "isPrivate" : false ,
23
- } )
24
- . to_string ( ) ;
25
-
26
18
let client = reqwest:: Client :: new ( ) ;
27
19
28
20
let req = {
29
21
let url = openapi ! ( "/statuses" ) ;
30
- let req = client
31
- . post ( url)
32
- . header ( CONTENT_TYPE , APPLICATION_JSON . to_string ( ) )
33
- . body ( body) ;
22
+ let body = json ! ( {
23
+ "content" : content,
24
+ "isPrivate" : false ,
25
+ } ) ;
26
+
27
+ let req = client. post ( url) . json ( & body) ;
34
28
setup_auth ( req, & self . pat )
35
29
} ;
36
30
Original file line number Diff line number Diff line change
1
+ use crate :: api:: post:: Post ;
2
+ use crate :: blog_backend;
3
+ use crate :: infra:: http:: { body_or_err, setup_auth} ;
4
+ use crate :: infra:: json;
5
+ use crate :: infra:: result:: IntoResult ;
6
+ use anyhow:: Result ;
7
+ use serde:: { Deserialize , Serialize } ;
8
+ use serde_json:: json;
9
+
10
+ impl Post {
11
+ pub async fn create ( & self , title : & str , body : & str , publish : bool ) -> Result < usize > {
12
+ let client = reqwest:: Client :: new ( ) ;
13
+
14
+ let req = {
15
+ let url = blog_backend ! ( "/posts" ) ;
16
+ let body = json ! ( {
17
+ "postType" : 1 ,
18
+ "title" : title,
19
+ "postBody" : body,
20
+ "isPublished" : publish
21
+ } ) ;
22
+ let req = client. post ( url) . json ( & body) ;
23
+ setup_auth ( req, & self . pat )
24
+ } ;
25
+
26
+ let resp = req. send ( ) . await ?;
27
+
28
+ let id = {
29
+ let json = body_or_err ( resp) . await ?;
30
+ #[ derive( Serialize , Deserialize , Debug ) ]
31
+ struct Body {
32
+ pub id : usize ,
33
+ }
34
+ let body = json:: deserialize :: < Body > ( & json) ?;
35
+ body. id
36
+ } ;
37
+
38
+ id. into_ok ( )
39
+ }
40
+ }
Original file line number Diff line number Diff line change
1
+ pub mod create;
1
2
pub mod del_one;
2
3
pub mod get_count;
3
4
pub mod get_meta_list;
You can’t perform that action at this time.
0 commit comments