Files
sena_db_api_layer/routes/lessonRoutes.js
silverpro89 47ab75f264
All checks were successful
Deploy to Production / deploy (push) Successful in 19s
Update backend 2
2026-02-25 20:05:00 +07:00

251 lines
6.0 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);
module.exports = router;