UNPKG

aisdk5-news-package

Version:

A comprehensive RSS news aggregation package for chat applications

33 lines (29 loc) 1.13 kB
import { NextRequest, NextResponse } from 'next/server'; import { DatabaseService } from '@aisdk5/news-package'; // import { db } from '@/lib/db'; // Replace with your database connection // Initialize database service (customize this) // const databaseService = new DatabaseService(yourDatabaseAdapter); export async function GET(request: NextRequest) { try { // Get all categories with article counts // const categories = await databaseService.getCategories(); // Mock response for template - replace with actual database call const categories = [ { id: 'technology', name: 'Technology', count: 15 }, { id: 'business', name: 'Business', count: 12 }, { id: 'world-news', name: 'World News', count: 8 }, { id: 'sports', name: 'Sports', count: 6 }, { id: 'science', name: 'Science', count: 4 }, ]; return NextResponse.json({ categories, count: categories.length, }); } catch (error) { console.error('Error fetching categories:', error); return NextResponse.json( { error: 'Failed to fetch categories' }, { status: 500 } ); } }