judge4c/src/api/problem.ts
liguang 42e576876e feat(user-management): 实现用户管理和题目管理功能
- 新增用户管理和题目管理的 API 接口
- 实现用户管理和题目管理的后端逻辑
- 添加保护布局组件,用于权限控制
- 创建用户管理的不同角色页面
- 移除不必要的数据文件和旧的页面组件
2025-06-19 16:13:50 +08:00

40 lines
1.2 KiB
TypeScript

import type { Problem } from "@/types/problem";
// 获取所有题目
export async function getProblems(): Promise<Problem[]> {
const res = await fetch("/api/problem");
if (!res.ok) throw new Error("获取题目失败");
return res.json();
}
// 新建题目
export async function createProblem(data: Partial<Problem>): Promise<Problem> {
const res = await fetch("/api/problem", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
if (!res.ok) throw new Error("新建题目失败");
return res.json();
}
// 编辑题目
export async function updateProblem(data: Partial<Problem>): Promise<Problem> {
const res = await fetch("/api/problem", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
if (!res.ok) throw new Error("更新题目失败");
return res.json();
}
// 删除题目
export async function deleteProblem(id: string): Promise<void> {
const res = await fetch("/api/problem", {
method: "DELETE",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ id }),
});
if (!res.ok) throw new Error("删除题目失败");
}