Class: Inferno::Web::Controllers::TestSessions::Results::IoValue
- Inherits:
-
Controller
- Object
- Hanami::Action
- Controller
- Inferno::Web::Controllers::TestSessions::Results::IoValue
- Defined in:
- lib/inferno/apps/web/controllers/test_sessions/results/io_value.rb
Instance Method Summary collapse
Methods inherited from Controller
call, resource_class, resource_name
Instance Method Details
#handle(req, res) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/inferno/apps/web/controllers/test_sessions/results/io_value.rb', line 12 def handle(req, res) test_session_id = req.params[:id] result_id = req.params[:result_id] type = req.params[:type] name = req.params[:name] unless %w[inputs outputs].include?(type) res.status = 400 res.body = { error: 'Invalid I/O type. Must be "inputs" or "outputs".' }.to_json return end test_session_results = results_repo.current_results_for_test_session(test_session_id) result = test_session_results.find { |r| r.id == result_id } if result.nil? res.status = 404 res.body = { error: "Result '#{result_id}' not found for test session '#{test_session_id}'." }.to_json return end entry = result_io_by_name(result, type, name) value = entry&.dig('value') if value.blank? res.status = 404 res.body = { error: "#{type.singularize.capitalize} '#{name}' not found or missing value." }.to_json return end res.body = value.is_a?(Hash) ? value.to_json : value res.content_type = content_type_for(value) end |