This repository has been archived by the owner on Feb 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathpost.rs
93 lines (88 loc) · 2.08 KB
/
post.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use crate::api::{get, post, put};
use anyhow::Error;
use lemmy_api_common::{
lemmy_db_schema::{
newtypes::{CommunityId, PostId},
ListingType,
SortType,
},
post::{
CreatePost,
CreatePostReport,
EditPost,
GetPost,
GetPostResponse,
GetPosts,
GetPostsResponse,
PostReportResponse,
PostResponse,
},
sensitive::Sensitive,
};
pub async fn list_posts(
community_id: i32,
limit: i32,
page: i32,
auth: Option<Sensitive<String>>,
) -> Result<GetPostsResponse, Error> {
let params = GetPosts {
community_id: Some(CommunityId(community_id)),
sort: Some(SortType::NewComments),
limit: Some(limit.into()),
page: Some(page.into()),
type_: Some(ListingType::All),
auth,
..Default::default()
};
get("/post/list", ¶ms).await
}
pub async fn get_post(id: i32, auth: Option<Sensitive<String>>) -> Result<GetPostResponse, Error> {
let params = GetPost {
id: Some(PostId(id)),
comment_id: None,
auth,
};
get("/post", ¶ms).await
}
pub async fn create_post(
name: String,
body: String,
community_id: i32,
auth: Sensitive<String>,
) -> Result<PostResponse, Error> {
let params = CreatePost {
name,
body: Some(body),
community_id: CommunityId(community_id),
auth,
..Default::default()
};
post("/post", ¶ms).await
}
pub async fn edit_post(
name: String,
body: String,
post_id: i32,
auth: Sensitive<String>,
) -> Result<PostResponse, Error> {
let params = EditPost {
post_id: PostId(post_id),
name: Some(name),
body: Some(body),
auth,
..Default::default()
};
put("/post", ¶ms).await
}
pub async fn report_post(
post_id: i32,
reason: String,
auth: Sensitive<String>,
) -> Result<PostReportResponse, Error> {
let params = CreatePostReport {
post_id: PostId(post_id),
reason,
auth,
};
post("/post/report", ¶ms).await
}