56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import apiClient from './client'
|
|
import type { Comment, ApiResponse, PaginatedResponse } from '@/types'
|
|
|
|
// 评论查询参数
|
|
export interface CommentQueryParams {
|
|
page?: number
|
|
page_size?: number
|
|
keyword?: string // 搜索关键词(内容)
|
|
post_id?: string // 关联帖子ID筛选
|
|
author_id?: string // 评论者ID筛选
|
|
status?: string // 状态筛选
|
|
start_date?: string // 开始日期
|
|
end_date?: string // 结束日期
|
|
}
|
|
|
|
// 评论详情(包含更多上下文)
|
|
export interface CommentDetail extends Comment {
|
|
parent_id?: string
|
|
reply_to_user?: {
|
|
id: string
|
|
username: string
|
|
nickname: string
|
|
}
|
|
post?: {
|
|
id: string
|
|
title: string
|
|
}
|
|
ip_address?: string
|
|
device_info?: string
|
|
}
|
|
|
|
// 评论管理API
|
|
export const commentsApi = {
|
|
// 获取评论列表(分页、搜索、筛选)
|
|
getComments: (params: CommentQueryParams) =>
|
|
apiClient.get<ApiResponse<PaginatedResponse<Comment>>>('/admin/comments', { params }),
|
|
|
|
// 获取评论详情
|
|
getCommentById: (id: string) =>
|
|
apiClient.get<ApiResponse<CommentDetail>>(`/admin/comments/${id}`),
|
|
|
|
// 删除评论
|
|
deleteComment: (id: string) =>
|
|
apiClient.delete<ApiResponse<void>>(`/admin/comments/${id}`),
|
|
|
|
// 批量删除评论
|
|
batchDeleteComments: (ids: string[]) =>
|
|
apiClient.post<ApiResponse<void>>('/admin/comments/batch-delete', { ids }),
|
|
|
|
// 获取帖子的评论列表
|
|
getCommentsByPost: (postId: string, params?: Omit<CommentQueryParams, 'post_id'>) =>
|
|
apiClient.get<ApiResponse<PaginatedResponse<Comment>>>(`/admin/comments/post/${postId}`, { params }),
|
|
}
|
|
|
|
export default commentsApi
|