Skip to content

Commit d680e68

Browse files
committed
feat: post comment api
1 parent 1a42725 commit d680e68

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/api/post/get_comment_list.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use crate::infra::http::{body_or_err, RequestBuilderExt};
2+
use crate::infra::json;
3+
use crate::infra::result::IntoResult;
4+
use crate::openapi;
5+
use anyhow::Result;
6+
use serde::{Deserialize, Serialize};
7+
use crate::api::post::Post;
8+
use crate::api::user::User;
9+
10+
#[derive(Clone, Debug, Serialize, Deserialize)]
11+
pub struct PostCommentEntry {
12+
#[serde(rename = "Id")]
13+
pub id: usize,
14+
#[serde(rename = "Body")]
15+
pub content: String,
16+
#[serde(rename = "Author")]
17+
pub user_name: String,
18+
#[serde(rename = "AuthorUrl")]
19+
pub user_home_url: String,
20+
#[serde(rename = "FaceUrl")]
21+
pub avatar_url: String,
22+
#[serde(rename = "Floor")]
23+
pub floor: usize,
24+
#[serde(rename = "DateAdded")]
25+
pub create_time: String,
26+
}
27+
28+
impl Post {
29+
pub async fn get_comment_list(&self, post_id: usize) -> Result<Vec<PostCommentEntry>> {
30+
let blog_app = User::new(self.pat.to_owned()).get_info().await?.blog_app;
31+
let client = reqwest::Client::new();
32+
33+
let req = {
34+
let url = openapi!("https://api.cnblogs.com/api/blogs/{}/posts/{}/comments", blog_app, post_id);
35+
client.get(url).pat_auth(&self.pat)
36+
};
37+
let resp = req.send().await?;
38+
39+
let entry_vec = {
40+
let body = body_or_err(resp).await?;
41+
json::deserialize::<Vec<PostCommentEntry>>(&body)?
42+
};
43+
44+
entry_vec.into_ok()
45+
}
46+
}

src/api/post/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod get_one;
66
pub mod get_one_raw;
77
pub mod search;
88
pub mod update;
9+
pub mod get_comment_list;
910

1011
pub struct Post {
1112
pat: String,

0 commit comments

Comments
 (0)