Commit f15726d6 authored by janithGamage's avatar janithGamage

feat: update

Desc : curriculum , tutorial backend config
parent cbd507de
import Curriculum from '../models/curriculum.model.js';
export const getAllCurriculums = async (req, res) => {
try {
const curriculums = await Curriculum.find();
res.status(200).json(curriculums);
} catch (error) {
res.status(500).json({ message: error.message });
}
}
export const getCurriculumById = async (req, res) => {
const { id } = req.params;
try {
const curriculum = await Curriculum.findById(id);
res.status(200).json(curriculum);
} catch (error) {
res.status(404).json({ message: 'Curriculum not found' });
}
}
export const createCurriculum = async (req, res) => {
const curriculumData = req.body;
try {
const newCurriculum = new Curriculum(curriculumData);
await newCurriculum.save();
res.status(201).json(newCurriculum);
} catch (error) {
res.status(400).json({ message: error.message });
}
}
export const updateCurriculum = async (req, res) => {
const { id } = req.params;
const updatedCurriculum = req.body;
try {
const result = await Curriculum.findByIdAndUpdate(id, updatedCurriculum, { new: true });
res.status(200).json(result);
} catch (error) {
res.status(404).json({ message: 'Curriculum not found' });
}
}
export const deleteCurriculum = async (req, res) => {
const { id } = req.params;
try {
await Curriculum.findByIdAndDelete(id);
res.status(200).json({ message: 'Curriculum deleted successfully' });
} catch (error) {
res.status(404).json({ message: 'Curriculum not found' });
}
}
import Tutorial from '../models/tutorial.model';
export const getAllTutorials = async (req, res) => {
try {
const tutorials = await Tutorial.find();
res.status(200).json(tutorials);
} catch (error) {
res.status(500).json({ message: error.message });
}
}
export const getTutorialById = async (req, res) => {
const { id } = req.params;
try {
const tutorial = await Tutorial.findById(id);
res.status(200).json(tutorial);
} catch (error) {
res.status(404).json({ message: 'Tutorial not found' });
}
}
export const createTutorial = async (req, res) => {
const tutorialData = req.body;
try {
const newTutorial = new Tutorial(tutorialData);
await newTutorial.save();
res.status(201).json(newTutorial);
} catch (error) {
res.status(400).json({ message: error.message });
}
}
export const updateTutorial = async (req, res) => {
const { id } = req.params;
const updatedTutorial = req.body;
try {
const result = await Tutorial.findByIdAndUpdate(id, updatedTutorial, { new: true });
res.status(200).json(result);
} catch (error) {
res.status(404).json({ message: 'Tutorial not found' });
}
}
export const deleteTutorial = async (req, res) => {
const { id } = req.params;
try {
await Tutorial.findByIdAndDelete(id);
res.status(200).json({ message: 'Tutorial deleted successfully' });
} catch (error) {
res.status(404).json({ message: 'Tutorial not found' });
}
}
import mongoose from "mongoose";
const tutorialSchema = new mongoose.Schema({
tutorialCode: String,
tutorialTitle: String,
tutorialImage: String,
// Additional fields for tutorial content
});
const curriculumSchema = new mongoose.Schema({
curriculumCode: String,
curriculumLevel: String,
curriculumName: String,
curriculumImage: String,
tutorials: [tutorialSchema], // Embed tutorials as subdocuments
// Additional fields for curriculum details
});
const Curriculum = mongoose.model("Curriculum", curriculumSchema);
export default Curriculum;
import mongoose from "mongoose";
const taskItemSchema = new mongoose.Schema({
title: String,
description: String,
howToDo: String,
referenceImage: String,
referenceVideo: String,
// Additional fields for task items
});
const tutorialSchema = new mongoose.Schema({
tutorialCode: String,
tutorialTitle: String,
tutorialImage: String,
taskItems: [taskItemSchema], // Embed task items as subdocuments
// Additional fields for tutorial details
});
const Tutorial = mongoose.model("Tutorial", tutorialSchema);
export default Tutorial;
import express from "express";
import {
createCurriculum,
deleteCurriculum,
getAllCurriculums,
getCurriculumById,
updateCurriculum
} from "../controllers/curriculum.controller.js";
const router = express.Router();
router.get('/', getAllCurriculums);
router.get('/:id', getCurriculumById);
router.post('/', createCurriculum);
router.put('/:id', updateCurriculum);
router.delete('/:id', deleteCurriculum);
export default router;
import express from "express";
import {
getAllTutorials,
getTutorialById,
createTutorial,
updateTutorial,
deleteTutorial
} from "../controllers/tutorial.controller.js";
const router = express.Router();
router.get('/', getAllTutorials);
router.get('/:id', getTutorialById);
router.post('/', createTutorial);
router.put('/:id', updateTutorial);
router.delete('/:id', deleteTutorial);
export default router;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment