feat(19-03): add tag filtering to global item search and migrate owner count

- searchGlobalItems now accepts tagNames param with AND intersection logic
- Owner count uses items.globalItemId instead of removed itemGlobalLinks
- Removed linkItemToGlobal and unlinkItemFromGlobal functions
- Route handlers now async with tags query param support
- Rewrote tests to async PGlite pattern, added tag filtering tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-05 20:55:36 +02:00
parent 1bdb34d33e
commit ecc6ac689a
4 changed files with 309 additions and 253 deletions

View File

@@ -9,21 +9,26 @@ type Env = { Variables: { db?: any } };
const app = new Hono<Env>();
app.get("/", (c) => {
app.get("/", async (c) => {
const db = c.get("db");
const q = c.req.query("q");
const items = searchGlobalItems(db, q || undefined);
const tagsParam = c.req.query("tags");
const tagNames = tagsParam
? tagsParam
.split(",")
.map((t) => t.trim())
.filter(Boolean)
: undefined;
const items = await searchGlobalItems(db, q || undefined, tagNames);
return c.json(items);
});
app.get("/:id", (c) => {
app.get("/:id", async (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);
const item = await getGlobalItemWithOwnerCount(db, id);
if (!item) return c.json({ error: "Global item not found" }, 404);
return c.json(item);
});