feat(30-01): add popular-items-by-tags endpoint to discovery routes
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import {
|
import {
|
||||||
|
getPopularItemsByTags,
|
||||||
getPopularSetups,
|
getPopularSetups,
|
||||||
getRecentGlobalItems,
|
getRecentGlobalItems,
|
||||||
getTrendingCategories,
|
getTrendingCategories,
|
||||||
} from "../services/discovery.service.ts";
|
} from "../services/discovery.service.ts";
|
||||||
|
import { withImageUrls } from "../services/storage.service.ts";
|
||||||
|
|
||||||
type Env = { Variables: { db?: any } };
|
type Env = { Variables: { db?: any } };
|
||||||
|
|
||||||
@@ -35,4 +37,23 @@ app.get("/categories", async (c) => {
|
|||||||
return c.json(result);
|
return c.json(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get("/popular-items", async (c) => {
|
||||||
|
const db = c.get("db");
|
||||||
|
const tagsParam = c.req.query("tags") || "";
|
||||||
|
const limitParam = c.req.query("limit");
|
||||||
|
const tagNames = tagsParam
|
||||||
|
.split(",")
|
||||||
|
.map((t) => t.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
const limit = limitParam ? Math.min(Number.parseInt(limitParam, 10), 50) : 24;
|
||||||
|
|
||||||
|
if (tagNames.length === 0) {
|
||||||
|
return c.json({ items: [] });
|
||||||
|
}
|
||||||
|
|
||||||
|
const results = await getPopularItemsByTags(db, tagNames, limit);
|
||||||
|
const enriched = await withImageUrls(results);
|
||||||
|
return c.json({ items: enriched });
|
||||||
|
});
|
||||||
|
|
||||||
export { app as discoveryRoutes };
|
export { app as discoveryRoutes };
|
||||||
|
|||||||
Reference in New Issue
Block a user