Skip to content

Commit b0026ab

Browse files
committed
fix: correct routes for swagger support
1 parent 50e1310 commit b0026ab

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

app/api/feedback/feedback_chip_api.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ class FeedbackChipApi < Grape::API
1111
authenticated?
1212
end
1313

14-
route :context_type_plural, values: %w[units task_definitions] do
15-
params[:context_type].pluralize
16-
end
17-
1814
desc "Get all feedback chips for a context"
15+
params do
16+
requires :context_type_plural, type: String, desc: 'The context - a unit or task_definition', values: %w[units task_definitions]
17+
requires :context_id, type: Integer, desc: 'The ID of the context'
18+
end
1919
get '/:context_type_plural/:context_id/feedback_chips' do
2020
context_type = params[:context_type_plural].singularize.camelize
2121
context_model = context_type.classify.constantize.find(params[:context_id])
@@ -153,6 +153,7 @@ class FeedbackChipApi < Grape::API
153153
desc 'Download the feedback chips for a specific outcome' # change to specific context rather than outcome
154154
params do
155155
requires :id, type: Integer, desc: 'The ID of the context'
156+
requires :context_type_plural, type: String, desc: 'The context - a unit or task_definition', values: %w[units task_definitions]
156157
end
157158
get '/:context_type_plural/:context_id/outcomes/:id/feedback_chips/csv' do
158159
# find context model dynamically
@@ -177,6 +178,7 @@ class FeedbackChipApi < Grape::API
177178
params do
178179
requires :context_id, type: Integer, desc: 'The ID of the context'
179180
optional :includes_tlos, type: Boolean, desc: 'Include TLOs in the export'
181+
requires :context_type_plural, type: String, desc: 'The context - a unit or task_definition', values: %w[units task_definitions]
180182
end
181183
get '/:context_type_plural/:context_id/feedback_chips/csv' do
182184
include_tlos = params[:includes_tlos] || false
@@ -201,13 +203,18 @@ class FeedbackChipApi < Grape::API
201203
params do
202204
requires :file, type: File, desc: 'CSV upload file.'
203205
requires :id, type: Integer, desc: 'The id of the learning outcome'
206+
requires :context_type_plural, type: String, desc: 'The context - a unit or task_definition', values: %w[units task_definitions]
207+
requires :context_id, type: Integer, desc: 'The ID of the context'
204208
end
205209
post '/:context_type_plural/:context_id/outcomes/:id/feedback_chips/csv' do
206210
# check mime is correct before uploading
207211
ensure_csv!(params[:file][:tempfile])
208212

213+
context_type = params[:context_type_plural].singularize.camelize
214+
context_model = context_type.classify.constantize.find(params[:context_id])
215+
209216
# find context model dynamically
210-
learning_outcome = LearningOutcome.find(params[:id])
217+
learning_outcome = context_model.learning_outcomes.find(params[:id])
211218

212219
unless authorise? current_user, learning_outcome, :upload_csv
213220
error!({ error: 'Not authorised to upload CSV of outcomes' }, 403)
@@ -220,6 +227,7 @@ class FeedbackChipApi < Grape::API
220227
desc 'Upload the feedback chips for a specified context from a csv'
221228
params do
222229
requires :file, type: File, desc: 'CSV upload file.'
230+
requires :context_type_plural, type: String, desc: 'The context - a unit or task_definition', values: %w[units task_definitions]
223231
requires :context_id, type: Integer, desc: 'The ID of the context'
224232
end
225233
post '/:context_type_plural/:context_id/feedback_chips/csv' do

app/api/learning_outcomes_api.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ class LearningOutcomesApi < Grape::API
1010
authenticated?
1111
end
1212

13-
route :context_type_plural, values: %w[units task_definitions] do
14-
params[:context_type].pluralize
15-
end
16-
1713
desc 'Get all global outcomes'
1814
get '/global/outcomes' do
1915
# can be read by any logged in user
@@ -26,6 +22,7 @@ class LearningOutcomesApi < Grape::API
2622
requires :short_description, type: String, desc: 'The ILO''s short_description'
2723
optional :full_outcome_description, type: String, desc: 'The ILO''s full_outcome_description'
2824
optional :linked_outcome_ids, type: Array[Integer], desc: 'The ids of the linked outcome ids'
25+
requires :context_type_plural, type: String, desc: 'The context - a unit or task_definition', values: %w[units task_definitions]
2926
end
3027
post '/:context_type_plural/:context_id/outcomes' do
3128
# find context model dynamically
@@ -36,7 +33,7 @@ class LearningOutcomesApi < Grape::API
3633
error!({ error: 'You are not authorised to create outcomes in this context.' }, 403)
3734
end
3835

