This commit is contained in:
@@ -11,7 +11,7 @@ class ContextController {
|
|||||||
*/
|
*/
|
||||||
async createContext(req, res, next) {
|
async createContext(req, res, next) {
|
||||||
try {
|
try {
|
||||||
const { title, desc, grade, type } = req.body;
|
const { title, desc, grade, type, type_image , reference_id } = req.body;
|
||||||
|
|
||||||
// Validate required fields
|
// Validate required fields
|
||||||
if (!title || !desc || !grade) {
|
if (!title || !desc || !grade) {
|
||||||
@@ -35,9 +35,11 @@ class ContextController {
|
|||||||
desc,
|
desc,
|
||||||
grade: gradeNum,
|
grade: gradeNum,
|
||||||
type: type || 'general',
|
type: type || 'general',
|
||||||
|
type_image: type_image || null,
|
||||||
status: 0, // Draft
|
status: 0, // Draft
|
||||||
context: '',
|
context: '',
|
||||||
knowledge: ''
|
knowledge: '',
|
||||||
|
reference_id: reference_id || null
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(201).json({
|
res.status(201).json({
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ class LessonController {
|
|||||||
is_published,
|
is_published,
|
||||||
is_free,
|
is_free,
|
||||||
lesson_type,
|
lesson_type,
|
||||||
|
lesson_content_type,
|
||||||
|
chapter_id,
|
||||||
search
|
search
|
||||||
} = req.query;
|
} = req.query;
|
||||||
|
|
||||||
@@ -24,6 +26,9 @@ class LessonController {
|
|||||||
const where = {};
|
const where = {};
|
||||||
|
|
||||||
// Filters
|
// Filters
|
||||||
|
if (chapter_id) {
|
||||||
|
where.chapter_id = chapter_id;
|
||||||
|
}
|
||||||
if (is_published !== undefined) {
|
if (is_published !== undefined) {
|
||||||
where.is_published = is_published === 'true';
|
where.is_published = is_published === 'true';
|
||||||
}
|
}
|
||||||
@@ -33,6 +38,9 @@ class LessonController {
|
|||||||
if (lesson_type) {
|
if (lesson_type) {
|
||||||
where.lesson_type = lesson_type;
|
where.lesson_type = lesson_type;
|
||||||
}
|
}
|
||||||
|
if (lesson_content_type) {
|
||||||
|
where.lesson_content_type = lesson_content_type;
|
||||||
|
}
|
||||||
if (search) {
|
if (search) {
|
||||||
where.lesson_title = { [Op.like]: `%${search}%` };
|
where.lesson_title = { [Op.like]: `%${search}%` };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ const Story = sequelize.define('stories', {
|
|||||||
allowNull: false,
|
allowNull: false,
|
||||||
comment: 'Story title/name'
|
comment: 'Story title/name'
|
||||||
},
|
},
|
||||||
|
thumbnail: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: true,
|
||||||
|
comment: 'URL to story thumbnail image'
|
||||||
|
},
|
||||||
logo: {
|
logo: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
|
|||||||
@@ -51,6 +51,32 @@ const { authenticateToken } = require('../middleware/auth');
|
|||||||
*/
|
*/
|
||||||
router.get('/', lessonController.getAllLessons);
|
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
|
* @swagger
|
||||||
* /api/lessons/{id}:
|
* /api/lessons/{id}:
|
||||||
@@ -138,7 +164,7 @@ router.get('/:id/games', lessonController.getMatchingGames);
|
|||||||
* 201:
|
* 201:
|
||||||
* description: Tạo bài học thành công
|
* description: Tạo bài học thành công
|
||||||
*/
|
*/
|
||||||
router.post('/', authenticateToken, lessonController.createLesson);
|
router.post('/', lessonController.createLesson);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
@@ -165,7 +191,7 @@ router.post('/', authenticateToken, lessonController.createLesson);
|
|||||||
* 200:
|
* 200:
|
||||||
* description: Cập nhật thành công
|
* description: Cập nhật thành công
|
||||||
*/
|
*/
|
||||||
router.put('/:id', authenticateToken, lessonController.updateLesson);
|
router.put('/:id', lessonController.updateLesson);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
@@ -186,7 +212,7 @@ router.put('/:id', authenticateToken, lessonController.updateLesson);
|
|||||||
* 200:
|
* 200:
|
||||||
* description: Xóa thành công
|
* description: Xóa thành công
|
||||||
*/
|
*/
|
||||||
router.delete('/:id', authenticateToken, lessonController.deleteLesson);
|
router.delete('/:id', lessonController.deleteLesson);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
@@ -219,6 +245,6 @@ router.delete('/:id', authenticateToken, lessonController.deleteLesson);
|
|||||||
* 200:
|
* 200:
|
||||||
* description: Hoàn thành bài học
|
* description: Hoàn thành bài học
|
||||||
*/
|
*/
|
||||||
router.post('/:id/complete', authenticateToken, lessonController.completeLesson);
|
router.post('/:id/complete', lessonController.completeLesson);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
Reference in New Issue
Block a user