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

feature/Courseflow-api #448

Open
wants to merge 43 commits into
base: new/course-flow
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8e70b3c
chore: update gems
macite Jun 11, 2024
363e02e
chore: ensure lf file endings
macite Jun 14, 2024
b12f55e
fix: add courseapi
DudeUnleashed May 21, 2024
7229689
feat: add course_map api
DudeUnleashed May 21, 2024
ae90301
feat: add course_map_unit api
DudeUnleashed May 21, 2024
eec7957
feat: add specialization api
DudeUnleashed May 21, 2024
b0df705
feat: add requirement_set api
DudeUnleashed May 21, 2024
921fc61
fix: Update schema.rb
DudeUnleashed Jul 29, 2024
90cc8f3
fix: Update schema.rb
DudeUnleashed Jul 29, 2024
07a4cc0
Update schema.rb
DudeUnleashed Jul 29, 2024
7cded48
Update schema.rb
DudeUnleashed Jul 29, 2024
0983d2d
fix: Update schema.rb
DudeUnleashed Jul 29, 2024
c1d2d90
fix: add authentication to requirement_set API and updated with appro…
DudeUnleashed Aug 4, 2024
7a51b74
fix: add authentication to course API and updated with appropriate ne…
DudeUnleashed Aug 4, 2024
eb7dada
fix: add authentication to course_map API and course_map_unit and upd…
DudeUnleashed Aug 4, 2024
9572335
fix: specialization update was incorrect
DudeUnleashed Aug 5, 2024
d730f5a
chore: update gems
macite Jun 11, 2024
fd8848e
feat: add specialization api
DudeUnleashed May 21, 2024
c39c6bd
fix: add authentication to specialization API and updated with approp…
DudeUnleashed Aug 4, 2024
40e4312
fix: specialization incorrectly updating
DudeUnleashed Aug 5, 2024
8a43fdb
fix: merging broken branches
DudeUnleashed Aug 11, 2024
cdb3355
fix: fixing schema.rb errors
DudeUnleashed Aug 11, 2024
f78969b
Merge remote-tracking branch 'origin' into feature/courseapi
DudeUnleashed Aug 11, 2024
19cd718
fix: update schema.rb based on db:migrate changes
DudeUnleashed Aug 11, 2024
b8196fb
fix: update schema.rb based on db:migrate changes
DudeUnleashed Aug 11, 2024
80aca85
fix: update schema.rb based on db:migrate changes
DudeUnleashed Aug 11, 2024
2afc2c3
fix: update schema.rb based on db:migrate changes
DudeUnleashed Aug 11, 2024
96b058d
fix: update schema.rb based on db:migrate changes
DudeUnleashed Aug 11, 2024
7e15d81
fix: fix schema.rb error
DudeUnleashed Aug 11, 2024
c113a64
feat:add unit definitions api
DudeUnleashed Sep 2, 2024
606be31
fix: clean up incorrect migration file
DudeUnleashed Sep 10, 2024
1bc6145
feature: start migration to link unit table to unitdefinitions
DudeUnleashed Sep 10, 2024
90e8b99
feature: add unit definition id to unit table
DudeUnleashed Sep 10, 2024
fd59cb3
fix: removed the print out from tests
DudeUnleashed Sep 16, 2024
9152325
feature: start adding file for courseflow dummy data
DudeUnleashed Sep 17, 2024
e2085da
feature: add rake command to populate courseflow data for testing
DudeUnleashed Sep 17, 2024
50e34b4
Merge branch 'feature/coursemapapi' into courseflow
DudeUnleashed Sep 24, 2024
a693990
Merge branch 'feature/specializationapi' into courseflow
DudeUnleashed Sep 24, 2024
7c84885
Merge branch 'feature/requirementsetapi' into courseflow
DudeUnleashed Sep 24, 2024
0a26e86
Merge branch 'feature/unitdefinition-unitmigration' into courseflow
DudeUnleashed Sep 24, 2024
962ab1b
Merge branch 'feature/coursedummydata' into courseflow
DudeUnleashed Sep 24, 2024
a162cb8
fix: removed test output from feature branch for final merging
DudeUnleashed Oct 14, 2024
99dc3c8
Merge branch 'new/course-flow' into courseflow
DudeUnleashed Oct 15, 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
10 changes: 6 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ source 'https://rubygems.org'

# Ruby versions for various enviornments
ruby_versions = {
development: '~>3.1.0',
test: '~>3.1.0',
staging: '~>3.1.0',
production: '~>3.1.0'
development: '~>3.3.0',
test: '~>3.3.0',
staging: '~>3.3.0',
production: '~>3.3.0'
}
# Get the ruby version for the current enviornment
ruby ruby_versions[(ENV['RAILS_ENV'] || 'development').to_sym]
Expand Down Expand Up @@ -112,3 +112,5 @@ gem 'shellwords'

# PDF reader for validating PDF file submissions
gem 'pdf-reader'

