This commit is contained in:
4
app.js
4
app.js
@@ -166,7 +166,7 @@ app.get('/api', (req, res) => {
|
||||
lessons: '/api/lessons',
|
||||
games: '/api/games',
|
||||
gameTypes: '/api/game-types',
|
||||
vocab: '/api/vocab',
|
||||
vocabs: '/api/vocabs',
|
||||
contexts: '/api/contexts',
|
||||
contextGuides: '/api/context-guides',
|
||||
upload: '/api/upload',
|
||||
@@ -223,7 +223,7 @@ app.use('/api/chapters', chapterLessonRoutes); // Nested route: /api/chapters/:i
|
||||
app.use('/api/games', gameRoutes);
|
||||
app.use('/api/game-types', gameTypeRoutes);
|
||||
app.use('/api/lessons', lessonRoutes);
|
||||
app.use('/api/vocab', vocabRoutes);
|
||||
app.use('/api/vocabs', vocabRoutes);
|
||||
app.use('/api/grammar', grammarRoutes);
|
||||
app.use('/api/stories', storyRoutes);
|
||||
app.use('/api/learning-content', learningContentRoutes);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { Context } = require('../models');
|
||||
const { Context, Vocab } = require('../models');
|
||||
|
||||
/**
|
||||
* Context Controller - Workflow-based status management
|
||||
@@ -220,6 +220,28 @@ class ContextController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk update all status 2 to status 3 (Prompt Ready -> Generating)
|
||||
*/
|
||||
async bulkUpdateStatus2To3(req, res, next) {
|
||||
try {
|
||||
const [affectedCount] = await Context.update(
|
||||
{ status: 3 },
|
||||
{ where: { status: 2 } }
|
||||
);
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: `Updated ${affectedCount} context(s) from status 2 to status 3`,
|
||||
data: {
|
||||
affectedCount
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add images - Status 3 -> 4 (Image Ready)
|
||||
*/
|
||||
@@ -286,9 +308,28 @@ class ContextController {
|
||||
message: 'Context must be in Image Ready status (4) to approve'
|
||||
});
|
||||
}
|
||||
|
||||
await context.update({ status: 5 });
|
||||
|
||||
// add image to Vocab Image
|
||||
const currentVocab = await Vocab.findOne({ where: { vocab_id: context.reference_id } });
|
||||
console.log('Current Vocab:', currentVocab);
|
||||
if (currentVocab) {
|
||||
if (context.type_image === 'small') {
|
||||
const updatedImagesSmall = currentVocab.image_small || [];
|
||||
updatedImagesSmall.push(context.image);
|
||||
await currentVocab.update({ image_small: updatedImagesSmall });
|
||||
} else if (context.type_image === 'square') {
|
||||
const updatedImagesSquare = currentVocab.image_square || [];
|
||||
updatedImagesSquare.push(context.image);
|
||||
await currentVocab.update({ image_square: updatedImagesSquare });
|
||||
} else if (context.type_image === 'normal') {
|
||||
const updatedImagesNormal = currentVocab.image_normal || [];
|
||||
updatedImagesNormal.push(context.image);
|
||||
await currentVocab.update({ image_normal: updatedImagesNormal });
|
||||
}
|
||||
await currentVocab.save();
|
||||
}
|
||||
await context.update({
|
||||
status: 5
|
||||
});
|
||||
res.json({
|
||||
success: true,
|
||||
message: 'Context approved successfully',
|
||||
|
||||
@@ -96,8 +96,7 @@ exports.getAllStories = async (req, res) => {
|
||||
where,
|
||||
limit: parseInt(limit),
|
||||
offset,
|
||||
order: [[sort_by, sort_order.toUpperCase()]],
|
||||
attributes: ['id', 'name', 'logo', 'grade', 'tag', 'created_at', 'updated_at']
|
||||
order: [[sort_by, sort_order.toUpperCase()]]
|
||||
});
|
||||
|
||||
res.json({
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,5 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../config/database');
|
||||
const { ref } = require('joi');
|
||||
|
||||
const Context = sequelize.define('Context', {
|
||||
uuid: {
|
||||
|
||||
@@ -24,16 +24,9 @@ const Vocab = sequelize.define('Vocab', {
|
||||
allowNull: false,
|
||||
index: true
|
||||
},
|
||||
// Đã xuất hiện trong khối nào, bài học nào, lesson nào
|
||||
// Ví dụ 111 là grade 1, unit 1, lesson 1
|
||||
grade: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0,
|
||||
comment: 'It is number of gradeX100 + unitX10 + lesson (e.g., Grade 1 Unit 2 Lesson 3 = 123)'
|
||||
},
|
||||
// Loại biến thể (V1, V2, V3, V_ing, Noun_Form...)
|
||||
form_key: {
|
||||
type: DataTypes.JSON,
|
||||
type: DataTypes.TEXT,
|
||||
defaultValue: 'base',
|
||||
comment: 'Form key indicating the type of word form (e.g., base, V1, V2, V3, V_ing, Noun_Form)'
|
||||
},
|
||||
@@ -47,10 +40,6 @@ const Vocab = sequelize.define('Vocab', {
|
||||
type: DataTypes.STRING(100),
|
||||
comment: 'Category of the word (e.g., Action Verbs, Nouns)'
|
||||
},
|
||||
etc : {
|
||||
type: DataTypes.TEXT,
|
||||
comment: 'Book or additional reference'
|
||||
},
|
||||
topic: {
|
||||
type: DataTypes.STRING(100),
|
||||
comment: 'Topic of the word (e.g., Food, Travel, Education)'
|
||||
@@ -121,10 +110,6 @@ const Vocab = sequelize.define('Vocab', {
|
||||
{
|
||||
name: 'idx_category',
|
||||
fields: ['category']
|
||||
},
|
||||
{
|
||||
name: 'idx_grade',
|
||||
fields: ['grade']
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
@@ -359,6 +359,16 @@
|
||||
<div class="card">
|
||||
<h3>📋 Get Contexts by Status <span class="status-indicator status-2">Status: 2</span></h3>
|
||||
<button onclick="getContextsByStatus(2)">Get Status 2 (Prompt Ready)</button>
|
||||
|
||||
<hr style="margin: 15px 0; border: 1px solid #e0e0e0;">
|
||||
|
||||
<button onclick="bulkUpdateStatus2To3()" style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); margin-top: 10px;">
|
||||
🚀 Quick Approve: All Status 2 → 3
|
||||
</button>
|
||||
<div class="result" id="bulkUpdateResultTop"></div>
|
||||
|
||||
<hr style="margin: 15px 0; border: 1px solid #e0e0e0;">
|
||||
|
||||
<div class="result" id="status2Result"></div>
|
||||
<div class="context-list" id="status2List"></div>
|
||||
</div>
|
||||
@@ -382,6 +392,14 @@
|
||||
</div>
|
||||
<button onclick="updateStatus()">Update Status</button>
|
||||
<div class="result" id="updateStatusResult"></div>
|
||||
|
||||
<hr style="margin: 20px 0; border: 1px solid #e0e0e0;">
|
||||
|
||||
<h4 style="color: #667eea; margin-bottom: 10px;">🚀 Bulk Update</h4>
|
||||
<button onclick="bulkUpdateStatus2To3()" style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);">
|
||||
Update All Status 2 → 3
|
||||
</button>
|
||||
<div class="result" id="bulkUpdateResult"></div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
@@ -643,6 +661,31 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function bulkUpdateStatus2To3() {
|
||||
const headers = getHeaders();
|
||||
|
||||
if (!confirm('Are you sure you want to update ALL contexts from status 2 to status 3?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/bulk/status-2-to-3`, {
|
||||
method: 'POST',
|
||||
headers: headers
|
||||
});
|
||||
const data = await response.json();
|
||||
showResult('bulkUpdateResult', data, response.ok);
|
||||
showResult('bulkUpdateResultTop', data, response.ok);
|
||||
if (response.ok) {
|
||||
getContextsByStatus(3);
|
||||
getContextsByStatus(2);
|
||||
}
|
||||
} catch (error) {
|
||||
showResult('bulkUpdateResult', { error: error.message }, false);
|
||||
showResult('bulkUpdateResultTop', { error: error.message }, false);
|
||||
}
|
||||
}
|
||||
|
||||
async function addImages() {
|
||||
const headers = getHeaders();
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@ router.post('/:id/prepare-prompt', contextController.preparePrompt);
|
||||
// Status 2 -> 3 or 1: Update status
|
||||
router.post('/:id/update-status', contextController.updateStatusFromPromptReady);
|
||||
|
||||
// Bulk update all status 2 to status 3
|
||||
router.post('/bulk/status-2-to-3', contextController.bulkUpdateStatus2To3);
|
||||
|
||||
// Status 3 -> 4: Add images
|
||||
router.post('/:id/add-images', contextController.addImages);
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ const { authenticateToken } = require('../middleware/auth');
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.post('/', authenticateToken, storyController.createStory);
|
||||
router.post('/', storyController.createStory);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -135,7 +135,7 @@ router.post('/', authenticateToken, storyController.createStory);
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.get('/', authenticateToken, storyController.getAllStories);
|
||||
router.get('/', storyController.getAllStories);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -160,7 +160,7 @@ router.get('/', authenticateToken, storyController.getAllStories);
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.get('/grade', authenticateToken, storyController.getStoriesByGrade);
|
||||
router.get('/grade', storyController.getStoriesByGrade);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -185,7 +185,7 @@ router.get('/grade', authenticateToken, storyController.getStoriesByGrade);
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.get('/tag', authenticateToken, storyController.getStoriesByTag);
|
||||
router.get('/tag', storyController.getStoriesByTag);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -228,7 +228,7 @@ router.get('/tag', authenticateToken, storyController.getStoriesByTag);
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.get('/guide', authenticateToken, storyController.getStoryGuide);
|
||||
router.get('/guide', storyController.getStoryGuide);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -244,7 +244,7 @@ router.get('/guide', authenticateToken, storyController.getStoryGuide);
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.get('/stats', authenticateToken, storyController.getStoryStats);
|
||||
router.get('/stats', storyController.getStoryStats);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -269,7 +269,7 @@ router.get('/stats', authenticateToken, storyController.getStoryStats);
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.get('/:id', authenticateToken, storyController.getStoryById);
|
||||
router.get('/:id', storyController.getStoryById);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -303,7 +303,7 @@ router.get('/:id', authenticateToken, storyController.getStoryById);
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.put('/:id', authenticateToken, storyController.updateStory);
|
||||
router.put('/:id', storyController.updateStory);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -328,6 +328,6 @@ router.put('/:id', authenticateToken, storyController.updateStory);
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.delete('/:id', authenticateToken, storyController.deleteStory);
|
||||
router.delete('/:id', storyController.deleteStory);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -4,334 +4,347 @@ const vocabController = require('../controllers/vocabController');
|
||||
const { authenticateToken } = require('../middleware/auth');
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* tags:
|
||||
* name: Vocabulary
|
||||
* description: Vocabulary management system for curriculum-based language learning
|
||||
*/
|
||||
* ============================================
|
||||
* POST /api/vocabs
|
||||
* ============================================
|
||||
* Tạo một vocab entry mới
|
||||
*
|
||||
* INPUT:
|
||||
* {
|
||||
* text: String (required) - từ thực tế (wash, washes, washing, ate, eaten...)
|
||||
* ipa: String - phiên âm IPA (ví dụ: /wɒʃ/)
|
||||
* base_word: String (required) - từ gốc để nhóm lại (wash, eat...)
|
||||
* form_key: JSON - loại biến thể (V1, V2, V3, V_ing, Noun_Form...), mặc định 'base'
|
||||
* vi: String - nghĩa tiếng Việt
|
||||
* category: String - category của từ (Action Verbs, Nouns, etc.)
|
||||
* topic: String - chủ đề (Food, Travel, Education, etc.)
|
||||
* image_small: JSON Array - mảng URLs của hình ảnh nhỏ
|
||||
* image_square: JSON Array - mảng URLs của hình ảnh vuông
|
||||
* image_normal: JSON Array - mảng URLs của hình ảnh bình thường
|
||||
* audio: JSON Array - mảng URLs của audio files
|
||||
* example_sentences: JSON - các câu ví dụ
|
||||
* tags: JSON Array - các tags để phân loại
|
||||
* syntax: JSON - vai trò cú pháp
|
||||
* semantics: JSON - ràng buộc ngữ nghĩa
|
||||
* constraints: JSON - ràng buộc ngữ pháp
|
||||
* }
|
||||
*
|
||||
* OUTPUT:
|
||||
* {
|
||||
* success: Boolean,
|
||||
* message: String,
|
||||
* data: Vocab object đã tạo (bao gồm vocab_id, created_at, updated_at)
|
||||
* }
|
||||
**/
|
||||
|
||||
router.post('/', vocabController.createVocab);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
* ============================================
|
||||
* POST /api/vocabs/bulk
|
||||
* ============================================
|
||||
* Tạo nhiều vocab entries cùng lúc
|
||||
*
|
||||
* INPUT:
|
||||
* {
|
||||
* vocabs: Array of Vocab objects - mỗi object phải có text và base_word
|
||||
* [
|
||||
* {
|
||||
* text: String (required),
|
||||
* base_word: String (required),
|
||||
* ipa: String,
|
||||
* vi: String,
|
||||
* ...
|
||||
* },
|
||||
* ...
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* OUTPUT:
|
||||
* {
|
||||
* success: Boolean,
|
||||
* message: String,
|
||||
* data: Array of created Vocab objects,
|
||||
* count: Number - số lượng vocab đã tạo
|
||||
* }
|
||||
**/
|
||||
router.post('/bulk', vocabController.bulkCreateVocabs);
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
* ============================================
|
||||
* POST /api/vocabs/search
|
||||
* ============================================
|
||||
* Tìm kiếm vocab nâng cao với nhiều filter
|
||||
*
|
||||
* INPUT:
|
||||
* {
|
||||
* topic: String (optional) - chủ đề (exact match)
|
||||
* category: String (optional) - loại từ (exact match)
|
||||
* base_word: String (optional) - từ gốc (partial match với LIKE)
|
||||
* form_key: JSON (optional) - loại biến thể (V1, V2, V3, V_ing, Noun_Form, etc.)
|
||||
* text: String (optional) - từ thực tế (partial match với LIKE)
|
||||
* vi: String (optional) - nghĩa tiếng Việt (partial match với LIKE)
|
||||
*
|
||||
* v_type: Boolean (optional) - tìm các biến thể khác của cùng một base_word
|
||||
* base_word_filter: String (optional) - base_word cụ thể (dùng khi v_type=true)
|
||||
*
|
||||
* shuffle_pos: Object (optional) - tìm từ thay thế dựa trên syntax
|
||||
* {
|
||||
* is_subject: Boolean,
|
||||
* is_verb: Boolean,
|
||||
* is_object: Boolean,
|
||||
* is_be: Boolean,
|
||||
* is_adj: Boolean,
|
||||
* is_adv: Boolean,
|
||||
* is_article: Boolean
|
||||
* }
|
||||
*
|
||||
* page: Number - trang hiện tại (mặc định: 1)
|
||||
* limit: Number - số items mỗi trang (mặc định: 100)
|
||||
* }
|
||||
*
|
||||
* OUTPUT:
|
||||
* {
|
||||
* success: Boolean,
|
||||
* message: String,
|
||||
* data: Array of Vocab objects,
|
||||
* pagination: {
|
||||
* total: Number,
|
||||
* page: Number,
|
||||
* limit: Number,
|
||||
* totalPages: Number
|
||||
* }
|
||||
* }
|
||||
**/
|
||||
router.post('/search', vocabController.searchVocabs);
|
||||
|
||||
/**
|
||||
* ============================================
|
||||
* GET /api/vocabs
|
||||
* ============================================
|
||||
* Lấy danh sách tất cả vocab với phân trang và filter
|
||||
*
|
||||
* INPUT (Query Parameters):
|
||||
* {
|
||||
* page: Number - trang hiện tại (mặc định: 1)
|
||||
* limit: Number - số items mỗi trang (mặc định: 20)
|
||||
* category: String - lọc theo category
|
||||
* topic: String - lọc theo topic
|
||||
* base_word: String - lọc theo base_word chính xác
|
||||
* text: String - lọc theo text chính xác
|
||||
* search: String - tìm kiếm trong text, base_word và vi
|
||||
* is_active: Boolean - lọc theo trạng thái active (mặc định: true)
|
||||
* }
|
||||
*
|
||||
* OUTPUT:
|
||||
* {
|
||||
* success: Boolean,
|
||||
* message: String,
|
||||
* data: Array of Vocab objects,
|
||||
* pagination: {
|
||||
* total: Number,
|
||||
* page: Number,
|
||||
* limit: Number,
|
||||
* totalPages: Number
|
||||
* }
|
||||
* }
|
||||
*
|
||||
**/
|
||||
router.get('/', 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);
|
||||
* ============================================
|
||||
* GET /api/vocabs/stats/overview
|
||||
* ============================================
|
||||
* Lấy thống kê tổng quan về vocab
|
||||
*
|
||||
* INPUT: Không có
|
||||
*
|
||||
* OUTPUT:
|
||||
* {
|
||||
* success: Boolean,
|
||||
* message: String,
|
||||
* data: {
|
||||
* total: {
|
||||
* active: Number,
|
||||
* inactive: Number,
|
||||
* all: Number
|
||||
* },
|
||||
* unique_base_words: Number,
|
||||
* by_category: Array [{category: String, count: Number}],
|
||||
* by_topic: Array [{topic: String, count: Number}]
|
||||
* }
|
||||
* }
|
||||
**/
|
||||
router.get('/stats/overview', vocabController.getVocabStats);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
* ============================================
|
||||
* GET /api/vocabs/meta/categories
|
||||
* ============================================
|
||||
* Lấy danh sách tất cả categories
|
||||
*
|
||||
* INPUT: Không có
|
||||
*
|
||||
* OUTPUT:
|
||||
* {
|
||||
* success: Boolean,
|
||||
* message: String,
|
||||
* data: Array of String - danh sách categories,
|
||||
* count: Number - số lượng categories
|
||||
* }
|
||||
**/
|
||||
router.get('/meta/categories', vocabController.getAllCategories);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
* ============================================
|
||||
* GET /api/vocabs/meta/topics
|
||||
* ============================================
|
||||
* Lấy danh sách tất cả topics
|
||||
*
|
||||
* INPUT: Không có
|
||||
*
|
||||
* OUTPUT:
|
||||
* {
|
||||
* success: Boolean,
|
||||
* message: String,
|
||||
* data: Array of String - danh sách topics,
|
||||
* count: Number - số lượng topics
|
||||
* }
|
||||
**/
|
||||
router.get('/meta/topics', vocabController.getAllTopics);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
* ============================================
|
||||
* GET /api/vocabs/missing/ipa
|
||||
* ============================================
|
||||
* Lấy tất cả các vocab chưa có IPA
|
||||
*
|
||||
* INPUT (Query Parameters):
|
||||
* {
|
||||
* page: Number - trang hiện tại (mặc định: 1),
|
||||
* limit: Number - số items mỗi trang (mặc định: 50)
|
||||
* }
|
||||
*
|
||||
* OUTPUT:
|
||||
* {
|
||||
* success: Boolean,
|
||||
* message: String,
|
||||
* data: Array of Vocab objects - các vocab chưa có IPA,
|
||||
* pagination: {
|
||||
* total: Number,
|
||||
* page: Number,
|
||||
* limit: Number,
|
||||
* totalPages: Number
|
||||
* }
|
||||
* }
|
||||
**/
|
||||
router.get('/missing/ipa', vocabController.getVocabsWithoutIpa);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
* ============================================
|
||||
* GET /api/vocabs/missing/images
|
||||
* ============================================
|
||||
* Lấy tất cả các vocab chưa đủ hình ảnh
|
||||
*
|
||||
* INPUT (Query Parameters):
|
||||
* {
|
||||
* page: Number - trang hiện tại (mặc định: 1),
|
||||
* limit: Number - số items mỗi trang (mặc định: 50)
|
||||
* }
|
||||
*
|
||||
* OUTPUT:
|
||||
* {
|
||||
* success: Boolean,
|
||||
* message: String,
|
||||
* data: Array of Vocab objects - các vocab chưa đủ hình ảnh,
|
||||
* pagination: {
|
||||
* total: Number,
|
||||
* page: Number,
|
||||
* limit: Number,
|
||||
* totalPages: Number
|
||||
* }
|
||||
* }
|
||||
**/
|
||||
router.get('/missing/images', vocabController.getVocabsWithoutImages);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
* ============================================
|
||||
* GET /api/vocabs/:id
|
||||
* ============================================
|
||||
* Lấy chi tiết một vocab theo ID
|
||||
*
|
||||
* INPUT (URL Parameter):
|
||||
* {
|
||||
* id: UUID - vocab_id của vocab cần lấy
|
||||
* }
|
||||
*
|
||||
* OUTPUT:
|
||||
* {
|
||||
* success: Boolean,
|
||||
* message: String,
|
||||
* data: Vocab object với đầy đủ thông tin
|
||||
* }
|
||||
**/
|
||||
router.get('/:id', vocabController.getVocabById);
|
||||
|
||||
/**
|
||||
* ============================================
|
||||
* PUT /api/vocabs/:id
|
||||
* ============================================
|
||||
* Cập nhật thông tin vocab
|
||||
*
|
||||
* INPUT (URL Parameter + Body):
|
||||
* {
|
||||
* id: UUID - vocab_id cần update
|
||||
* Body: Object - các trường cần update (có thể update một hoặc nhiều trường)
|
||||
* {
|
||||
* text: String,
|
||||
* ipa: String,
|
||||
* base_word: String,
|
||||
* form_key: JSON,
|
||||
* vi: String,
|
||||
* category: String,
|
||||
* topic: String,
|
||||
* image_small: JSON Array,
|
||||
* image_square: JSON Array,
|
||||
* image_normal: JSON Array,
|
||||
* audio: JSON Array,
|
||||
* example_sentences: JSON,
|
||||
* tags: JSON Array,
|
||||
* syntax: JSON,
|
||||
* semantics: JSON,
|
||||
* constraints: JSON,
|
||||
* is_active: Boolean
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* OUTPUT:
|
||||
* {
|
||||
* success: Boolean,
|
||||
* message: String,
|
||||
* data: Updated Vocab object
|
||||
* }
|
||||
* **/
|
||||
router.put('/:id', vocabController.updateVocab);
|
||||
|
||||
/**
|
||||
* ============================================
|
||||
* DELETE /api/vocabs/:id
|
||||
* ============================================
|
||||
* Xóa mềm vocab (set is_active = false)
|
||||
*
|
||||
* INPUT (URL Parameter):
|
||||
* {
|
||||
* id: UUID - vocab_id cần xóa
|
||||
* }
|
||||
*
|
||||
* OUTPUT:
|
||||
* {
|
||||
* success: Boolean,
|
||||
* message: String
|
||||
* }
|
||||
**/
|
||||
router.delete('/:id', vocabController.deleteVocab);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user