Просмотр исходного кода

# api: 重新生成提交判题模块API

yangyi 1 месяц назад
Родитель
Сommit
d7f3cc5c51

+ 8 - 6
src/api/contest-controller.ts

@@ -10,7 +10,8 @@ import type {
   ContestProblemDto,
   ContestRegisterDto,
   DeleteByIds1Params,
-  GetDetail1Params,
+  GetDetail2Params,
+  GetRankingParams,
   QueryByPage2Params,
   RemoveProblemParams,
   ResponseBoolean,
@@ -110,7 +111,7 @@ export const getContestController = () => {
   /**
    * @summary 查询比赛详情
    */
-  const getDetail1 = (id: number, params?: GetDetail1Params) => {
+  const getDetail2 = (id: number, params?: GetDetail2Params) => {
     return customAxiosInstance<ResponseContestDetailVo>({
       url: `/contest/${id}`,
       method: "GET",
@@ -129,10 +130,11 @@ export const getContestController = () => {
   /**
    * @summary 查询比赛排行榜
    */
-  const getRanking = (id: number) => {
+  const getRanking = (id: number, params?: GetRankingParams) => {
     return customAxiosInstance<ResponseListRankVo>({
       url: `/contest/${id}/ranking`,
       method: "GET",
+      params,
     });
   };
   return {
@@ -144,7 +146,7 @@ export const getContestController = () => {
     addProblem,
     removeProblem,
     register,
-    getDetail1,
+    getDetail2,
     queryRegistrations,
     getRanking,
   };
@@ -173,8 +175,8 @@ export type RemoveProblemResult = NonNullable<
 export type RegisterResult = NonNullable<
   Awaited<ReturnType<ReturnType<typeof getContestController>["register"]>>
 >;
-export type GetDetail1Result = NonNullable<
-  Awaited<ReturnType<ReturnType<typeof getContestController>["getDetail1"]>>
+export type GetDetail2Result = NonNullable<
+  Awaited<ReturnType<ReturnType<typeof getContestController>["getDetail2"]>>
 >;
 export type QueryRegistrationsResult = NonNullable<
   Awaited<

+ 1 - 1
src/api/models/getDetail1Params.ts → src/api/models/getDetail2Params.ts

@@ -6,7 +6,7 @@
  * OpenAPI spec version: 0.0.1-SNAPSHOT
  */
 
-export type GetDetail1Params = {
+export type GetDetail2Params = {
   /**
    * 访问密码(密码型比赛需传入)
    */

+ 14 - 0
src/api/models/getRankingParams.ts

@@ -0,0 +1,14 @@
+/**
+ * Generated by orval v7.0.1 🍺
+ * Do not edit manually.
+ * Serve API
+ * Serve应用接口文档
+ * OpenAPI spec version: 0.0.1-SNAPSHOT
+ */
+
+export type GetRankingParams = {
+  /**
+   * 访问密码(密码型比赛需传入)
+   */
+  password?: string;
+};

+ 10 - 1
src/api/models/index.ts

@@ -29,10 +29,12 @@ export * from "./deleteByIds1Params";
 export * from "./deleteByIdsParams";
 export * from "./deleteCaseParams";
 export * from "./deleteTestParams";
-export * from "./getDetail1Params";
+export * from "./getDetail2Params";
+export * from "./getRankingParams";
 export * from "./loginDto";
 export * from "./pageVoListContestVo";
 export * from "./pageVoListProblemVo";
+export * from "./pageVoListSubmissionVo";
 export * from "./pageVoListUserVo";
 export * from "./problemCaseDto";
 export * from "./problemCaseVo";
@@ -52,6 +54,8 @@ export * from "./problemVoIsPublic";
 export * from "./queryByPage1Params";
 export * from "./queryByPage2Params";
 export * from "./queryByPageParams";
+export * from "./queryByProblemIdParams";
+export * from "./queryMyParams";
 export * from "./rankVo";
 export * from "./registerDto";
 export * from "./removeProblemParams";
@@ -65,9 +69,14 @@ export * from "./responseListProblemTestVo";
 export * from "./responseListRankVo";
 export * from "./responsePageVoListContestVo";
 export * from "./responsePageVoListProblemVo";
+export * from "./responsePageVoListSubmissionVo";
 export * from "./responsePageVoListUserVo";
 export * from "./responseProblemDetailVo";
+export * from "./responseSubmissionVo";
 export * from "./responseUserVo";
+export * from "./submissionVo";
+export * from "./submitDto";
+export * from "./submitDtoLanguage";
 export * from "./updateUserAvatarDto";
 export * from "./updateUserPasswordDto";
 export * from "./updateUserStatusDto";

+ 18 - 0
src/api/models/pageVoListSubmissionVo.ts

@@ -0,0 +1,18 @@
+/**
+ * Generated by orval v7.0.1 🍺
+ * Do not edit manually.
+ * Serve API
+ * Serve应用接口文档
+ * OpenAPI spec version: 0.0.1-SNAPSHOT
+ */
+import type { SubmissionVo } from "./submissionVo";
+
+/**
+ * 分页数据对象
+ */
+export interface PageVoListSubmissionVo {
+  /** 当前页的数据 */
+  data?: SubmissionVo[];
+  /** 总数据条数 */
+  total?: number;
+}

+ 18 - 0
src/api/models/queryByProblemIdParams.ts

@@ -0,0 +1,18 @@
+/**
+ * Generated by orval v7.0.1 🍺
+ * Do not edit manually.
+ * Serve API
+ * Serve应用接口文档
+ * OpenAPI spec version: 0.0.1-SNAPSHOT
+ */
+
+export type QueryByProblemIdParams = {
+  /**
+   * 页码
+   */
+  pageNum?: number;
+  /**
+   * 分页大小
+   */
+  pageSize?: number;
+};

+ 18 - 0
src/api/models/queryMyParams.ts

@@ -0,0 +1,18 @@
+/**
+ * Generated by orval v7.0.1 🍺
+ * Do not edit manually.
+ * Serve API
+ * Serve应用接口文档
+ * OpenAPI spec version: 0.0.1-SNAPSHOT
+ */
+
+export type QueryMyParams = {
+  /**
+   * 页码
+   */
+  pageNum?: number;
+  /**
+   * 分页大小
+   */
+  pageSize?: number;
+};

+ 20 - 0
src/api/models/responsePageVoListSubmissionVo.ts

@@ -0,0 +1,20 @@
+/**
+ * Generated by orval v7.0.1 🍺
+ * Do not edit manually.
+ * Serve API
+ * Serve应用接口文档
+ * OpenAPI spec version: 0.0.1-SNAPSHOT
+ */
+import type { PageVoListSubmissionVo } from "./pageVoListSubmissionVo";
+
+/**
+ * 后端统一的响应实体
+ */
+export interface ResponsePageVoListSubmissionVo {
+  /** 状态码;200:成功 */
+  code?: number;
+  /** 响应的具体数据 */
+  data?: PageVoListSubmissionVo;
+  /** 响应附加信息 */
+  message?: string;
+}

+ 20 - 0
src/api/models/responseSubmissionVo.ts

@@ -0,0 +1,20 @@
+/**
+ * Generated by orval v7.0.1 🍺
+ * Do not edit manually.
+ * Serve API
+ * Serve应用接口文档
+ * OpenAPI spec version: 0.0.1-SNAPSHOT
+ */
+import type { SubmissionVo } from "./submissionVo";
+
+/**
+ * 后端统一的响应实体
+ */
+export interface ResponseSubmissionVo {
+  /** 状态码;200:成功 */
+  code?: number;
+  /** 响应的具体数据 */
+  data?: SubmissionVo;
+  /** 响应附加信息 */
+  message?: string;
+}

+ 37 - 0
src/api/models/submissionVo.ts

@@ -0,0 +1,37 @@
+/**
+ * Generated by orval v7.0.1 🍺
+ * Do not edit manually.
+ * Serve API
+ * Serve应用接口文档
+ * OpenAPI spec version: 0.0.1-SNAPSHOT
+ */
+
+/**
+ * 提交记录响应展示对象
+ */
+export interface SubmissionVo {
+  /** 比赛ID,练习提交为null */
+  contestId?: number;
+  /** 提交时间 */
+  createdAt?: string;
+  /** 提交ID */
+  id?: number;
+  /** 判题详情(CE/SE时展示错误信息) */
+  judgeDetail?: string;
+  /** 提交语言 */
+  language?: string;
+  /** 内存使用(KB) */
+  memoryUsedKb?: number;
+  /** 通过测试用例数 */
+  passedTestCases?: number;
+  /** 题目ID */
+  problemId?: number;
+  /** 得分 */
+  score?: number;
+  /** 判题状态:SUBMITTED-已提交,JUDGING-判题中,AC-通过,WA-答案错误,TLE-超时,MLE-内存超限,RE-运行错误,CE-编译失败,SE-系统错误 */
+  status?: string;
+  /** 执行时间(毫秒) */
+  timeUsedMs?: number;
+  /** 总测试用例数 */
+  totalTestCases?: number;
+}

+ 28 - 0
src/api/models/submitDto.ts

@@ -0,0 +1,28 @@
+/**
+ * Generated by orval v7.0.1 🍺
+ * Do not edit manually.
+ * Serve API
+ * Serve应用接口文档
+ * OpenAPI spec version: 0.0.1-SNAPSHOT
+ */
+import type { SubmitDtoLanguage } from "./submitDtoLanguage";
+
+/**
+ * 代码提交DTO
+ */
+export interface SubmitDto {
+  /**
+   * 提交代码
+   * @minLength 1
+   */
+  code: string;
+  /** 比赛ID,为空表示日常练习提交 */
+  contestId?: number;
+  /**
+   * 提交语言,当前仅支持java
+   * @minLength 1
+   */
+  language: SubmitDtoLanguage;
+  /** 题目ID */
+  problemId: number;
+}

+ 19 - 0
src/api/models/submitDtoLanguage.ts

@@ -0,0 +1,19 @@
+/**
+ * Generated by orval v7.0.1 🍺
+ * Do not edit manually.
+ * Serve API
+ * Serve应用接口文档
+ * OpenAPI spec version: 0.0.1-SNAPSHOT
+ */
+
+/**
+ * 提交语言,当前仅支持java
+ * @minLength 1
+ */
+export type SubmitDtoLanguage =
+  (typeof SubmitDtoLanguage)[keyof typeof SubmitDtoLanguage];
+
+// eslint-disable-next-line @typescript-eslint/no-redeclare
+export const SubmitDtoLanguage = {
+  java: "java",
+} as const;

+ 4 - 4
src/api/problem-controller.ts

@@ -139,7 +139,7 @@ export const getProblemController = () => {
   /**
    * @summary 查询题目详情
    */
-  const getDetail = (id: number) => {
+  const getDetail1 = (id: number) => {
     return customAxiosInstance<ResponseProblemDetailVo>({
       url: `/problem/${id}`,
       method: "GET",
@@ -157,7 +157,7 @@ export const getProblemController = () => {
     queryTests,
     addTest,
     addCase,
-    getDetail,
+    getDetail1,
   };
 };
 export type QueryByPage1Result = NonNullable<
@@ -193,6 +193,6 @@ export type AddTestResult = NonNullable<
 export type AddCaseResult = NonNullable<
   Awaited<ReturnType<ReturnType<typeof getProblemController>["addCase"]>>
 >;
-export type GetDetailResult = NonNullable<
-  Awaited<ReturnType<ReturnType<typeof getProblemController>["getDetail"]>>
+export type GetDetail1Result = NonNullable<
+  Awaited<ReturnType<ReturnType<typeof getProblemController>["getDetail1"]>>
 >;

+ 76 - 0
src/api/submission-controller.ts

@@ -0,0 +1,76 @@
+/**
+ * Generated by orval v7.0.1 🍺
+ * Do not edit manually.
+ * Serve API
+ * Serve应用接口文档
+ * OpenAPI spec version: 0.0.1-SNAPSHOT
+ */
+import type {
+  QueryByProblemIdParams,
+  QueryMyParams,
+  ResponsePageVoListSubmissionVo,
+  ResponseSubmissionVo,
+  SubmitDto,
+} from "./models";
+import { customAxiosInstance } from "../util/axios-instance";
+
+export const getSubmissionController = () => {
+  /**
+   * 同步返回判题结果,contestId为空表示日常练习提交
+   * @summary 提交代码并判题
+   */
+  const submit = (submitDto: SubmitDto) => {
+    return customAxiosInstance<ResponseSubmissionVo>({
+      url: `/submit`,
+      method: "POST",
+      headers: { "Content-Type": "application/json" },
+      data: submitDto,
+    });
+  };
+  /**
+   * @summary 查询提交记录详情
+   */
+  const getDetail = (id: number) => {
+    return customAxiosInstance<ResponseSubmissionVo>({
+      url: `/submission/${id}`,
+      method: "GET",
+    });
+  };
+  /**
+   * 分页查询当前用户的提交记录,按提交时间倒序
+   * @summary 查询我的提交记录
+   */
+  const queryMy = (params: QueryMyParams) => {
+    return customAxiosInstance<ResponsePageVoListSubmissionVo>({
+      url: `/submission/my`,
+      method: "GET",
+      params,
+    });
+  };
+  /**
+   * coach/admin 查看某题的全部提交记录
+   * @summary 查询题目的提交记录
+   */
+  const queryByProblemId = (id: number, params: QueryByProblemIdParams) => {
+    return customAxiosInstance<ResponsePageVoListSubmissionVo>({
+      url: `/problem/${id}/submission`,
+      method: "GET",
+      params,
+    });
+  };
+  return { submit, getDetail, queryMy, queryByProblemId };
+};
+export type SubmitResult = NonNullable<
+  Awaited<ReturnType<ReturnType<typeof getSubmissionController>["submit"]>>
+>;
+export type GetDetailResult = NonNullable<
+  Awaited<ReturnType<ReturnType<typeof getSubmissionController>["getDetail"]>>
+>;
+export type QueryMyResult = NonNullable<
+  Awaited<ReturnType<ReturnType<typeof getSubmissionController>["queryMy"]>>
+>;
+export type QueryByProblemIdResult = NonNullable<
+  Awaited<
+    ReturnType<ReturnType<typeof getSubmissionController>["queryByProblemId"]>
+  >
+>;