gem 'csv'
38 changes: 35 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ GEM
bigdecimal
rexml
crass (1.0.6)
csv (3.3.0)
database_cleaner-active_record (2.1.0)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
Expand Down Expand Up @@ -168,7 +169,15 @@ GEM
faraday-net_http (3.1.0)
net-http
ffi (1.17.0-aarch64-linux-gnu)
ffi (1.17.0-aarch64-linux-musl)
ffi (1.17.0-arm-linux-gnu)
ffi (1.17.0-arm-linux-musl)
ffi (1.17.0-arm64-darwin)
ffi (1.17.0-x86-linux-gnu)
ffi (1.17.0-x86-linux-musl)
ffi (1.17.0-x86_64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
ffi (1.17.0-x86_64-linux-musl)
fugit (1.11.0)
et-orbi (~> 1, >= 1.2.11)
raabro (~> 1.4)
Expand Down Expand Up @@ -267,6 +276,16 @@ GEM
racc (~> 1.4)
nokogiri (1.16.6-x86_64-linux)
racc (~> 1.4)
nokogiri (1.16.5-arm-linux)
racc (~> 1.4)
nokogiri (1.16.5-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.5-x86-linux)
racc (~> 1.4)
nokogiri (1.16.5-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.5-x86_64-linux)
racc (~> 1.4)
observer (0.1.2)
orm_adapter (0.5.0)
parallel (1.25.1)
Expand Down Expand Up @@ -497,8 +516,20 @@ GEM
zeitwerk (2.6.16)

PLATFORMS
aarch64-linux
aarch64-linux-gnu
aarch64-linux-musl
arm-linux
arm-linux-gnu
arm-linux-musl
arm64-darwin
x86-linux
x86-linux-gnu
x86-linux-musl
x86_64-darwin
x86_64-linux
x86_64-linux-gnu
x86_64-linux-musl
aarch64-linux

DEPENDENCIES
better_errors
Expand All @@ -507,6 +538,7 @@ DEPENDENCIES
byebug
ci_reporter
coderay
csv
database_cleaner-active_record
devise
devise_ldap_authenticatable
Expand Down Expand Up @@ -560,7 +592,7 @@ DEPENDENCIES
webmock

RUBY VERSION
ruby 3.1.4p223
ruby 3.3.2p78

BUNDLED WITH
2.4.22
2.5.11
14 changes: 14 additions & 0 deletions app/api/api_root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ class ApiRoot < Grape::API
mount WebcalApi
mount WebcalPublicApi

mount Courseflow::CourseApi
mount Courseflow::CourseMapApi
mount Courseflow::CourseMapUnitApi
mount Courseflow::SpecializationApi
mount Courseflow::RequirementSetApi
mount UnitDefinitionApi

#
# Add auth details to all end points
#
Expand Down Expand Up @@ -128,6 +135,13 @@ class ApiRoot < Grape::API
AuthenticationHelpers.add_auth_to UnitsApi
AuthenticationHelpers.add_auth_to WebcalApi

AuthenticationHelpers.add_auth_to Courseflow::CourseApi
AuthenticationHelpers.add_auth_to Courseflow::CourseMapApi
AuthenticationHelpers.add_auth_to Courseflow::CourseMapUnitApi
AuthenticationHelpers.add_auth_to Courseflow::SpecializationApi
AuthenticationHelpers.add_auth_to Courseflow::RequirementSetApi
AuthenticationHelpers.add_auth_to UnitDefinitionApi

add_swagger_documentation \
base_path: nil,
api_version: 'v1',
Expand Down
100 changes: 100 additions & 0 deletions app/api/courseflow/course_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
require 'grape'
module Courseflow
class CourseApi < Grape::API

format :json
helpers AuthenticationHelpers
helpers AuthorisationHelpers

before do
authenticated?
end

desc "Get all course data"
get '/course' do
courses = Course.all # get all courses in the database
present courses, with: Entities::CourseEntity # present the courses using the CourseEntity
end

desc "Get course by ID"
params do
requires :courseId, type: Integer, desc: "Course ID"
end
get '/course/courseId/:courseId' do
course = Course.find(params[:courseId]) # find the course by ID
present course, with: Entities::CourseEntity # present the course using the CourseEntity
end

desc "Get courses that partially match the search params"
params do # define the parameters that can be used to filter the courses, all optional, if none given it'll return every course
optional :name, type: String, desc: "Course name"
optional :code, type: String, desc: "Course code"
optional :year, type: Integer, desc: "Course year"
end
get '/course/search' do
courses = Course.all # gets all courses initially

courses = courses.where("name LIKE :name", name: "%#{params[:name]}%") if params[:name].present? # if name is provided, filter by name, even partially
courses = courses.where("code LIKE :code", code: "%#{params[:code]}%") if params[:code].present? # if code is provided, filter by code, (can do things like SIT to get all SIT courses)
courses = courses.where(year: params[:year]) if params[:year].present? # if year is provided, filter by year

present courses, with: Entities::CourseEntity # return the filtered courses
end

desc "Add a new course"
params do # define the parameters required to create a new course
requires :name, type: String
requires :code, type: String
requires :year, type: Integer
requires :version, type: String
requires :url, type: String
end
post '/course' do
unless authorise? current_user, User, :handle_courseflow
error!({ error: 'Not authorised to create a course' }, 403)
end
course = Course.new(params) # create a new course with the provided params
if course.save
present course, with: Entities::CourseEntity # if the course is saved, present the course using the CourseEntity
else
error!({ error: "Failed to create course", details: course.errors.full_messages }, 400) # if the course is not saved, return an error with the full error messages
end
end

desc "Update an existing course via its ID"
params do # define the parameters required to update a course
requires :courseId, type: Integer, desc: "Course ID"
requires :name, type: String
requires :code, type: String
requires :year, type: Integer
requires :version, type: String
requires :url, type: String
end
put '/course/courseId/:courseId' do
unless authorise? current_user, User, :handle_courseflow
error!({ error: 'Not authorised to update a course' }, 403)
end
course = Course.find(params[:courseId]) # find the course by ID
error!({ error: "Course not found" }, 404) unless course # return an error if the course is not found

if course.update(name: params[:name], code: params[:code], year: params[:year], version: params[:version], url: params[:url]) # update the course with the provided params
present course, with: Entities::CourseEntity # if the course is updated, present the course using the CourseEntity
else
error!({ error: "Failed to update course", details: course.errors.full_messages }, 400) # if the course is not updated, return an error with the full error messages
end
end

desc "Deletes an existing course via its ID"
params do
requires :courseId, type: Integer, desc: "Course ID"
end
delete '/course/courseId/:courseId' do
unless authorise? current_user, User, :handle_courseflow
error!({ error: 'Not authorised to delete a course' }, 403)
end
course = Course.find(params[:courseId]) # find the course by ID
course.destroy
{ message: "Course with ID #{params[:courseId]} has been deleted" } # return a message saying the course was deleted
end
end
end
106 changes: 106 additions & 0 deletions app/api/courseflow/course_map_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
require 'grape'
module Courseflow
class CourseMapApi < Grape::API

format :json
helpers AuthenticationHelpers
helpers AuthorisationHelpers

before do
authenticated?
end

desc "Get course map via user ID"
params do
requires :userId, type: Integer, desc: "User ID"
end
get '/coursemap/userId/:userId' do
course_map = CourseMap.find_by(userId: params[:userId])
if course_map
present course_map, with: Entities::CourseMapEntity
else
error!({ error: "Course map #{params[:userId]} not found" }, 404)
end
end

desc "Get course map via course ID"
params do
requires :courseId, type: Integer, desc: "Course ID"
end
get '/coursemap/courseId/:courseId' do
course_map = CourseMap.where(courseId: params[:courseId])
if course_map
present course_map, with: Entities::CourseMapEntity
else
error!({ error: "Course map #{params[:courseId]} not found" }, 404)
end
end

desc "Add a new course map"
params do
requires :userId, type: Integer
requires :courseId, type: Integer
end
post '/coursemap' do
unless authorise? current_user, User, :handle_courseflow
error!({ error: 'Not authorised to add a new course map' }, 403)
end
course_map = CourseMap.new(params)
if course_map.save
present course_map, with: Entities::CourseMapEntity
else
error!({ error: "Failed to create course map", details: coursemap.errors.full_messages }, 400)
end
end

desc "Update an existing course map via its ID"
params do
requires :courseMapId, type: Integer, desc: "Course map ID"
requires :userId, type: Integer
requires :courseId, type: Integer
end
put '/coursemap/courseMapId/:courseMapId' do
unless authorise? current_user, User, :handle_courseflow
error!({ error: 'Not authorised to update course maps' }, 403)
end
course_map = CourseMap.find(params[:courseMapId])
if course_map.update(params.except(:courseMapId))
present course_map, with: Entities::CourseMapEntity
else
error!({ error: "Failed to update course map", details: course_map.errors.full_messages }, 400)
end
end

desc "Delete all course maps via its associated course map ID"
params do
requires :courseMapId, type: Integer, desc: "Course map ID"
end
delete '/coursemap/courseMapId/:courseMapId' do
unless authorise? current_user, User, :handle_courseflow
error!({ error: 'Not authorised to delete course maps' }, 403)
end
course_map = CourseMap.find(params[:courseMapId])
if course_map
course_map.destroy
else
error!({ error: "Course map #{params[:courseMapId]} not found" }, 404)
end
end

desc "Delete all course maps via its associated user ID"
params do
requires :userId, type: Integer, desc: "User ID"
end
delete '/coursemap/userId/:userId' do
unless authorise? current_user, User, :handle_courseflow
error!({ error: 'Not authorised to delete course maps' }, 403)
end
course_map = CourseMap.find(params[:userId])
if course_map
course_map.destroy
else
error!({ error: "Course map #{params[:userId]} not found" }, 404)
end
end
end
end
Loading