news.routes.ts•8.58 kB
/**
* Routes for news-related endpoints
*/
import { Router } from 'express';
import { NewsController } from '../controllers/news.controller';
const router = Router();
const newsController = new NewsController();
/**
* @swagger
* /news/top:
* get:
* summary: Get top news articles
* description: Retrieve a list of top news articles with optional filtering
* tags: [News]
* parameters:
* - $ref: '#/components/parameters/limitParam'
* - $ref: '#/components/parameters/offsetParam'
* - $ref: '#/components/parameters/sortParam'
* - $ref: '#/components/parameters/orderParam'
* - name: category
* in: query
* description: Filter by category (e.g., technology, business)
* required: false
* schema:
* type: string
* - name: source
* in: query
* description: Filter by news source
* required: false
* schema:
* type: string
* - name: language
* in: query
* description: Filter by language (e.g., en, es)
* required: false
* schema:
* type: string
* default: en
* responses:
* 200:
* description: A list of top news articles
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* type: object
* properties:
* articles:
* type: array
* items:
* $ref: '#/components/schemas/Article'
* total:
* type: integer
* description: Total number of articles matching query
* example: 42
* 500:
* $ref: '#/components/responses/ServerError'
*/
router.get('/top', (req, res) => newsController.getTopNews(req, res));
/**
* @swagger
* /news/all:
* get:
* summary: Get all news articles
* description: Retrieve all news articles with optional filtering and advanced search
* tags: [News]
* parameters:
* - $ref: '#/components/parameters/limitParam'
* - $ref: '#/components/parameters/offsetParam'
* - $ref: '#/components/parameters/sortParam'
* - $ref: '#/components/parameters/orderParam'
* - name: category
* in: query
* description: Filter by category (e.g., technology, business)
* required: false
* schema:
* type: string
* - name: source
* in: query
* description: Filter by news source
* required: false
* schema:
* type: string
* - name: search
* in: query
* description: Search term in title or description
* required: false
* schema:
* type: string
* - name: fromDate
* in: query
* description: Filter articles published after this date (ISO format)
* required: false
* schema:
* type: string
* format: date-time
* - name: toDate
* in: query
* description: Filter articles published before this date (ISO format)
* required: false
* schema:
* type: string
* format: date-time
* responses:
* 200:
* description: A list of all news articles matching the criteria
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* type: object
* properties:
* articles:
* type: array
* items:
* $ref: '#/components/schemas/Article'
* total:
* type: integer
* description: Total number of articles matching query
* example: 157
* filters:
* type: object
* description: Applied filters
* 500:
* $ref: '#/components/responses/ServerError'
*/
router.get('/all', (req, res) => newsController.getAllNews(req, res));
/**
* @swagger
* /news/similar/{uuid}:
* get:
* summary: Get similar news articles
* description: Retrieve articles similar to the specified article UUID
* tags: [News]
* parameters:
* - name: uuid
* in: path
* description: UUID of the reference article
* required: true
* schema:
* type: string
* - $ref: '#/components/parameters/limitParam'
* responses:
* 200:
* description: A list of similar news articles
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* type: object
* properties:
* articles:
* type: array
* items:
* $ref: '#/components/schemas/Article'
* referenceArticle:
* $ref: '#/components/schemas/Article'
* 404:
* $ref: '#/components/responses/NotFound'
* 500:
* $ref: '#/components/responses/ServerError'
*/
router.get('/similar/:uuid', (req, res) => newsController.getSimilarNews(req, res));
/**
* @swagger
* /news/uuid/{uuid}:
* get:
* summary: Get a specific news article
* description: Retrieve a specific news article by its UUID
* tags: [News]
* parameters:
* - name: uuid
* in: path
* description: UUID of the article to retrieve
* required: true
* schema:
* type: string
* responses:
* 200:
* description: The requested news article
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* type: object
* properties:
* article:
* $ref: '#/components/schemas/Article'
* 404:
* $ref: '#/components/responses/NotFound'
* 500:
* $ref: '#/components/responses/ServerError'
*/
router.get('/uuid/:uuid', (req, res) => newsController.getNewsByUuid(req, res));
/**
* @swagger
* /news/sources:
* get:
* summary: Get available news sources
* description: Retrieve a list of all available news sources with optional filtering
* tags: [News]
* parameters:
* - $ref: '#/components/parameters/limitParam'
* - $ref: '#/components/parameters/offsetParam'
* - name: search
* in: query
* description: Search term for filtering sources
* required: false
* schema:
* type: string
* responses:
* 200:
* description: A list of news sources
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* type: object
* properties:
* sources:
* type: array
* items:
* type: object
* properties:
* name:
* type: string
* example: 'The Verge'
* count:
* type: integer
* example: 125
* total:
* type: integer
* example: 35
* 500:
* $ref: '#/components/responses/ServerError'
*/
router.get('/sources', (req, res) => newsController.getNewsSources(req, res));
export default router;