diff --git a/src/index.ts b/src/index.ts index 8f444c8..e50c5a6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ import { db, testDB } from "./db/client"; import { User } from "./db/schema"; +import { routes } from "./routes"; import { createUser, createIssue, createProject } from "./db/queries"; const DEV = process.argv.find((arg) => ["--dev", "--developer", "-d"].includes(arg.toLowerCase())) != null; @@ -30,6 +31,7 @@ const main = async () => { port: Number(PORT), routes: { "/": () => new Response(`title: eussi\ndev-mode: ${DEV}\nport: ${PORT}`), + "/issues/:projectId": routes.issues, }, }); diff --git a/src/routes/index.ts b/src/routes/index.ts new file mode 100644 index 0000000..e47145c --- /dev/null +++ b/src/routes/index.ts @@ -0,0 +1,5 @@ +import issues from "./issues"; + +export const routes = { + issues, +}; diff --git a/src/routes/issues.ts b/src/routes/issues.ts new file mode 100644 index 0000000..52b247a --- /dev/null +++ b/src/routes/issues.ts @@ -0,0 +1,14 @@ +import type { BunRequest } from "bun"; +import { getIssuesByProject, getProjectByBlob } from "../db/queries.js"; + +export default async function issues(req: BunRequest<"/issues/:projectId">) { + const { projectId } = req.params; + + const project = await getProjectByBlob(projectId); + if (!project) { + return new Response("project not found", { status: 404 }); + } + const issues = await getIssuesByProject(project.id); + + return Response.json(issues); +}