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

[Add]: set up flow to add lms to course #41

Merged
merged 34 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
16f6a26
Add models for course_to_lms
Zzz212zzZ Apr 19, 2024
f48fa29
Implement creating association in course_to_lms
Zzz212zzZ Apr 19, 2024
bb98d3d
Test for creating association in course_to_lms
Zzz212zzZ Apr 19, 2024
03264c7
added space in schema for canvas data
ekandell Apr 20, 2024
99ff5e0
Replace the external_course_id from courses table to course_to_lmss t…
Zzz212zzZ Apr 20, 2024
5b4a9e9
Merge branch 'add-canvas-data-to-schema' of https://github.com/cs169/…
Zzz212zzZ Apr 20, 2024
08ed513
Merge branch 'main' of https://github.com/cs169/flextensions into 187…
Zzz212zzZ Apr 20, 2024
6b6f81f
Take external_course_id into consideration
Zzz212zzZ Apr 20, 2024
528292d
test coverage badge update
Apr 12, 2024
b945975
test coverage badge update 2
Apr 12, 2024
b6c16d4
code climate yml file updated
Apr 15, 2024
6f4a173
code climate yml file updated 2
Apr 15, 2024
58108dc
badge fix to linux
Apr 15, 2024
3d49687
added codeclimate test reporter
Apr 18, 2024
ac4ab61
added gems
Apr 18, 2024
c6f0b1a
simple cov version downgraded
Apr 18, 2024
4f94ecd
simplecov v17
Apr 20, 2024
4768889
secret added
Apr 20, 2024
7f47c45
secret added2
Apr 20, 2024
fa42bbd
secret added3
Apr 20, 2024
8c59962
secret added4
Apr 20, 2024
cb90e99
initial changes to create user
Apr 22, 2024
98c5a52
drafted
Apr 22, 2024
4ee7e63
validation email added
Apr 22, 2024
1c03ef8
chnages added: new+save, has many asso for extension
Apr 23, 2024
69eaa49
Merge latest main into feature branch and resolve conflict
Zzz212zzZ Apr 23, 2024
3ba246b
Refactor the controller and add integer validation
Zzz212zzZ Apr 24, 2024
b4216b9
Pull from main and resolve conflict
Zzz212zzZ Apr 24, 2024
cfca6d8
Fix potential issue in lmss_controller
Zzz212zzZ Apr 25, 2024
de66102
Merge conflict from main branch
Zzz212zzZ Apr 25, 2024
adc3bc1
Add validation check for lms
Zzz212zzZ Apr 26, 2024
e94a196
Use validation helper
Zzz212zzZ Apr 26, 2024
0ef28f3
Merge branch 'main' of https://github.com/cs169/flextensions into 187…
Zzz212zzZ Apr 28, 2024
c692f6c
Amend minor comments
Zzz212zzZ Apr 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions app/controllers/api/v1/lmss_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
module Api
module V1
class LmssController < BaseController
before_action :validate_name!, only: [:create]
before_action :validate_ids!, only: [:create]

# POST /courses/:course_id/lmss
def create
render :json => 'not yet implemented'.to_json, status: 501
course_id = params[:course_id] # course_id from the URL
lms_id = params[:lms_id] # lms_id from the body
external_course_id = params[:external_course_id] # external_course_id from the body

# Ensure the course exists
unless Course.exists?(course_id)
render json: { error: 'Course not found' }, status: :not_found
return
end

# Ensure the lms exists
unless Lms.exists?(lms_id)
render json: { error: 'Lms not found' }, status: :not_found
return
end

# Check if the entry already exists
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 course_to_lms entry
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

def index
Expand All @@ -20,9 +55,9 @@ def destroy
# 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
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
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions app/models/course.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# app/models/course.rb

class Course < ApplicationRecord


end
11 changes: 11 additions & 0 deletions app/models/course_to_lms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# app/models/course_to_lms.rb
class CourseToLms < ApplicationRecord
# Association with Course and Lms
belongs_to :course
belongs_to :lms

# You can add validations here if needed, for example:
validates :course_id, presence: true
validates :lms_id, presence: true
end

5 changes: 5 additions & 0 deletions app/models/lms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# app/models/lms.rb
class Lms < ApplicationRecord


end
75 changes: 60 additions & 15 deletions spec/controllers/api/v1/lmss_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,71 @@
module Api
module V1
describe LmssController do
let(:mock_course_id) { 16 }
let(:mock_course_name) { 'testCourseName' }
describe 'create' do
it 'throws a 501 error' do
post :create, params: {
course_id: :mock_course_id,
name: :mock_course_name,
}
expect(response.status).to eq(501)
def json_response
JSON.parse(response.body)
end

before do
# Manually create a course and LMS in the database
@course = Course.create!(course_name: "Mock CS169 Course")
@lms = Lms.create!(lms_name: "Mock Canvas", use_auth_token: true)
@external_course_id = "mock_external_course_id"
end

after do
# Clean up the specifically created data
CourseToLms.delete_all
Course.delete_all
Lms.delete_all
end

describe 'POST #create' do
context 'when valid parameters are provided' do
it 'creates a new course_to_lms association and returns status :created' do
post :create, params: { course_id: @course.id, lms_id: @lms.id, external_course_id: @external_course_id}
expect(response).to have_http_status(:created)
expect(json_response['course_id']).to eq(@course.id)
expect(json_response['lms_id']).to eq(@lms.id)
end
end

it 'throws a 401 error if the name is not specified' do
post :create, params: {
course_id: :mock_course_id,
}
expect(response.status).to eq(401)
expect(response.body).to eq('name parameter is required')

context 'when lms_id is missing' do
it 'returns status :bad_request' do
post :create, params: { course_id: @course.id, external_course_id: @external_course_id}
expect(response).to have_http_status(:bad_request)
expect(response.body).to include('course_id and lms_id are required')
end
end

context 'when course does not exist' do
it 'returns status :not_found' do
post :create, params: { course_id: -1, lms_id: @lms.id, external_course_id: @external_course_id}
expect(response).to have_http_status(:not_found)
expect(response.body).to include('Course not found')
end
end

context 'when lms does not exist' do
it 'returns status :not_found' do
post :create, params: { course_id: @course.id, lms_id: -1, external_course_id: @external_course_id}
expect(response).to have_http_status(:not_found)
expect(response.body).to include('Lms not found')
end
end

context 'when the association already exists' do
it 'returns status :ok' do
CourseToLms.create!(course_id: @course.id, lms_id: @lms.id, external_course_id: @external_course_id)
post :create, params: { course_id: @course.id, lms_id: @lms.id, external_course_id: @external_course_id}
expect(response).to have_http_status(:ok)
expect(response.body).to include('The association between the specified course and LMS already exists.')
end
end
end



describe 'index' do
it 'throws a 501 error' do
get :index, params: { course_id: :mock_course_id }
Expand Down
Loading