blob: d62482148b0020bf4ade2fcade609365754c7f09 [file] [log] [blame]
223010143d966302025-06-07 22:54:40 +08001import axios from 'axios';
2import type { Work, WorkResponse, WorkFormData, BugReport, Discussion } from './otherType';
3
4const API_BASE_URL = '/api';
5
6class WorkAPI {
7 /**
8 * 获取作品列表(支持分页、分类筛选和搜索)
9 */
10 static getWorks(params?: {
11 categoryId?: number;
12 page?: number;
13 size?: number;
14 search?: string;
15 }): Promise<WorkResponse> {
16 return axios.get<WorkResponse>(`${API_BASE_URL}/works`, { params })
17 .then(response => response.data);
18 }
19
20 /**
21 * 获取单个作品详情
22 */
23 static getWorkById(id: number): Promise<Work> {
24 return axios.get<Work>(`${API_BASE_URL}/works/${id}`)
25 .then(response => response.data);
26 }
27
28 /**
29 * 创建新作品
30 */
31 static createWork(data: WorkFormData): Promise<Work> {
32 return axios.post<Work>(`${API_BASE_URL}/works`, data)
33 .then(response => response.data);
34 }
35
36 /**
37 * 更新作品信息
38 */
39 static updateWork(id: number, data: WorkFormData): Promise<Work> {
40 return axios.put<Work>(`${API_BASE_URL}/works/${id}`, data)
41 .then(response => response.data);
42 }
43
44 /**
45 * 删除作品
46 */
47 static deleteWork(id: number): Promise<void> {
48 return axios.delete(`${API_BASE_URL}/works/${id}`);
49 }
50
51 /**
52 * 点赞作品
53 */
54 static likeWork(id: number): Promise<void> {
55 return axios.post(`${API_BASE_URL}/works/${id}/like`);
56 }
57
58 /**
59 * 根据作者查询作品
60 */
61 static getWorksByAuthor(author: string): Promise<Work[]> {
62 return axios.get<Work[]>(`${API_BASE_URL}/works/byAuthor`, { params: { author } })
63 .then(response => response.data);
64 }
65
66 /**
67 * 获取作品Bug反馈列表
68 */
69 static getBugReports(workId: number): Promise<BugReport[]> {
70 return axios.get<BugReport[]>(`${API_BASE_URL}/works/${workId}/bugs`)
71 .then(response => response.data);
72 }
73
74 /**
75 * 提交Bug反馈
76 */
77 static reportBug(workId: number, data: {
78 title: string;
79 description: string;
80 severity: 'low' | 'medium' | 'high';
81 }): Promise<void> {
82 return axios.post(`${API_BASE_URL}/works/${workId}/bugs`, data);
83 }
84
85 /**
86 * 获取作品讨论区列表
87 */
88 static getDiscussions(workId: number): Promise<Discussion[]> {
89 return axios.get<Discussion[]>(`${API_BASE_URL}/works/${workId}/discussions`)
90 .then(response => response.data);
91 }
92
93 /**
94 * 创建新讨论
95 */
96 static createDiscussion(data: {
97 workId: number;
98 title: string;
99 content: string;
100 }): Promise<void> {
101 return axios.post(`${API_BASE_URL}/discussions`, data);
102 }
103}
104
105export default WorkAPI;