39-
outcome_params = declared(params, include_missing: false).except(:linked_outcome_ids)
36+
outcome_params = declared(params, include_missing: false).except(:linked_outcome_ids, :context_type_plural)
4037
outcome_params[:context_type] = context_type
4138

4239
learning_outcome = context_model.learning_outcomes.create!(outcome_params)
@@ -76,6 +73,7 @@ class LearningOutcomesApi < Grape::API
7673
optional :full_outcome_description, type: String, desc: 'The ILO''s full_outcome_description'
7774
optional :linked_outcome_ids, type: Array[Integer], desc: 'The ids of the linked outcome ids'
7875
# optional :ilo_number, type: Integer, desc: 'The ILO''s new sequence number'
76+
requires :context_type_plural, type: String, desc: 'The context - a unit or task_definition', values: %w[units task_definitions]
7977
end
8078
put '/:context_type_plural/:context_id/outcomes/:id' do
8179
# find context model dynamically
@@ -128,6 +126,7 @@ class LearningOutcomesApi < Grape::API
128126
params do
129127
requires :context_id, type: Integer, desc: 'The id of the context'
130128
requires :id, type: Integer, desc: 'The id for the outcome you wish to delete'
129+
requires :context_type_plural, type: String, desc: 'The context - a unit or task_definition', values: %w[units task_definitions]
131130
end
132131
delete '/:context_type_plural/:context_id/outcomes/:id' do
133132
# find context model dynamically
@@ -165,6 +164,7 @@ class LearningOutcomesApi < Grape::API
165164
params do
166165
requires :context_id, type: Integer, desc: 'The id of the context'
167166
optional :includes_tlos, type: Boolean, desc: 'Include nested task learning outcomes in the export'
167+
requires :context_type_plural, type: String, desc: 'The context - a unit or task_definition', values: %w[units task_definitions]
168168
end
169169
get '/:context_type_plural/:context_id/outcomes/csv' do
170170
# find context model dynamically
@@ -190,6 +190,7 @@ class LearningOutcomesApi < Grape::API
190190
params do
191191
requires :file, type: File, desc: 'CSV upload file.'
192192
requires :context_id, type: Integer, desc: 'The id of the context'
193+
requires :context_type_plural, type: String, desc: 'The context - a unit or task_definition', values: %w[units task_definitions]
193194
end
194195
post '/:context_type_plural/:context_id/outcomes/csv' do
195196
# check mime is correct before uploading

app/api/tii/tii_action_api.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class TiiActionApi < Grape::API
1212

1313
desc 'Get the outstanding turn it in actions'
1414
params do
15-
optional :unit_id, type: Integer, desc: 'The id of the unit to filter by', default: nil
15+
optional :unit_id, type: Integer, desc: 'The id of the unit to filter by'
1616
optional :limit, type: Integer, desc: 'The maximum number of actions to return', default: 50
1717
optional :offset, type: Integer, desc: 'The offset to start from', default: 0
1818
optional :show_complete, type: Boolean, desc: 'Include complete actions?', default: false
@@ -38,10 +38,10 @@ class TiiActionApi < Grape::API
3838
desc 'Trigger an action on the given group attachment'
3939
params do
4040
requires :action, type: String, desc: 'The action to perform: retry'
41-
optional :unit_id, type: Integer, desc: 'The id of the unit to filter by', default: nil
41+
# optional :unit_id, type: Integer, desc: 'The id of the unit to filter by'
4242
end
4343
put '/tii_actions/:id' do
44-
unit = Unit.find(params[:unit_id]) if params[:unit_id].present?
44+
# unit = Unit.find(params[:unit_id]) if params[:unit_id].present?
4545

4646
unless authorise?(current_user, User, :admin_units)
4747
error!({ error: 'Not authorised to retry tasks' }, 403)

0 commit comments

Comments
 (0)