forked from saasbook/flextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Add]: set up flow to add lms to course (#41)
* Add models for course_to_lms * Implement creating association in course_to_lms * Test for creating association in course_to_lms * added space in schema for canvas data * Replace the external_course_id from courses table to course_to_lmss table * Take external_course_id into consideration * test coverage badge update * test coverage badge update 2 * code climate yml file updated * code climate yml file updated 2 * badge fix to linux * added codeclimate test reporter * added gems * simple cov version downgraded * simplecov v17 * secret added * secret added2 * secret added3 * secret added4 * initial changes to create user * drafted * validation email added * chnages added: new+save, has many asso for extension * Merge latest main into feature branch and resolve conflict * Refactor the controller and add integer validation * Fix potential issue in lmss_controller * Add validation check for lms * Use validation helper * Amend minor comments --------- Co-authored-by: Evan Kandell <[email protected]> Co-authored-by: Sepehr Behmanesh Fard <[email protected]>
- Loading branch information
1 parent
6b89523
commit cd1ed11
Showing
3 changed files
with
144 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,67 @@ | ||
module Api | ||
module V1 | ||
class LmssController < BaseController | ||
before_action :validate_name!, only: [:create] | ||
|
||
def create | ||
render :json => 'not yet implemented'.to_json, status: 501 | ||
end | ||
include CanvasValidationHelper | ||
before_action :validate_ids!, only: [:create] | ||
|
||
def index | ||
render :json => 'not yet implemented'.to_json, status: 501 | ||
render json: { message: 'not yet implemented'}, status: 501 | ||
end | ||
|
||
def destroy | ||
render :json => 'not yet implemented'.to_json, status: 501 | ||
render json: { message: 'not yet implemented'}, status: 501 | ||
end | ||
|
||
## | ||
# Validator definitions. | ||
# TODO: this should be exported to its own (validator) class. | ||
# TODO: this validation should also check the config file for the name of lms's. | ||
# | ||
def validate_name! | ||
if params['name'].blank? | ||
render :json => 'name parameter is required', status: 401 | ||
# POST /courses/:course_id/lmss | ||
def create | ||
course_id = params[:course_id] | ||
lms_id = params[:lms_id] | ||
external_course_id = params[:external_course_id] | ||
|
||
# Ensure that the course and LMS exist | ||
unless Course.exists?(course_id) | ||
render json: { error: 'Course not found' }, status: :not_found | ||
return | ||
end | ||
unless Lms.exists?(lms_id) | ||
render json: { error: 'Lms not found' }, status: :not_found | ||
return | ||
end | ||
# Ensure that the association does not already exist | ||
existing_entry = CourseToLms.find_by(course_id: course_id, lms_id: lms_id, external_course_id: external_course_id) | ||
if existing_entry | ||
render json: { message: 'The association between the specified course and LMS already exists.' }, status: :ok | ||
return | ||
end | ||
# Create the association | ||
course_to_lms = CourseToLms.new( | ||
course_id: course_id, | ||
lms_id: lms_id, | ||
external_course_id: external_course_id | ||
) | ||
|
||
if course_to_lms.save | ||
render json: course_to_lms, status: :created | ||
else | ||
render json: course_to_lms.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def validate_ids! | ||
begin | ||
params.require([:course_id, :lms_id, :external_course_id]) | ||
rescue ActionController::ParameterMissing => e | ||
render json: { error: e.message }, status: :bad_request | ||
return | ||
else | ||
unless is_valid_course_id(params[:course_id].to_i) && is_valid_lms_id(params[:lms_id].to_i) | ||
render json: { error: 'Invalid course_id or lms_id' }, status: :bad_request | ||
return | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters