Skip to content

Commit

Permalink
quality: move stage into feedback folder and load
Browse files Browse the repository at this point in the history
Added feedback folder loading into application. No module needed
in the model. Using a module for the feedback api folder.

Co-authored-by: ugonj <[email protected]>
Co-authored-by: wakedreamer <[email protected]>
Co-authored-by: ublefo <[email protected]>
  • Loading branch information
4 people committed Dec 16, 2022
1 parent c74a676 commit 70a7ddb
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/api/api_root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ class ApiRoot < Grape::API
mount BreaksApi
mount DiscussionCommentApi
mount ExtensionCommentsApi
mount FeedbackApi::StageApi
mount GroupSetsApi
mount LearningOutcomesApi
mount LearningAlignmentApi
mount ProjectsApi
mount SettingsApi
mount StageApi
mount StudentsApi
mount Submission::PortfolioApi
mount Submission::PortfolioEvidenceApi
Expand Down Expand Up @@ -96,7 +96,7 @@ class ApiRoot < Grape::API
AuthenticationHelpers.add_auth_to LearningAlignmentApi
AuthenticationHelpers.add_auth_to ProjectsApi
AuthenticationHelpers.add_auth_to StudentsApi
AuthenticationHelpers.add_auth_to StageApi
AuthenticationHelpers.add_auth_to FeedbackApi::StageApi
AuthenticationHelpers.add_auth_to Submission::PortfolioApi
AuthenticationHelpers.add_auth_to Submission::PortfolioEvidenceApi
AuthenticationHelpers.add_auth_to Submission::BatchTaskApi
Expand Down
77 changes: 77 additions & 0 deletions app/api/feedback_api/stage_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
require 'grape'

module FeedbackApi
class StageApi < Grape::API

desc 'Feedback is provided in stages. This endpoint allows you to create a new stage for feedback on tasks for a given task definition.'
params do
requires :task_definition_id, type: Integer, desc: 'The task definition to which the stage belongs'
requires :title, type: String, desc: 'The title of the new stage'
requires :order, type: Integer, desc: 'The order to determine the order in which to display stages'
end
post '/stages' do
task_definition = TaskDefinition.find(params[:task_definition_id])

unless authorise? current_user, task_definition.unit, :update
error!({ error: 'Not authorised to create a stage for this unit' }, 403)
end

stage_parameters = ActionController::Parameters.new(params)
.permit(:title, :order)

stage_parameters[:task_definition] = task_definition

result = Stage.create!(stage_parameters)

present result, with: Entities::StageEntity
end

desc 'This endpoint allows you to get all the stages for a given task definition.'
params do
requires :task_definition_id, type: Integer, desc: 'The task definition to which the stage belongs'
end
get '/stages' do
task_definition = TaskDefinition.find(params[:task_definition_id])

unless authorise? current_user, task_definition.unit, :provide_feedback
error!({ error: 'Not authorised to get feedback stages for this unit' }, 403)
end

present task_definition.stages, with: Entities::StageEntity
end

desc 'This endpoint allows you to update the name and order of a stage.'
params do
optional :title, type: String, desc: 'The new title for the stage'
optional :order, type: Integer, desc: 'The order value for the stage'
end
put '/stages/:id' do
# Get the stage from the task definition
stage = Stage.find(params[:id])

unless authorise? current_user, stage.unit, :update
error!({ error: 'Not authorised to update feedback stages for this unit' }, 403)
end

stage_params = ActionController::Parameters.new(params)
.permit(:title, :order)

stage.update!(stage_params)

present stage, with: Entities::StageEntity
end

desc 'This endpoint allows you to delete a stage.'
delete '/stages/:id' do
# Get the stage from the task definition
stage = Stage.find(params[:id])

unless authorise? current_user, stage.unit, :update
error!({ error: 'Not authorised to delete feedback stages for this unit' }, 403)
end

stage.destroy!
end

end
end
32 changes: 0 additions & 32 deletions app/api/stage_api.rb

This file was deleted.

1 change: 1 addition & 0 deletions app/models/stage.rb → app/models/feedback/stage.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Stage < ApplicationRecord
belongs_to :task_definition
has_one :unit, through: :task_definition

validates :title, :order, presence: true

Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class Application < Rails::Application
# config.paths.add 'app/api', glob: '**/*.rb'
# config.autoload_paths += Dir["#{Rails.root}/app"]
# config.autoload_paths += Dir[Rails.root.join("app", "models", "{*/}")]
config.eager_load_paths << Rails.root.join('app') << Rails.root.join('app', 'models', 'comments')
config.eager_load_paths << Rails.root.join('app') << Rails.root.join('app', 'models', 'comments') << Rails.root.join('app', 'models', 'feedback')

# CORS config
config.middleware.insert_before Warden::Manager, Rack::Cors do
Expand Down

0 comments on commit 70a7ddb

Please sign in to comment.