From 34197502cf3d4a6b77fdf9b17b0aed59d06ba60b Mon Sep 17 00:00:00 2001 From: slhmy <1484836413@qq.com> Date: Thu, 8 Feb 2024 16:23:56 +0800 Subject: [PATCH] Prepare problem APIs --- src/api/problem.ts | 33 +++++++++++++++++++ src/components/ProblemTable.tsx | 27 +++++++++++++--- src/mocks/handlers.ts | 12 ++++++- src/mocks/rest/problem.ts | 26 +++++++++++++-- src/pages/admin-dashboard/CreateProblem.tsx | 36 ++++++++++++++++++--- 5 files changed, 123 insertions(+), 11 deletions(-) diff --git a/src/api/problem.ts b/src/api/problem.ts index b9c99914f..a1c042d3e 100644 --- a/src/api/problem.ts +++ b/src/api/problem.ts @@ -34,4 +34,37 @@ export namespace ProblemService { } return res.data; } + + export async function putProblemPackage( + problemSlug: string, + packageFile: File, + ) { + let formData = new FormData(); + formData.append("file", packageFile); + let res = await client.put( + `/api/v1/problem/${problemSlug}/package`, + formData, + ); + if (res.status !== 200) { + throw Error("failed to put problem package"); + } + return res.data; + } + + export async function checkProblemSlug( + slug: string, + ): Promise<{ valid: boolean }> { + let res = await client.get<{ valid: boolean }>( + `/api/v1/problem/${slug}/check`, + ); + + return res.data; + } + + export async function deleteProblem(slug: string) { + let res = await client.delete(`/api/v1/problem/${slug}`); + if (res.status !== 200) { + throw Error("failed to delete problem"); + } + } } diff --git a/src/components/ProblemTable.tsx b/src/components/ProblemTable.tsx index 7d047641a..22f7deb97 100644 --- a/src/components/ProblemTable.tsx +++ b/src/components/ProblemTable.tsx @@ -2,6 +2,7 @@ import { TrashIcon, PencilSquareIcon } from "@heroicons/react/24/outline"; import { ProblemServiceModel } from "../typings/problem"; import React from "react"; import { useNavigate } from "react-router-dom"; +import { ProblemService } from "@/api/problem"; const columns = [ { name: "SLUG", uid: "slug" }, @@ -19,6 +20,8 @@ export interface ProblemTableProps { } const ProblemTable: React.FC = (props) => { + const [deletingSlug, setDeletingSlug] = React.useState(""); + const navigate = useNavigate(); return ( @@ -56,7 +59,9 @@ const ProblemTable: React.FC = (props) => { {props.showActions && ( - + setDeletingSlug(problemInfo.slug)} + /> )} @@ -75,7 +80,13 @@ const ProblemTable: React.FC = (props) => {