import express from 'express'; import { PrismaClient } from '@prisma/client'; import { auth } from '../middleware/auth.js'; const router = express.Router(); const prisma = new PrismaClient(); // Search articles router.get('/search', async (req, res) => { try { const { q, page = 1, limit = 9 } = req.query; const skip = (page - 1) * limit; const where = { OR: [ { title: { contains: q, mode: 'insensitive' } }, { excerpt: { contains: q, mode: 'insensitive' } }, { content: { contains: q, mode: 'insensitive' } }, ] }; const [articles, total] = await Promise.all([ prisma.article.findMany({ where, include: { author: { select: { id: true, displayName: true, email: true } } }, skip, take: parseInt(limit), orderBy: { publishedAt: 'desc' } }), prisma.article.count({ where }) ]); res.json({ articles, totalPages: Math.ceil(total / limit), currentPage: parseInt(page) }); } catch (error) { res.status(500).json({ error: 'Server error' }); } }); // Get articles with pagination and filters router.get('/', async (req, res) => { try { const { page = 1, category, city } = req.query; const perPage = 6; const where = { ...(category && { category }), ...(city && { city }) }; const [articles, total] = await Promise.all([ prisma.article.findMany({ where, include: { author: { select: { id: true, displayName: true, email: true } } }, skip: (page - 1) * perPage, take: perPage, orderBy: { publishedAt: 'desc' } }), prisma.article.count({ where }) ]); res.json({ articles, totalPages: Math.ceil(total / perPage), currentPage: parseInt(page) }); } catch (error) { res.status(500).json({ error: 'Server error' }); } }); // Rest of the routes remain the same...