chore(阶段3): 删除阶段 1 的临时验证物
GET /api/dev/problems、dev-problems.vue、对应路由项,以及只服务于它的 problemSummarySchema。阶段 1 用来验证「能从真实库读出一道题」,已完成使命。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,6 @@ import {
|
||||
problemDetailSchema,
|
||||
problemListItemSchema,
|
||||
problemListSchema,
|
||||
problemSummarySchema,
|
||||
tagSchema,
|
||||
yearlyAcSchema,
|
||||
} from "@oj2/contract"
|
||||
@@ -228,25 +227,6 @@ problemRoutes.get("/problems/:displayId/yearly-ac", async (c) => {
|
||||
return success(c, rows.map((row) => yearlyAcSchema.parse({ ...row, acRate: row.total > 0 ? Math.round(row.accepted / row.total * 10_000) / 100 : 0 })))
|
||||
})
|
||||
|
||||
problemRoutes.get("/dev/problems", async (c) => {
|
||||
const rows = await db
|
||||
.select({
|
||||
id: schema.problem.id,
|
||||
_id: schema.problem.displayId,
|
||||
title: schema.problem.title,
|
||||
difficulty: schema.problem.difficulty,
|
||||
submissionNumber: schema.problem.submissionNumber,
|
||||
acceptedNumber: schema.problem.acceptedNumber,
|
||||
})
|
||||
.from(schema.problem)
|
||||
.where(and(eq(schema.problem.visible, true), isNull(schema.problem.contestId)))
|
||||
.orderBy(desc(schema.problem.id))
|
||||
.limit(20)
|
||||
|
||||
const data = rows.map((row) => problemSummarySchema.parse(row))
|
||||
return success(c, data)
|
||||
})
|
||||
|
||||
problemRoutes.get("/problems/:displayId", optionalAuth, async (c) => {
|
||||
const [row] = await db
|
||||
.select({
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import type { ProblemSummary } from "@oj2/contract"
|
||||
import { onMounted, ref } from "vue"
|
||||
|
||||
const problems = ref<ProblemSummary[]>([])
|
||||
const error = ref("")
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const response = await fetch("/api2/problems")
|
||||
const body = await response.json()
|
||||
problems.value = body.data
|
||||
} catch (cause) {
|
||||
error.value = String(cause)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div style="padding: 24px">
|
||||
<h2>阶段 1 链路验证(临时页,阶段 3 删除)</h2>
|
||||
<p v-if="error" style="color: red">{{ error }}</p>
|
||||
<p>共 {{ problems.length }} 道题</p>
|
||||
<ul>
|
||||
<li v-for="problem in problems" :key="problem.id">
|
||||
{{ problem._id }} — {{ problem.title }}({{ problem.difficulty }},通过
|
||||
{{ problem.acceptedNumber }}/{{ problem.submissionNumber }})
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
@@ -5,7 +5,6 @@ export const ojs: RouteRecordRaw = {
|
||||
component: () => import("shared/layout/default.vue"),
|
||||
children: [
|
||||
{ path: "", component: () => import("oj/problem/list.vue") },
|
||||
{ path: "dev-problems", component: () => import("oj/dev-problems.vue") },
|
||||
{
|
||||
path: "problem/:problemID",
|
||||
component: () => import("oj/problem/detail.vue"),
|
||||
|
||||
@@ -2,18 +2,6 @@ import { z } from "zod"
|
||||
|
||||
import { paginatedSchema, sampleUserSchema } from "./common"
|
||||
|
||||
/** 题目列表项。字段取自 problem 表,只含列表页需要的列。 */
|
||||
export const problemSummarySchema = z.object({
|
||||
id: z.number().int(),
|
||||
_id: z.string(), // 展示用编号,与自增 id 不同
|
||||
title: z.string(),
|
||||
difficulty: z.string(),
|
||||
submissionNumber: z.number().int(),
|
||||
acceptedNumber: z.number().int(),
|
||||
})
|
||||
|
||||
export type ProblemSummary = z.infer<typeof problemSummarySchema>
|
||||
|
||||
export const problemDetailSchema = z.object({
|
||||
id: z.number().int(),
|
||||
_id: z.string(),
|
||||
|
||||
Reference in New Issue
Block a user