Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create contoller for user-courses #7

Open
Musoye opened this issue Oct 18, 2023 · 3 comments · May be fixed by #27
Open

create contoller for user-courses #7

Musoye opened this issue Oct 18, 2023 · 3 comments · May be fixed by #27

Comments

@Musoye
Copy link
Collaborator

Musoye commented Oct 18, 2023

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)

@Adedejiosvaldo
Copy link

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

@devvspaces
Copy link
Owner

Yes you need to

@devvspaces
Copy link
Owner

You can configure it

@Arun-cn Arun-cn linked a pull request Oct 31, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants