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

# api: 使用重新生成的比赛详情API类型

yangyi 2 месяцев назад
Родитель
Сommit
88ce4a99da

+ 2 - 2
src/api/contest-controller.ts

@@ -14,7 +14,7 @@ import type {
   QueryByPage2Params,
   RemoveProblemParams,
   ResponseBoolean,
-  ResponseContestVo,
+  ResponseContestDetailVo,
   ResponseListContestRegistrationVo,
   ResponseListRankVo,
   ResponsePageVoListContestVo,
@@ -111,7 +111,7 @@ export const getContestController = () => {
    * @summary 查询比赛详情
    */
   const getDetail1 = (id: number, params?: GetDetail1Params) => {
-    return customAxiosInstance<ResponseContestVo>({
+    return customAxiosInstance<ResponseContestDetailVo>({
       url: `/contest/${id}`,
       method: "GET",
       params,

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

@@ -1,18 +0,0 @@
-/**
- * Generated by orval v7.0.1 🍺
- * Do not edit manually.
- * Serve API
- * Serve应用接口文档
- * OpenAPI spec version: 0.0.1-SNAPSHOT
- */
-
-export interface FieldError {
-  arguments?: unknown[];
-  bindingFailure?: boolean;
-  code?: string;
-  codes?: string[];
-  defaultMessage?: string;
-  field?: string;
-  objectName?: string;
-  rejectedValue?: unknown;
-}

+ 0 - 3
src/api/models/index.ts

@@ -29,7 +29,6 @@ export * from "./deleteByIds1Params";
 export * from "./deleteByIdsParams";
 export * from "./deleteCaseParams";
 export * from "./deleteTestParams";
-export * from "./fieldError";
 export * from "./getDetail1Params";
 export * from "./loginDto";
 export * from "./pageVoListContestVo";
@@ -60,10 +59,8 @@ export * from "./response";
 export * from "./responseAuthTokenVo";
 export * from "./responseBoolean";
 export * from "./responseContestDetailVo";
-export * from "./responseContestVo";
 export * from "./responseListCategoryVo";
 export * from "./responseListContestRegistrationVo";
-export * from "./responseListFieldError";
 export * from "./responseListProblemTestVo";
 export * from "./responseListRankVo";
 export * from "./responsePageVoListContestVo";

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

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

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

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

+ 0 - 16
src/type/contest.ts

@@ -1,16 +0,0 @@
-import type { ContestVo } from '@/api/models'
-
-export interface ContestProblem {
-  problemId: number
-  title: string
-  difficulty: string
-  displayOrder: number
-  score: number
-}
-
-export interface ContestDetail extends ContestVo {
-  description?: string
-  creatorUsername?: string
-  registered?: boolean
-  problems?: ContestProblem[]
-}

+ 7 - 7
src/view/admin/ContestManageView.vue

@@ -4,6 +4,7 @@ import { getProblemController } from '@/api/problem-controller'
 import type {
   ContestDto,
   ContestProblemDto,
+  ContestProblemVo,
   ContestRegistrationVo,
   ContestVo,
   ProblemVo,
@@ -14,7 +15,6 @@ import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'elem
 import { Delete, Edit, Plus, RefreshRight, Search, UserFilled, View } from '@element-plus/icons-vue'
 import { computed, onMounted, reactive, ref } from 'vue'
 import { useLoginUserStore } from '@/store'
-import type { ContestDetail, ContestProblem } from '@/type/contest'
 
 const api = getContestController()
 const problemApi = getProblemController()
@@ -222,8 +222,8 @@ const configType = ref<ContestVo['type']>('public')
 const configPassword = ref('')
 const configLoaded = ref(false)
 const configSaving = ref(false)
-const configProblems = ref<ContestProblem[]>([])
-const existingProblems = ref<ContestProblem[]>([])
+const configProblems = ref<ContestProblemVo[]>([])
+const existingProblems = ref<ContestProblemVo[]>([])
 
 const candSearch = reactive({ title: '' })
 const candData = ref<ProblemVo[]>([])
@@ -274,7 +274,7 @@ const loadConfig = async () => {
   try {
     const res = await api.getDetail1(configContestId.value, configPassword.value ? { password: configPassword.value } : undefined)
     if (res?.code === 200 && res.data) {
-      const d = res.data as unknown as ContestDetail
+      const d = res.data
       if (d.type === 'password' && !d.creatorUsername) {
         ElMessage.error('比赛密码错误')
         return
@@ -300,7 +300,7 @@ const toggleConfigure = (row: ProblemVo, checked: boolean) => {
       configProblems.value.push({
         problemId: row.id,
         title: row.title || '',
-        difficulty: row.difficulty || '',
+        difficulty: row.difficulty,
         displayOrder: configProblems.value.length + 1,
         score: 100
       })
@@ -331,7 +331,7 @@ const saveConfig = async () => {
 
     for (const cp of current) {
       const old = existingMap.get(cp.problemId)
-      const dto: ContestProblemDto = { problemId: cp.problemId, score: cp.score, displayOrder: cp.displayOrder }
+      const dto: ContestProblemDto = { problemId: cp.problemId!, score: cp.score ?? 0, displayOrder: cp.displayOrder ?? 1 }
       if (!old) {
         const res = await api.addProblem(id, dto)
         if (res?.code !== 200) {
@@ -349,7 +349,7 @@ const saveConfig = async () => {
 
     for (const ex of existing) {
       if (!currentMap.has(ex.problemId)) {
-        const res = await api.removeProblem(id, { problemId: ex.problemId })
+        const res = await api.removeProblem(id, { problemId: ex.problemId! })
         if (res?.code !== 200) {
           ElMessage.error(res?.message || `移除题目 ${ex.title} 失败`)
           return

+ 3 - 3
src/view/contest/ContestDetailView.vue

@@ -1,11 +1,11 @@
 <script setup lang="ts">
 import { getContestController } from '@/api/contest-controller'
+import type { ContestDetailVo } from '@/api/models'
 import { ElMessage } from 'element-plus'
 import { ArrowLeft, Key, Trophy } from '@element-plus/icons-vue'
 import { computed, onMounted, ref } from 'vue'
 import { useRoute, useRouter } from 'vue-router'
 import { useLoginUserStore } from '@/store'
-import type { ContestDetail } from '@/type/contest'
 
 const route = useRoute()
 const router = useRouter()
@@ -14,7 +14,7 @@ const loginUserStore = useLoginUserStore()
 
 const contestId = computed(() => Number(route.params.id))
 const loading = ref(false)
-const detail = ref<ContestDetail>({})
+const detail = ref<ContestDetailVo>({})
 const unlocked = ref(true)
 const validPassword = ref<string | undefined>(undefined)
 
@@ -79,7 +79,7 @@ const fetchDetail = async (password?: string) => {
   try {
     const res = await api.getDetail1(contestId.value, password ? { password } : undefined)
     if (res?.code === 200 && res.data) {
-      const d = res.data as unknown as ContestDetail
+      const d = res.data
       detail.value = d
       if (d.type === 'password') {
         if (!d.creatorUsername) {