Untitled

 avatar
unknown
plain_text
a year ago
7.4 kB
16
Indexable
"use strict";

const { Router } = require("express");
const multer = require("multer");
const upload = multer();

const roadSourceBottomUpPollutantController = require("../../controllers/roadSourceBottomUpPollutant.controller");

const router = Router();

/**
 * @openapi
 * tags:
 *   - name: Road Source Bottom-Up Pollutant
 *     description: Manage pollutants for road source (bottom-up)
 */

/**
 * @openapi
 * /api/v1/traffic/roadSourceBottomUpPollutant:
 *   get:
 *     summary: Get pollutants (paginated)
 *     description: Return pollutants with pagination.
 *     tags:
 *       - Road Source Bottom-Up Pollutant
 *     parameters:
 *       - in: query
 *         name: page
 *         required: true
 *         schema:
 *           type: integer
 *           example: 1
 *         description: Page number.
 *       - in: query
 *         name: limit
 *         required: true
 *         schema:
 *           type: integer
 *           example: 10
 *         description: Items per page.
 *     responses:
 *       200:
 *         description: Paginated list of pollutants.
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                 message:
 *                   type: string
 *                 result:
 *                   type: object
 *                   properties:
 *                     currentPage:
 *                       type: integer
 *                     totalPages:
 *                       type: integer
 *                     totalRecords:
 *                       type: integer
 *                     limit:
 *                       type: integer
 *                     data:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           _id:
 *                             type: string
 *                           name:
 *                             type: string
 *                             example: "PM2.5"
 *                           createdAt:
 *                             type: string
 *                             format: date-time
 *                           updatedAt:
 *                             type: string
 *                             format: date-time
 *       400:
 *         description: Invalid query parameters.
 */
router.get(
    "/",
    roadSourceBottomUpPollutantController.getListRoadSourceBottomUpPollutant
);

/**
 * @openapi
 * /api/v1/traffic/roadSourceBottomUpPollutant:
 *   post:
 *     summary: Create a pollutant
 *     description: Add a new pollutant.
 *     tags:
 *       - Road Source Bottom-Up Pollutant
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - name
 *             properties:
 *               name:
 *                 type: string
 *                 example: "PM2.5"
 *     responses:
 *       201:
 *         description: Created successfully.
 *       400:
 *         description: Invalid input.
 *       409:
 *         description: Duplicate name.
 */
router.post(
    "/",
    roadSourceBottomUpPollutantController.createRoadSourceBottomUpPollutant
);

/**
 * @openapi
 * /api/v1/traffic/roadSourceBottomUpPollutant/{id}:
 *   get:
 *     summary: Get pollutant by ID
 *     description: Return a single pollutant by MongoDB ObjectId.
 *     tags:
 *       - Road Source Bottom-Up Pollutant
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: string
 *         description: Pollutant ID.
 *     responses:
 *       200:
 *         description: The pollutant.
 *       400:
 *         description: Invalid ID format.
 *       404:
 *         description: Not found.
 */
router.get(
    "/:id",
    roadSourceBottomUpPollutantController.getRoadSourceBottomUpPollutantById
);

/**
 * @openapi
 * /api/v1/traffic/roadSourceBottomUpPollutant/{id}:
 *   patch:
 *     summary: Update pollutant name
 *     description: Update the `name` field by ID.
 *     tags:
 *       - Road Source Bottom-Up Pollutant
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: string
 *         description: Pollutant ID.
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - name
 *             properties:
 *               name:
 *                 type: string
 *                 example: "NOx"
 *     responses:
 *       200:
 *         description: Updated successfully.
 *       400:
 *         description: Invalid input or ID.
 *       404:
 *         description: Not found.
 *       409:
 *         description: Duplicate name.
 */
router.patch(
    "/:id",
    roadSourceBottomUpPollutantController.updateRoadSourceBottomUpPollutantById
);

/**
 * @openapi
 * /api/v1/traffic/roadSourceBottomUpPollutant/{id}:
 *   delete:
 *     summary: Delete pollutant
 *     description: Delete a pollutant by ID.
 *     tags:
 *       - Road Source Bottom-Up Pollutant
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: string
 *         description: Pollutant ID.
 *     responses:
 *       200:
 *         description: Deleted successfully.
 *       400:
 *         description: Invalid ID format.
 *       404:
 *         description: Not found.
 */
router.delete(
    "/:id",
    roadSourceBottomUpPollutantController.deleteRoadSourceBottomUpPollutantById
);

/**
 * @openapi
 * /api/v1/traffic/roadSourceBottomUpPollutant/import:
 *   post:
 *     summary: Import pollutants from Excel
 *     description: Upload an Excel file. Sheet 1, column A = name. Header in row 1.
 *     tags:
 *       - Road Source Bottom-Up Pollutant
 *     requestBody:
 *       required: true
 *       content:
 *         multipart/form-data:
 *           schema:
 *             type: object
 *             properties:
 *               file:
 *                 type: string
 *                 format: binary
 *                 description: Excel file to import.
 *     responses:
 *       200:
 *         description: Import completed.
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: Import completed
 *                 result:
 *                   type: object
 *                   properties:
 *                     added:
 *                       type: integer
 *                       example: 6
 *                     skipped:
 *                       type: integer
 *                       example: 1
 *                     processed:
 *                       type: integer
 *                       example: 7
 *       400:
 *         description: No file uploaded or invalid Excel file.
 */
router.post(
    "/import",
    upload.single("file"),
    roadSourceBottomUpPollutantController.importRoadSourceBottomUpPollutant
);

module.exports = router;
Editor is loading...
Leave a Comment