Skip to content

Commit

Permalink
Merge pull request #74 from Anushkabh/anushkab
Browse files Browse the repository at this point in the history
get course lecture
  • Loading branch information
anand-harsh authored Jan 20, 2024
2 parents 58d83b1 + 72c6ff6 commit 96398bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 19 additions & 0 deletions controllers/courseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,22 @@ export const addLectureToCourse = catchAsyncError(async (req, res, next) => {
});
});

export const getCourseLectures = catchAsyncError(async (req, res, next) => {
const courseId = req.params.id;

const course = await Course.findById(courseId);

if (!course) {
return next(new ErrorHandler("Course not found", 404));
}

course.views += 1;
await course.save();

res.status(200).json({
success: true,
course,
});
});


4 changes: 3 additions & 1 deletion routes/courseRoutes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express from "express"
import { getAllCourses , createCourse,addLectureToCourse} from "../controllers/courseController.js"
import { getAllCourses , createCourse,addLectureToCourse, getCourseLectures} from "../controllers/courseController.js"
import { isAdminAuthenticated } from "../middlewares/adminAuth.js";
import { isAuthenticated } from "../middlewares/Auth.js";
const router=express.Router()
Expand All @@ -12,6 +12,8 @@ router.route("/createcourse").post(isAdminAuthenticated,createCourse)

// TODO: add lecturs, only Admins
router.post("/course/:id", isAuthenticated, isAdminAuthenticated, addLectureToCourse);
// Get lectures of a course
router.get("/course/:id",isAuthenticated, getCourseLectures);

// TODO: Delete lectures,

Expand Down

0 comments on commit 96398bf

Please sign in to comment.