Implemented add_user in courses controller #44
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
General Info
Changes
Explain your changes here (in such a way that you would understand why you made them a year from now).
Implemented
add_user
method inclass CoursesController
. This method acceptscourse_id
anduser_id
in the request body and adds an entry to theuser_to_courses
table andUserToCourse
model.Testing
Explain how you tested your changes. If testing is not necessary, explain why.
Tests cover these cases:
(1) If either the provided
course_id
does not exist in thecourses
table or the provideduser_id
does not exists in theusers
tables, theadd_user
method should returnnot_found
status and an error message in the JSON response.(2) If the user is already added to the course, in the JSON response return an error message saying "The user is already added to the course".
(3) Happy path:
course_id
anduser_id
exist in their corresponding tables, and an entry with thecourse_id
,user_id
, androle
is successfully added to theuser_to_courses
table andUserToCourse
model.Documentation
Does this PR require documentation. If so, explain where it can be found.
Checklist