diff --git a/src/api/topic/reply.ts b/src/api/topic/reply.ts index 1a986822..8fd3855c 100644 --- a/src/api/topic/reply.ts +++ b/src/api/topic/reply.ts @@ -1,4 +1,4 @@ -import { fetchGet, fetchPost } from '@/utils/request' +import { fetchGet, fetchPost, fetchPut } from '@/utils/request' // 将对象转为请求参数的函数 import objectToQueryParams from '@/utils/objectToQueryParams' import * as Reply from './types/reply' @@ -7,34 +7,60 @@ import * as Reply from './types/reply' export async function getRepliesByPidApi( request: Reply.TopicReplyRequestData ): Promise { - try { - const queryParams = objectToQueryParams(request, 'tid') - const url = `/topics/${request.tid}/replies?${queryParams}` + const queryParams = objectToQueryParams(request, 'tid') + const url = `/topics/${request.tid}/replies?${queryParams}` - const response = await fetchGet(url) + const response = await fetchGet(url) - return response - } catch (error) { - console.log(error) - throw new Error('Failed to fetch replies') - } + return response } // 根据 tid 创建一个回复 export async function postReplyByPidApi( request: Reply.TopicCreateReplyRequestData ): Promise { - try { - const url = `/topics/${request.tid}/reply` + const url = `/topics/${request.tid}/reply` - const response = await fetchPost( - url, - request - ) + const response = await fetchPost( + url, + request + ) - return response - } catch (error) { - console.log(error) - throw new Error('Failed to create reply') - } + 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 } diff --git a/src/api/topic/types/reply.ts b/src/api/topic/types/reply.ts index d4c91d3f..818dfc54 100644 --- a/src/api/topic/types/reply.ts +++ b/src/api/topic/types/reply.ts @@ -21,7 +21,7 @@ export interface TopicReply { to_user: TopicToUserInfo edited: number content: string - upvote: number[] + upvotes: number[] likes: number[] dislikes: number[] tags: string[] diff --git a/src/store/modules/topic.ts b/src/store/modules/topic.ts index 2f990910..fa10af6b 100644 --- a/src/store/modules/topic.ts +++ b/src/store/modules/topic.ts @@ -3,23 +3,21 @@ import { defineStore } from 'pinia' // 话题 import { getTopicByTidApi, + getRelatedTopicsByTagsApi, + getPopularTopicsByUserUidApi, + updateTopicUpvoteApi, + updateTopicLikeApi, + updateTopicDislikeApi, +} from '@/api' +import type { TopicDetailResponseData, TopicAsideOtherTagRequestData, - getRelatedTopicsByTagsApi, TopicAsideMasterRequestData, - getPopularTopicsByUserUidApi, TopicAsideResponseData, -} from '@/api' - -// 点赞等动作 -import { - updateTopicUpvoteApi, TopicUpvoteTopicRequestData, TopicUpvoteTopicResponseData, - updateTopicLikeApi, TopicLikeTopicRequestData, TopicLikeTopicResponseData, - updateTopicDislikeApi, TopicDislikeTopicRequestData, TopicDislikeTopicResponseData, } from '@/api' @@ -28,10 +26,22 @@ import { import { getRepliesByPidApi, postReplyByPidApi, + updateReplyUpvoteApi, + updateReplyLikeApi, + updateReplyDislikeApi, +} from '@/api' + +import type { TopicReplyRequestData, TopicReplyResponseData, TopicCreateReplyRequestData, TopicCreateReplyResponseData, + TopicUpvoteReplyRequestData, + TopicUpvoteReplyResponseData, + TopicLikeReplyRequestData, + TopicLikeReplyResponseData, + TopicDislikeReplyRequestData, + TopicDislikeReplyResponseData, } from '@/api' // 评论 @@ -154,7 +164,7 @@ export const useKUNGalgameTopicStore = defineStore({ }, // 获取回复 - async getReplies(tid: number): Promise { + async getReplies(tid: number): Promise { // 这里的默认值用于初始化 const requestData: TopicReplyRequestData = { tid: tid, @@ -179,6 +189,52 @@ export const useKUNGalgameTopicStore = defineStore({ return await postReplyByPidApi(requestData) }, + // 推回复 + async updateReplyUpvote( + tid: number, + toUid: number, + rid: number + ): Promise { + const requestData: TopicUpvoteReplyRequestData = { + tid: tid, + to_uid: toUid, + rid: rid, + } + return await updateReplyUpvoteApi(requestData) + }, + + // 点赞回复 + async updateReplyLike( + tid: number, + toUid: number, + rid: number, + isPush: boolean + ): Promise { + const requestData: TopicLikeReplyRequestData = { + tid: tid, + to_uid: toUid, + rid: rid, + isPush: isPush, + } + return await updateReplyLikeApi(requestData) + }, + + // 点踩回复 + async updateReplyDislike( + tid: number, + toUid: number, + rid: number, + isPush: boolean + ): Promise { + const requestData: TopicDislikeReplyRequestData = { + tid: tid, + to_uid: toUid, + rid: rid, + isPush: isPush, + } + return await updateReplyDislikeApi(requestData) + }, + // 获取评论 async getComments( tid: number, diff --git a/src/views/topic/components/reply/Reply.vue b/src/views/topic/components/reply/Reply.vue index 034aa1b4..c3049447 100644 --- a/src/views/topic/components/reply/Reply.vue +++ b/src/views/topic/components/reply/Reply.vue @@ -98,16 +98,17 @@ const handleClickComment = (rid: number) => { - +