-
Notifications
You must be signed in to change notification settings - Fork 0
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
[DEPRECATED PR]: structure flow to create the assignment #39
[DEPRECATED PR]: structure flow to create the assignment #39
Conversation
…flextensions into 187434223-set-up-flow-to-add-lms-to-course
…434223-set-up-flow-to-add-lms-to-course
cab3d24
to
569dc2e
Compare
def validate_ids! | ||
if params[:name].blank? || params[:external_assignment_id].blank? || params[:course_id].blank? || params[:lms_id].blank? | ||
render json: { error: 'Params required' }, status: :bad_request | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also added a validation class to do some of this validation as well (eg: ensuring that they are integers). The reason why this is important is because we need to make sure we are not introducing any vulnerabilities with user provided input.
def assignment_exists?(course_to_lms, assignment_name, external_assignment_id) | ||
existing_assignment = Assignment.find_by(course_to_lms_id: course_to_lms.id, name: assignment_name, external_assignment_id: external_assignment_id) | ||
if existing_assignment | ||
render json: { message: 'Record already exists' }, status: :ok |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This render causes side effects which we always try to avoid. Instead, we should try to make all renders happen from the controller method which the route calls.
def create_and_render_assignment(course_to_lms, assignment_name, external_assignment_id) | ||
assignment = Assignment.new(course_to_lms_id: course_to_lms.id, name: assignment_name, external_assignment_id: external_assignment_id) | ||
if assignment.save | ||
render json: assignment, status: :created | ||
else | ||
render json: assignment.errors, status: :unprocessable_entity | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say it might be better to include this in the controller method logic itself since it renders stuff. Since the method is clear about the fact that it renders, it makes it a bit clearer, but I still tend to avoid it since it is "side-effecty"
def validate_ids! | ||
if params[:course_id].blank? || params[:lms_id].blank? || params[:external_course_id].blank? | ||
render json: { error: 'course_id and lms_id are required' }, status: :bad_request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets also use the validation library for these as well
t.bigint "course_to_lms_id", null: false | ||
t.index ["course_to_lms_id"], name: "index_assignments_on_course_to_lms_id" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assignment is owned by a course which is owned by an lms so shouldn't we use that relation to get this value instead of adding it to every assignment?
t.string "name" | ||
t.datetime "created_at", null: false | ||
t.datetime "updated_at", null: false | ||
t.string "external_assignment_id" | ||
t.index ["lms_id"], name: "index_assignments_on_lms_id" | ||
t.bigint "course_to_lms_id", null: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is supposed to be a reference to a join table, it should prob be a foreign key only
…434339-structure-flow-to-create-the-assignment
General Info
This is a deprecated pr messed up with many unrelated commits. So I created a new branch and made a new pr with clean commits, plus amended the code according to the comments in this deprecated pr.
Changes
Explain your changes here (in such a way that you would understand why you made them a year from now).
Assignment
Table. Now it should rely onCourse_to_lms
Table instead oflms
Table.create
method within the assignment controllerTesting
course
andlms
exist before. It uses a foreign key ofcourse_to_lms_id
to ensure this.course_to_lms_id
andexternal_assignment_id
that we want to create.Documentation
Updated E-R diagram
Checklist