mirror of
https://github.com/xtr-dev/rondevu-server.git
synced 2025-12-10 02:43:24 +00:00
Add startsWith filter to topics endpoint
Added optional startsWith parameter to GET /topics endpoint: - Filters topics by prefix using SQL LIKE operator - Updated storage interface and implementations (SQLite & D1) - Added query param documentation - Returns startsWith in response when used Version bumped to 0.1.1 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
11
src/app.ts
11
src/app.ts
@@ -231,22 +231,29 @@ export function createApp(storage: Storage, config: Config) {
|
||||
* GET /topics
|
||||
* List all topics with active peer counts (paginated)
|
||||
* Public endpoint (no auth required)
|
||||
* Query params:
|
||||
* - limit: Max topics to return (default 50, max 200)
|
||||
* - offset: Number of topics to skip (default 0)
|
||||
* - startsWith: Filter topics starting with this prefix (optional)
|
||||
*/
|
||||
app.get('/topics', async (c) => {
|
||||
try {
|
||||
const limitParam = c.req.query('limit');
|
||||
const offsetParam = c.req.query('offset');
|
||||
const startsWithParam = c.req.query('startsWith');
|
||||
|
||||
const limit = limitParam ? Math.min(parseInt(limitParam, 10), 200) : 50;
|
||||
const offset = offsetParam ? parseInt(offsetParam, 10) : 0;
|
||||
const startsWith = startsWithParam || undefined;
|
||||
|
||||
const result = await storage.getTopics(limit, offset);
|
||||
const result = await storage.getTopics(limit, offset, startsWith);
|
||||
|
||||
return c.json({
|
||||
topics: result.topics,
|
||||
total: result.total,
|
||||
limit,
|
||||
offset
|
||||
offset,
|
||||
...(startsWith && { startsWith })
|
||||
}, 200);
|
||||
} catch (err) {
|
||||
console.error('Error fetching topics:', err);
|
||||
|
||||
Reference in New Issue
Block a user