update
This commit is contained in:
333
routes/storyRoutes.js
Normal file
333
routes/storyRoutes.js
Normal file
@@ -0,0 +1,333 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const storyController = require('../controllers/storyController');
|
||||
const { authenticateToken } = require('../middleware/auth');
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* tags:
|
||||
* name: Stories
|
||||
* description: Story management system for interactive learning content
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/stories:
|
||||
* post:
|
||||
* summary: Create a new story
|
||||
* tags: [Stories]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - name
|
||||
* properties:
|
||||
* name:
|
||||
* type: string
|
||||
* example: "The Greedy Cat"
|
||||
* logo:
|
||||
* type: string
|
||||
* example: "https://cdn.sena.tech/thumbs/greedy-cat.jpg"
|
||||
* vocabulary:
|
||||
* type: array
|
||||
* items:
|
||||
* type: string
|
||||
* example: ["cat", "eat", "apple", "happy", "greedy"]
|
||||
* context:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* image:
|
||||
* type: string
|
||||
* text:
|
||||
* type: string
|
||||
* audio:
|
||||
* type: string
|
||||
* order:
|
||||
* type: integer
|
||||
* example:
|
||||
* - image: "https://cdn.sena.tech/story/scene1.jpg"
|
||||
* text: "Once upon a time, there was a greedy cat."
|
||||
* audio: "https://cdn.sena.tech/audio/scene1.mp3"
|
||||
* order: 1
|
||||
* - image: "https://cdn.sena.tech/story/scene2.jpg"
|
||||
* text: "The cat loved eating apples every day."
|
||||
* audio: "https://cdn.sena.tech/audio/scene2.mp3"
|
||||
* order: 2
|
||||
* grade:
|
||||
* type: array
|
||||
* items:
|
||||
* type: string
|
||||
* example: ["Grade 1", "Grade 2"]
|
||||
* tag:
|
||||
* type: array
|
||||
* items:
|
||||
* type: string
|
||||
* example: ["animals", "food", "lesson", "health", "fiction"]
|
||||
* responses:
|
||||
* 201:
|
||||
* description: Story created successfully
|
||||
* 400:
|
||||
* description: Invalid input
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.post('/', authenticateToken, storyController.createStory);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/stories:
|
||||
* get:
|
||||
* summary: Get all stories with pagination and filters
|
||||
* tags: [Stories]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: page
|
||||
* schema:
|
||||
* type: integer
|
||||
* default: 1
|
||||
* description: Page number
|
||||
* - in: query
|
||||
* name: limit
|
||||
* schema:
|
||||
* type: integer
|
||||
* default: 20
|
||||
* description: Items per page
|
||||
* - in: query
|
||||
* name: search
|
||||
* schema:
|
||||
* type: string
|
||||
* description: Search in story name
|
||||
* - in: query
|
||||
* name: grade_filter
|
||||
* schema:
|
||||
* type: string
|
||||
* description: Filter by grade (e.g., "Grade 1")
|
||||
* - in: query
|
||||
* name: tag_filter
|
||||
* schema:
|
||||
* type: string
|
||||
* description: Filter by tag (e.g., "animals")
|
||||
* - in: query
|
||||
* name: sort_by
|
||||
* schema:
|
||||
* type: string
|
||||
* default: created_at
|
||||
* description: Sort by field
|
||||
* - in: query
|
||||
* name: sort_order
|
||||
* schema:
|
||||
* type: string
|
||||
* enum: [ASC, DESC]
|
||||
* default: DESC
|
||||
* description: Sort order
|
||||
* responses:
|
||||
* 200:
|
||||
* description: List of stories
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.get('/', authenticateToken, storyController.getAllStories);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/stories/grade:
|
||||
* get:
|
||||
* summary: Get stories by grade level
|
||||
* tags: [Stories]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: grade
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: Grade level (e.g., "Grade 1")
|
||||
* responses:
|
||||
* 200:
|
||||
* description: List of stories for the specified grade
|
||||
* 400:
|
||||
* description: Missing grade parameter
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.get('/grade', authenticateToken, storyController.getStoriesByGrade);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/stories/tag:
|
||||
* get:
|
||||
* summary: Get stories by tag
|
||||
* tags: [Stories]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: tag
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: Tag name (e.g., "animals")
|
||||
* responses:
|
||||
* 200:
|
||||
* description: List of stories with the specified tag
|
||||
* 400:
|
||||
* description: Missing tag parameter
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.get('/tag', authenticateToken, storyController.getStoriesByTag);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/stories/guide:
|
||||
* get:
|
||||
* summary: Get comprehensive guide for AI to create stories
|
||||
* tags: [Stories]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Complete guide with rules, examples, and data structures
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* guide_version:
|
||||
* type: string
|
||||
* last_updated:
|
||||
* type: string
|
||||
* data_structure:
|
||||
* type: object
|
||||
* context_structure:
|
||||
* type: object
|
||||
* vocabulary_guidelines:
|
||||
* type: object
|
||||
* grade_levels:
|
||||
* type: object
|
||||
* tag_categories:
|
||||
* type: object
|
||||
* examples:
|
||||
* type: object
|
||||
* validation_checklist:
|
||||
* type: array
|
||||
* common_mistakes:
|
||||
* type: array
|
||||
* ai_tips:
|
||||
* type: object
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.get('/guide', authenticateToken, storyController.getStoryGuide);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/stories/stats:
|
||||
* get:
|
||||
* summary: Get story statistics
|
||||
* tags: [Stories]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Story statistics
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.get('/stats', authenticateToken, storyController.getStoryStats);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/stories/{id}:
|
||||
* get:
|
||||
* summary: Get story by ID
|
||||
* tags: [Stories]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: Story ID (UUID)
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Story details
|
||||
* 404:
|
||||
* description: Story not found
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.get('/:id', authenticateToken, storyController.getStoryById);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/stories/{id}:
|
||||
* put:
|
||||
* summary: Update story
|
||||
* tags: [Stories]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: Story ID (UUID)
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* example:
|
||||
* name: "The Greedy Cat (Updated)"
|
||||
* tag: ["animals", "food", "lesson", "health", "fiction", "updated"]
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Story updated successfully
|
||||
* 404:
|
||||
* description: Story not found
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.put('/:id', authenticateToken, storyController.updateStory);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/stories/{id}:
|
||||
* delete:
|
||||
* summary: Delete story
|
||||
* tags: [Stories]
|
||||
* security:
|
||||
* - bearerAuth: []
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: Story ID (UUID)
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Story deleted successfully
|
||||
* 404:
|
||||
* description: Story not found
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.delete('/:id', authenticateToken, storyController.deleteStory);
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user