kun-galgame-vue/src/api/topic/reply.ts

67 lines
2 KiB
TypeScript
Raw Normal View History

2023-10-06 10:43:14 +00:00
import { fetchGet, fetchPost, fetchPut } from '@/utils/request'
2023-10-06 09:07:46 +00:00
// 将对象转为请求参数的函数
import objectToQueryParams from '@/utils/objectToQueryParams'
import * as Reply from './types/reply'
// 根据话题 tid 获取话题回复
export async function getRepliesByPidApi(
request: Reply.TopicReplyRequestData
): Promise<Reply.TopicReplyResponseData> {
2023-10-06 10:43:14 +00:00
const queryParams = objectToQueryParams(request, 'tid')
const url = `/topics/${request.tid}/replies?${queryParams}`
2023-10-06 09:07:46 +00:00
2023-10-06 10:43:14 +00:00
const response = await fetchGet<Reply.TopicReplyResponseData>(url)
2023-10-06 09:07:46 +00:00
2023-10-06 10:43:14 +00:00
return response
2023-10-06 09:07:46 +00:00
}
// 根据 tid 创建一个回复
export async function postReplyByPidApi(
request: Reply.TopicCreateReplyRequestData
): Promise<Reply.TopicCreateReplyResponseData> {
2023-10-06 10:43:14 +00:00
const url = `/topics/${request.tid}/reply`
const response = await fetchPost<Reply.TopicCreateReplyResponseData>(
url,
request
)
return response
}
// 推
export async function updateReplyUpvoteApi(
request: Reply.TopicUpvoteReplyRequestData
): Promise<Reply.TopicUpvoteReplyResponseData> {
const queryParams = objectToQueryParams(request, 'tid')
const url = `/topics/${request.tid}/reply/upvote?${queryParams}`
const response = fetchPut<Reply.TopicUpvoteReplyResponseData>(url)
return response
}
// 点赞
export async function updateReplyLikeApi(
request: Reply.TopicLikeReplyRequestData
): Promise<Reply.TopicLikeReplyResponseData> {
const queryParams = objectToQueryParams(request, 'tid')
const url = `/topics/${request.tid}/reply/like?${queryParams}`
const response = fetchPut<Reply.TopicLikeReplyResponseData>(url)
return response
}
// 点踩
export async function updateReplyDislikeApi(
request: Reply.TopicDislikeReplyRequestData
): Promise<Reply.TopicDislikeReplyResponseData> {
const queryParams = objectToQueryParams(request, 'tid')
const url = `/topics/${request.tid}/reply/dislike?${queryParams}`
const response = fetchPut<Reply.TopicDislikeReplyResponseData>(url)
return response
2023-10-06 09:07:46 +00:00
}