feat(18-02): add global item routes, item link/unlink endpoints, and route tests
- GET /api/global-items with optional q search parameter - GET /api/global-items/:id with ownerCount - POST /api/items/:id/link to link user item to global item - DELETE /api/items/:id/link to unlink - Route registered in index.ts - 10 route tests covering all endpoints
This commit is contained in:
30
src/server/routes/global-items.ts
Normal file
30
src/server/routes/global-items.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Hono } from "hono";
|
||||
import { parseId } from "../lib/params.ts";
|
||||
import {
|
||||
getGlobalItemWithOwnerCount,
|
||||
searchGlobalItems,
|
||||
} from "../services/global-item.service.ts";
|
||||
|
||||
type Env = { Variables: { db?: any } };
|
||||
|
||||
const app = new Hono<Env>();
|
||||
|
||||
app.get("/", (c) => {
|
||||
const db = c.get("db");
|
||||
const q = c.req.query("q");
|
||||
const items = searchGlobalItems(db, q || undefined);
|
||||
return c.json(items);
|
||||
});
|
||||
|
||||
app.get("/:id", (c) => {
|
||||
const db = c.get("db");
|
||||
const id = parseId(c.req.param("id"));
|
||||
if (!id) return c.json({ error: "Invalid global item ID" }, 400);
|
||||
|
||||
const item = getGlobalItemWithOwnerCount(db, id);
|
||||
if (!item) return c.json({ error: "Global item not found" }, 404);
|
||||
|
||||
return c.json(item);
|
||||
});
|
||||
|
||||
export { app as globalItemRoutes };
|
||||
Reference in New Issue
Block a user