import { fetchGet, fetchPost, fetchPut } from '@/utils/request' // 将对象转为请求参数的函数 import objectToQueryParams from '@/utils/objectToQueryParams' import * as Reply from './types/reply' // 根据话题 tid 获取话题回复 export async function getRepliesByPidApi( request: Reply.TopicReplyRequestData ): Promise { const queryParams = objectToQueryParams(request, 'tid') const url = `/topics/${request.tid}/replies?${queryParams}` const response = await fetchGet(url) return response } // 根据 tid 创建一个回复 export async function postReplyByPidApi( request: Reply.TopicCreateReplyRequestData ): Promise { const url = `/topics/${request.tid}/reply` const response = await fetchPost( url, request ) return response } // 推 export async function updateReplyUpvoteApi( request: Reply.TopicUpvoteReplyRequestData ): Promise { const queryParams = objectToQueryParams(request, 'tid') const url = `/topics/${request.tid}/reply/upvote?${queryParams}` const response = fetchPut(url) return response } // 点赞 export async function updateReplyLikeApi( request: Reply.TopicLikeReplyRequestData ): Promise { const queryParams = objectToQueryParams(request, 'tid') const url = `/topics/${request.tid}/reply/like?${queryParams}` const response = fetchPut(url) return response } // 点踩 export async function updateReplyDislikeApi( request: Reply.TopicDislikeReplyRequestData ): Promise { const queryParams = objectToQueryParams(request, 'tid') const url = `/topics/${request.tid}/reply/dislike?${queryParams}` const response = fetchPut(url) return response } // 更新回复 export async function updateReplyApi( requestData: Reply.TopicUpdateReplyRequestData ): Promise { const url = `/topics/${requestData.tid}/reply` const response = fetchPut( url, requestData ) return response }