Add routes to upvote and downvote posts and comments
This commit is contained in:
parent
9376e3a6c7
commit
ce9bf6d3ed
|
@ -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<CommentResponse, reqwest::Error> {
|
||||
let params = CreateCommentLike {
|
||||
comment_id,
|
||||
score,
|
||||
auth: util::get_auth_token().unwrap(),
|
||||
};
|
||||
super::post("/comment/like", ¶ms)
|
||||
}
|
||||
|
|
|
@ -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<String>) -> std::result::Result<Vec<CommunityView>, reqwest::Error> {
|
||||
|
@ -7,6 +9,7 @@ pub fn fetch_communities(page: i64, query: Option<String>) -> std::result::Resul
|
|||
let params = ListCommunities {
|
||||
sort: Some(SortType::TopMonth),
|
||||
page: Some(page),
|
||||
auth: util::get_auth_token(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
|
|
@ -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<GetCommunityResponse, reqwest::Error> {
|
||||
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<CommunityResponse, reqwest::Error> {
|
||||
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()
|
||||
}
|
||||
|
|
|
@ -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<GetPostResponse, reqwest::Error> {
|
||||
pub fn get_post(id: PostId) -> Result<GetPostResponse, reqwest::Error> {
|
||||
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<Vec<CommentView>, reqwest::Error> {
|
||||
pub fn get_comments(post_id: PostId) -> Result<Vec<CommentView>, 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<PostResponse, reqwest::Error> {
|
||||
let params = CreatePostLike {
|
||||
post_id,
|
||||
score,
|
||||
auth: util::get_auth_token().unwrap(),
|
||||
};
|
||||
super::post("/post/like", ¶ms)
|
||||
}
|
||||
|
|
|
@ -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<String>) -> std::result::Result<Vec<PostView>, reqwest::Error> {
|
||||
let params = GetPosts {
|
||||
page: Some(page),
|
||||
community_name,
|
||||
auth: util::get_auth_token(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
|
|
@ -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<SearchType>) -> std::result::Result<SearchResponse, reqwest::Error> {
|
||||
let params = Search {
|
||||
q: query,
|
||||
sort: Some(SortType::TopMonth),
|
||||
page: Some(page),
|
||||
type_: search_type,
|
||||
auth: util::get_auth_token(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
|
|
@ -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<GetPersonDetailsResponse, reqwest::Error> {
|
||||
let params = GetPersonDetails {
|
||||
page: Some(page),
|
||||
username: Some(username),
|
||||
auth: util::get_auth_token(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue