Files
sena_db_api_layer/routes/lessonRoutes.js
Ken 6287a019e3
All checks were successful
Deploy to Production / deploy (push) Successful in 20s
update
2026-02-27 09:38:39 +07:00

384 lines
9.3 KiB
JavaScript

const express = require('express');
const router = express.Router();
const lessonController = require('../controllers/lessonController');
const { authenticateToken } = require('../middleware/auth');
/**
* @swagger
* tags:
* name: Lessons
* description: Quản lý bài học
*/
/**
* @swagger
* /api/lessons:
* get:
* tags: [Lessons]
* summary: Lấy danh sách bài học
* description: Lấy tất cả bài học với phân trang và filter
* parameters:
* - in: query
* name: page
* schema:
* type: integer
* default: 1
* - in: query
* name: limit
* schema:
* type: integer
* default: 20
* - in: query
* name: is_published
* schema:
* type: boolean
* - in: query
* name: is_free
* schema:
* type: boolean
* - in: query
* name: lesson_type
* schema:
* type: string
* enum: [json_content, url_content]
* - in: query
* name: search
* schema:
* type: string
* responses:
* 200:
* description: Danh sách bài học
*/
router.get('/', lessonController.getAllLessons);
/**
* @swagger
* /api/lessons/chapter/{chapter_id}:
* get:
* tags: [Lessons]
* summary: Lấy tất cả bài học trong một chapter
* parameters:
* - in: path
* name: chapter_id
* required: true
* schema:
* type: string
* format: uuid
* description: UUID của chapter
* - in: query
* name: include_unpublished
* schema:
* type: boolean
* default: false
* description: Bao gồm cả bài chưa publish
* responses:
* 200:
* description: Danh sách bài học trong chapter
*/
router.get('/chapter/:chapter_id', lessonController.getLessonsByChapter);
/**
* @swagger
* /api/lessons/{id}:
* get:
* tags: [Lessons]
* summary: Lấy chi tiết bài học
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* format: uuid
* responses:
* 200:
* description: Chi tiết bài học
* 404:
* description: Không tìm thấy bài học
*/
router.get('/:id', lessonController.getLessonById);
/**
* @swagger
* /api/lessons/{id}/games:
* get:
* tags: [Lessons]
* summary: Lấy danh sách game phù hợp với bài học
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* format: uuid
* responses:
* 200:
* description: Danh sách game engines
*/
router.get('/:id/games', lessonController.getMatchingGames);
/**
* @swagger
* /api/lessons:
* post:
* tags: [Lessons]
* summary: Tạo bài học mới
* security:
* - bearerAuth: []
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - chapter_id
* - lesson_title
* - lesson_type
* properties:
* chapter_id:
* type: string
* format: uuid
* lesson_number:
* type: integer
* lesson_title:
* type: string
* lesson_type:
* type: string
* enum: [json_content, url_content]
* lesson_description:
* type: string
* content_json:
* type: object
* content_url:
* type: string
* content_type:
* type: string
* duration_minutes:
* type: integer
* is_published:
* type: boolean
* is_free:
* type: boolean
* responses:
* 201:
* description: Tạo bài học thành công
*/
router.post('/', lessonController.createLesson);
/**
* @swagger
* /api/lessons/{id}:
* put:
* tags: [Lessons]
* summary: Cập nhật bài học
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* format: uuid
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* responses:
* 200:
* description: Cập nhật thành công
*/
router.put('/:id', lessonController.updateLesson);
/**
* @swagger
* /api/lessons/{id}:
* delete:
* tags: [Lessons]
* summary: Xóa bài học
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* format: uuid
* responses:
* 200:
* description: Xóa thành công
*/
router.delete('/:id', lessonController.deleteLesson);
/**
* @swagger
* /api/lessons/{id}/complete:
* post:
* tags: [Lessons]
* summary: Đánh dấu hoàn thành bài học
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* format: uuid
* requestBody:
* content:
* application/json:
* schema:
* type: object
* properties:
* score:
* type: integer
* time_spent:
* type: integer
* results_data:
* type: object
* responses:
* 200:
* description: Hoàn thành bài học
*/
router.post('/:id/complete', lessonController.completeLesson);
// ============ Nested Story Routes ============
/**
* @swagger
* /api/lessons/{lessonId}/stories:
* get:
* tags: [Lessons]
* summary: Lấy danh sách stories trong một lesson
* parameters:
* - in: path
* name: lessonId
* required: true
* schema:
* type: string
* format: uuid
* - in: query
* name: page
* schema:
* type: integer
* default: 1
* - in: query
* name: limit
* schema:
* type: integer
* default: 20
* responses:
* 200:
* description: Danh sách stories trong lesson
*/
router.get('/:lessonId/stories', lessonController.getStoriesByLesson);
/**
* @swagger
* /api/lessons/{lessonId}/stories:
* post:
* tags: [Lessons]
* summary: Thêm story vào lesson
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: lessonId
* required: true
* schema:
* type: string
* format: uuid
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - story_id
* properties:
* story_id:
* type: string
* format: uuid
* display_order:
* type: integer
* default: 0
* is_required:
* type: boolean
* default: true
* responses:
* 201:
* description: Story đã được thêm vào lesson
*/
router.post('/:lessonId/stories', lessonController.addStoryToLesson);
/**
* @swagger
* /api/lessons/{lessonId}/stories/{storyId}:
* put:
* tags: [Lessons]
* summary: Cập nhật story trong lesson (display_order, is_required)
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: lessonId
* required: true
* schema:
* type: string
* format: uuid
* - in: path
* name: storyId
* required: true
* schema:
* type: string
* format: uuid
* requestBody:
* content:
* application/json:
* schema:
* type: object
* properties:
* display_order:
* type: integer
* is_required:
* type: boolean
* responses:
* 200:
* description: Cập nhật thành công
*/
router.put('/:lessonId/stories/:storyId', lessonController.updateStoryInLesson);
/**
* @swagger
* /api/lessons/{lessonId}/stories/{storyId}:
* delete:
* tags: [Lessons]
* summary: Xóa story khỏi lesson
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: lessonId
* required: true
* schema:
* type: string
* format: uuid
* - in: path
* name: storyId
* required: true
* schema:
* type: string
* format: uuid
* responses:
* 200:
* description: Story đã được xóa khỏi lesson
*/
router.delete('/:lessonId/stories/:storyId', lessonController.removeStoryFromLesson);
module.exports = router;