diff --git a/src/api/comment.rs b/src/api/comment.rs index 40c531b..af84502 100644 --- a/src/api/comment.rs +++ b/src/api/comment.rs @@ -1,4 +1,4 @@ -use lemmy_api_common::{comment::{CommentResponse, CreateComment}, lemmy_db_schema::newtypes::{PostId, CommentId}}; +use lemmy_api_common::{comment::{CommentResponse, CreateComment, CreateCommentLike}, lemmy_db_schema::newtypes::{PostId, CommentId}}; use crate::util; @@ -17,3 +17,13 @@ pub fn create_comment( }; super::post("/comment", ¶ms) } + +// see posts.rs for possible score parameters +pub fn like_comment(comment_id: CommentId, score: i16) -> Result { + let params = CreateCommentLike { + comment_id, + score, + auth: util::get_auth_token().unwrap(), + }; + super::post("/comment/like", ¶ms) +} diff --git a/src/api/communities.rs b/src/api/communities.rs index 835e79e..f5f3e94 100644 --- a/src/api/communities.rs +++ b/src/api/communities.rs @@ -1,5 +1,7 @@ use lemmy_api_common::{community::{ListCommunities, ListCommunitiesResponse}, lemmy_db_schema::{SortType, SearchType}, lemmy_db_views_actor::structs::CommunityView}; +use crate::util; + use super::search; pub fn fetch_communities(page: i64, query: Option) -> std::result::Result, reqwest::Error> { @@ -7,6 +9,7 @@ pub fn fetch_communities(page: i64, query: Option) -> std::result::Resul let params = ListCommunities { sort: Some(SortType::TopMonth), page: Some(page), + auth: util::get_auth_token(), ..Default::default() }; diff --git a/src/api/community.rs b/src/api/community.rs index b58936d..6c703dc 100644 --- a/src/api/community.rs +++ b/src/api/community.rs @@ -1,14 +1,29 @@ -use lemmy_api_common::community::{GetCommunity, GetCommunityResponse}; +use lemmy_api_common::{community::{GetCommunity, GetCommunityResponse, CommunityResponse, FollowCommunity}, lemmy_db_schema::newtypes::CommunityId}; + +use crate::util; pub fn get_community(name: String) -> std::result::Result { let params = GetCommunity { name: Some(name), + auth: util::get_auth_token(), ..Default::default() }; super::get("/community", ¶ms) } +pub async fn follow_community( + community_id: i32, + follow: bool, +) -> Result { + let params = FollowCommunity { + community_id: CommunityId(community_id), + follow, + auth: util::get_auth_token().unwrap(), + }; + super::post("/community/follow", ¶ms) +} + pub fn default_community() -> GetCommunityResponse { serde_json::from_str(include_str!("../examples/community.json")).unwrap() } diff --git a/src/api/post.rs b/src/api/post.rs index 46833e4..a227e3f 100644 --- a/src/api/post.rs +++ b/src/api/post.rs @@ -1,21 +1,23 @@ -use lemmy_api_common::{post::{GetPost, GetPostResponse, PostResponse, CreatePost}, lemmy_db_schema::{newtypes::{PostId, CommunityId}, CommentSortType, ListingType}, comment::{GetComments, GetCommentsResponse}, lemmy_db_views::structs::CommentView}; +use lemmy_api_common::{post::{GetPost, GetPostResponse, PostResponse, CreatePost, CreatePostLike}, lemmy_db_schema::{newtypes::{PostId, CommunityId}, CommentSortType, ListingType}, comment::{GetComments, GetCommentsResponse}, lemmy_db_views::structs::CommentView}; use crate::util; -pub fn get_post(id: PostId) -> std::result::Result { +pub fn get_post(id: PostId) -> Result { let params = GetPost { id: Some(id), + auth: util::get_auth_token(), ..Default::default() }; super::get("/post", ¶ms) } -pub fn get_comments(post_id: PostId) -> std::result::Result, reqwest::Error> { +pub fn get_comments(post_id: PostId) -> Result, reqwest::Error> { let params = GetComments { post_id: Some(post_id), sort: Some(CommentSortType::Hot), type_: Some(ListingType::All), + auth: util::get_auth_token(), ..Default::default() }; @@ -45,3 +47,13 @@ pub fn create_post( }; super::post("/post", ¶ms) } + +// for score, use 1 to upvote, -1 to vote down and 0 to reset the user's voting +pub fn like_post(post_id: PostId, score: i16) -> Result { + let params = CreatePostLike { + post_id, + score, + auth: util::get_auth_token().unwrap(), + }; + super::post("/post/like", ¶ms) +} diff --git a/src/api/posts.rs b/src/api/posts.rs index eee5019..244c6a1 100644 --- a/src/api/posts.rs +++ b/src/api/posts.rs @@ -1,9 +1,12 @@ use lemmy_api_common::{post::{GetPostsResponse, GetPosts}, lemmy_db_views::structs::PostView}; +use crate::util; + pub fn list_posts(page: i64, community_name: Option) -> std::result::Result, reqwest::Error> { let params = GetPosts { page: Some(page), community_name, + auth: util::get_auth_token(), ..Default::default() }; diff --git a/src/api/search.rs b/src/api/search.rs index 6a9d045..d64c50d 100644 --- a/src/api/search.rs +++ b/src/api/search.rs @@ -1,11 +1,14 @@ use lemmy_api_common::{site::{SearchResponse, Search}, lemmy_db_schema::{SortType, SearchType}}; +use crate::util; + pub fn fetch_search(page: i64, query: String, search_type: Option) -> std::result::Result { let params = Search { q: query, sort: Some(SortType::TopMonth), page: Some(page), type_: search_type, + auth: util::get_auth_token(), ..Default::default() }; diff --git a/src/api/user.rs b/src/api/user.rs index 9bccc43..884d13e 100644 --- a/src/api/user.rs +++ b/src/api/user.rs @@ -1,9 +1,12 @@ use lemmy_api_common::{person::{GetPersonDetailsResponse, GetPersonDetails}}; +use crate::util; + pub fn get_user(username: String, page: i64) -> std::result::Result { let params = GetPersonDetails { page: Some(page), username: Some(username), + auth: util::get_auth_token(), ..Default::default() };