This commit is contained in:
silverpro89
2026-01-26 20:23:08 +07:00
parent 53d97ba5db
commit 2c7b4675a7
49 changed files with 12668 additions and 1 deletions

337
routes/vocabRoutes.js Normal file
View File

@@ -0,0 +1,337 @@
const express = require('express');
const router = express.Router();
const vocabController = require('../controllers/vocabController');
const { authenticateToken } = require('../middleware/auth');
/**
* @swagger
* tags:
* name: Vocabulary
* description: Vocabulary management system for curriculum-based language learning
*/
/**
* @swagger
* /api/vocab:
* post:
* summary: Create a new vocabulary entry
* tags: [Vocabulary]
* security:
* - bearerAuth: []
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/VocabComplete'
* example:
* vocab_code: "vocab-001-eat"
* base_word: "eat"
* translation: "ăn"
* attributes:
* difficulty_score: 1
* category: "Action Verbs"
* images:
* - "https://cdn.sena.tech/img/eat-main.png"
* - "https://cdn.sena.tech/img/eat-context.jpg"
* tags: ["daily-routine", "verb"]
* mappings:
* - book_id: "global-success-1"
* grade: 1
* unit: 2
* lesson: 3
* form_key: "v1"
* - book_id: "global-success-2"
* grade: 2
* unit: 5
* lesson: 1
* form_key: "v_ing"
* forms:
* v1:
* text: "eat"
* phonetic: "/iːt/"
* audio: "https://cdn.sena.tech/audio/eat_v1.mp3"
* min_grade: 1
* v_s_es:
* text: "eats"
* phonetic: "/iːts/"
* audio: "https://cdn.sena.tech/audio/eats_s.mp3"
* min_grade: 2
* v_ing:
* text: "eating"
* phonetic: "/ˈiː.tɪŋ/"
* audio: "https://cdn.sena.tech/audio/eating_ing.mp3"
* min_grade: 2
* v2:
* text: "ate"
* phonetic: "/et/"
* audio: "https://cdn.sena.tech/audio/ate_v2.mp3"
* min_grade: 3
* relations:
* synonyms: ["consume", "dine"]
* antonyms: ["fast", "starve"]
* syntax:
* is_subject: false
* is_verb: true
* is_object: false
* is_be: false
* is_adj: false
* verb_type: "transitive"
* semantics:
* can_be_subject_type: ["human", "animal"]
* can_take_object_type: ["food", "plant"]
* word_type: "action"
* constraints:
* requires_object: true
* semantic_object_types: ["food", "plant"]
* responses:
* 201:
* description: Vocabulary created successfully
* 400:
* description: Invalid input
* 500:
* description: Server error
*/
router.post('/', authenticateToken, vocabController.createVocab);
/**
* @swagger
* /api/vocab:
* get:
* summary: Get all vocabulary entries with pagination and filters
* tags: [Vocabulary]
* 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: category
* schema:
* type: string
* description: Filter by category (e.g., "Action Verbs")
* - in: query
* name: grade
* schema:
* type: integer
* description: Filter by grade level
* - in: query
* name: book_id
* schema:
* type: string
* description: Filter by book ID (e.g., "global-success-1")
* - in: query
* name: difficulty_min
* schema:
* type: integer
* description: Minimum difficulty score
* - in: query
* name: difficulty_max
* schema:
* type: integer
* description: Maximum difficulty score
* - in: query
* name: search
* schema:
* type: string
* description: Search in base_word, translation, or vocab_code
* - in: query
* name: include_relations
* schema:
* type: string
* enum: ['true', 'false']
* default: 'false'
* description: Include synonyms/antonyms in response
* responses:
* 200:
* description: List of vocabularies
* 500:
* description: Server error
*/
router.get('/', authenticateToken, vocabController.getAllVocabs);
/**
* @swagger
* /api/vocab/curriculum:
* get:
* summary: Get vocabularies by curriculum mapping
* tags: [Vocabulary]
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: book_id
* required: false
* schema:
* type: string
* description: Book ID (e.g., "global-success-1")
* - in: query
* name: grade
* required: false
* schema:
* type: integer
* description: Grade level
* - in: query
* name: unit
* schema:
* type: integer
* description: Unit number
* - in: query
* name: lesson
* schema:
* type: integer
* description: Lesson number
* responses:
* 200:
* description: List of vocabularies for the specified curriculum
* 400:
* description: Invalid parameters
* 500:
* description: Server error
*/
router.get('/curriculum', authenticateToken, vocabController.getVocabsByCurriculum);
/**
* @swagger
* /api/vocab/guide:
* get:
* summary: Get comprehensive guide for AI to create vocabulary entries
* tags: [Vocabulary]
* 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
* rules:
* type: object
* examples:
* type: object
* 500:
* description: Server error
*/
router.get('/guide', authenticateToken, vocabController.getVocabGuide);
/**
* @swagger
* /api/vocab/stats:
* get:
* summary: Get vocabulary statistics
* tags: [Vocabulary]
* security:
* - bearerAuth: []
* responses:
* 200:
* description: Vocabulary statistics
* 500:
* description: Server error
*/
router.get('/stats', authenticateToken, vocabController.getVocabStats);
/**
* @swagger
* /api/vocab/{id}:
* get:
* summary: Get vocabulary by ID or code
* tags: [Vocabulary]
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* description: Vocabulary ID (numeric) or vocab_code (string)
* responses:
* 200:
* description: Vocabulary details
* 404:
* description: Vocabulary not found
* 500:
* description: Server error
*/
router.get('/:id', authenticateToken, vocabController.getVocabById);
/**
* @swagger
* /api/vocab/{id}:
* put:
* summary: Update vocabulary entry
* tags: [Vocabulary]
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* description: Vocabulary ID (numeric) or vocab_code (string)
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/VocabComplete'
* example:
* translation: "ăn uống"
* attributes:
* difficulty_score: 2
* tags: ["daily-routine", "verb", "food"]
* responses:
* 200:
* description: Vocabulary updated successfully
* 404:
* description: Vocabulary not found
* 500:
* description: Server error
*/
router.put('/:id', authenticateToken, vocabController.updateVocab);
/**
* @swagger
* /api/vocab/{id}:
* delete:
* summary: Delete vocabulary (soft delete)
* tags: [Vocabulary]
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* description: Vocabulary ID (numeric) or vocab_code (string)
* responses:
* 200:
* description: Vocabulary deleted successfully
* 404:
* description: Vocabulary not found
* 500:
* description: Server error
*/
router.delete('/:id', authenticateToken, vocabController.deleteVocab);
module.exports = router;