feat: 评论完了
This commit is contained in:
85
src/services/commentServices.ts
Normal file
85
src/services/commentServices.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import httpService from "./httpService";
|
||||
import type { ApiResponse } from "./httpService";
|
||||
|
||||
export interface CommentResponse {
|
||||
rows: Comment[]
|
||||
count: number
|
||||
}
|
||||
|
||||
export interface UserInfo {
|
||||
id: number
|
||||
nickname: string
|
||||
avatar_url: string
|
||||
}
|
||||
|
||||
export type BaseComment<T = {}> = {
|
||||
create_time: string
|
||||
last_modify_time: string
|
||||
id: number
|
||||
game_id: number
|
||||
user_id: number
|
||||
parent_id: number | null
|
||||
reply_to_user_id: number | null
|
||||
content: string
|
||||
like_count: number
|
||||
reply_count: number
|
||||
user: UserInfo
|
||||
is_liked?: boolean
|
||||
} & T
|
||||
|
||||
export type ReplyComment = BaseComment<{
|
||||
parent_id: number
|
||||
reply_to_user_id: number
|
||||
reply_to_user: UserInfo
|
||||
}>
|
||||
|
||||
export type Comment = BaseComment<{
|
||||
replies: ReplyComment[]
|
||||
}>
|
||||
|
||||
// 接口响应
|
||||
export interface ReplyCommentResponse {
|
||||
count: number
|
||||
rows: ReplyComment[]
|
||||
}
|
||||
|
||||
export interface ToggleLikeType {
|
||||
is_liked: boolean,
|
||||
like_count: number,
|
||||
message: string
|
||||
}
|
||||
|
||||
// 评论管理类
|
||||
class CommentService {
|
||||
// 查询评论列表
|
||||
async getComments(req: { game_id: number, page: number, pageSize: number }): Promise<ApiResponse<CommentResponse>> {
|
||||
return httpService.post("/comments/list", req, { showLoading: true });
|
||||
}
|
||||
|
||||
// 发表评论
|
||||
async createComment(req: { game_id: number, content: string }): Promise<ApiResponse<BaseComment>> {
|
||||
return httpService.post("/comments/create", req, { showLoading: true });
|
||||
}
|
||||
|
||||
// 回复评论
|
||||
async replyComment(req: { parent_id: number, reply_to_user_id: number, content: string }): Promise<ApiResponse<ReplyComment>> {
|
||||
return httpService.post("/comments/reply", req, { showLoading: true });
|
||||
}
|
||||
|
||||
// 点赞取消点赞评论
|
||||
async toggleLike(req: { comment_id: number }): Promise<ApiResponse<ToggleLikeType>> {
|
||||
return httpService.post("/comments/like", req, { showLoading: true });
|
||||
}
|
||||
|
||||
// 删除评论
|
||||
async deleteComment(req: { comment_id: number }): Promise<ApiResponse<any>> {
|
||||
return httpService.post("/comments/delete", req, { showLoading: true });
|
||||
}
|
||||
|
||||
// 获取评论的所有回复
|
||||
async getReplies(req: { comment_id: number, page: number, pageSize: number }): Promise<ApiResponse<ReplyCommentResponse>> {
|
||||
return httpService.post("/comments/replies", req, { showLoading: true });
|
||||
}
|
||||
}
|
||||
|
||||
export default new CommentService();
|
||||
Reference in New Issue
Block a user