From 3c975e85eef15122af0372a645894143ff04db23 Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Thu, 6 Aug 2026 21:14:58 -0600 Subject: [PATCH] =?UTF-8?q?feat(=E9=98=B6=E6=AE=B51):=20Hono=20=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E4=B8=8E=E9=A2=98=E7=9B=AE=E5=88=97=E8=A1=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E8=AF=BB=E9=80=9A=E6=9C=AC=E5=9C=B0=E7=9C=9F?= =?UTF-8?q?=E5=AE=9E=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/src/index.ts | 13 +++++++++++++ apps/api/src/routes/problem.ts | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 apps/api/src/index.ts create mode 100644 apps/api/src/routes/problem.ts diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts new file mode 100644 index 0000000..64e36a1 --- /dev/null +++ b/apps/api/src/index.ts @@ -0,0 +1,13 @@ +import { Hono } from "hono" + +import { problemRoutes } from "./routes/problem" + +const app = new Hono() + +app.get("/health", (c) => c.json({ ok: true })) +app.route("/api", problemRoutes) + +export default { + port: 3000, + fetch: app.fetch, +} diff --git a/apps/api/src/routes/problem.ts b/apps/api/src/routes/problem.ts new file mode 100644 index 0000000..cfda360 --- /dev/null +++ b/apps/api/src/routes/problem.ts @@ -0,0 +1,25 @@ +import { problemSummarySchema } from "@oj2/contract" +import { desc } from "drizzle-orm" +import { Hono } from "hono" + +import { db, schema } from "../db" + +export const problemRoutes = new Hono() + +problemRoutes.get("/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) + .orderBy(desc(schema.problem.id)) + .limit(20) + + const data = rows.map((row) => problemSummarySchema.parse(row)) + return c.json({ data }) +})