devvspaces/EduHub

create contoller for user-courses

Opened this issue · 3 comments

Musoye commented

create user_courses controller

The file should be under controller/user_courses.js

The schema contain - user_id, course_id

  • create a function createCourseForUser that creates a new course for user.
    This function will accept the request object and if user_id not a user return a 404 error user not found and if course_id is not course return 404 course not found. If everything is okay, Create the new course for a user and return status code 201 with new object created.

  • create a function getUserCourses that get all courses for a particular user with a user_id in the database. return status code 200 with all the courses.

  • create a function getCoursesUser that get all users for a particular course with a particular course_id. The ID will be part of the url(params). If okay, return the user with 200 statuscode

  • create a function deleteUserCourse. Check if user exist else return 404 with error user not found. This id get a course with a particular course_id. The ID will be part of the url(params). If course not found return 404 with error course not found. Then delete this course for this user and return 200 with details of course and user_id deleted

POST - createCourseForUser, deleteUserCourse
GET - getCoursesUser , getUserCourses

routes

/user-courses/:user_id -> getUserCourses
/:course_id/users/ -> createCourseForUser, deleteUserCourse
/:user_id/courses/:course_id -> getCoursesUser

Import this into and include the routes in routes/user_courses.js then include it in server.js.
Test everything if possible.(Optional: Write an automated testing for testing each endpoints in user_courses_test.py/.js)

Do I need to add in the database config or would that be given??

Yes you need to

You can configure it