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(); 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 };