@gv-sh/specgen-server
Version:
SpecGen Server - API for Speculative Fiction Generator
224 lines (218 loc) • 6.6 kB
JavaScript
// routes/categories.js
const express = require('express');
const router = express.Router();
const categoryController = require('../controllers/categoryController');
/**
* @swagger
* /api/categories:
* get:
* summary: Get all categories
* tags: [Categories]
* responses:
* 200:
* description: List of categories
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* type: array
* items:
* $ref: '#/components/schemas/Category'
* 500:
* $ref: '#/components/responses/Error'
*/
router.get('/', categoryController.getAllCategories);
/**
* @swagger
* /api/categories/{id}:
* get:
* summary: Get a category by ID
* tags: [Categories]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* description: Category ID
* example: science-fiction
* responses:
* 200:
* description: Category details
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* $ref: '#/components/schemas/Category'
* 404:
* $ref: '#/components/responses/Error'
* 500:
* $ref: '#/components/responses/Error'
*/
router.get('/:id', categoryController.getCategoryById);
/**
* @swagger
* /api/categories:
* post:
* summary: Create a new category
* tags: [Categories]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required: [name]
* properties:
* name:
* type: string
* example: "Science Fiction"
* description:
* type: string
* example: "Stories set in the future with advanced technology"
* visibility:
* type: string
* enum: [Show, Hide]
* default: Show
* example: "Show"
* examples:
* basicCategory:
* summary: Basic category with just a name
* value:
* name: "Science Fiction"
* fullCategory:
* summary: Complete category with all fields
* value:
* name: "Fantasy"
* description: "Stories with magic and mythical creatures"
* visibility: "Show"
* responses:
* 201:
* description: Category created successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* $ref: '#/components/schemas/Category'
* 400:
* $ref: '#/components/responses/Error'
* 500:
* $ref: '#/components/responses/Error'
*/
router.post('/', categoryController.createCategory);
/**
* @swagger
* /api/categories/{id}:
* put:
* summary: Update a category
* tags: [Categories]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* description: Category ID
* example: science-fiction
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* name:
* type: string
* example: "Updated Science Fiction"
* description:
* type: string
* example: "Updated description for science fiction category"
* visibility:
* type: string
* enum: [Show, Hide]
* example: "Show"
* example:
* name: "Updated Science Fiction"
* description: "Updated description for science fiction category"
* visibility: "Show"
* responses:
* 200:
* description: Category updated successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* $ref: '#/components/schemas/Category'
* 404:
* $ref: '#/components/responses/Error'
* 500:
* $ref: '#/components/responses/Error'
*/
router.put('/:id', categoryController.updateCategory);
/**
* @swagger
* /api/categories/{id}:
* delete:
* summary: Delete a category and its parameters
* tags: [Categories]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* description: Category ID
* example: science-fiction
* responses:
* 200:
* description: Category deleted successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* message:
* type: string
* example: "Category 'Science Fiction' deleted successfully"
* data:
* type: object
* properties:
* deletedCategory:
* $ref: '#/components/schemas/Category'
* deletedParameters:
* type: array
* items:
* $ref: '#/components/schemas/Parameter'
* parameterCount:
* type: integer
* example: 3
* 404:
* $ref: '#/components/responses/Error'
* 500:
* $ref: '#/components/responses/Error'
*/
router.delete('/:id', categoryController.deleteCategory);
module.exports = router;