diff --git a/app/controllers/conflicts_summaries_controller.rb b/app/controllers/conflicts_summaries_controller.rb new file mode 100644 index 0000000..bac807d --- /dev/null +++ b/app/controllers/conflicts_summaries_controller.rb @@ -0,0 +1,11 @@ +class ConflictsSummariesController < ApplicationController + def show + @conflicts_summary = ConflictsSummary.new conflicts_summary_params + end + + private + + def conflicts_summary_params + params.require(:conflicts_summary).permit(talk_ids: []) + end +end diff --git a/app/models/conflicts_summary.rb b/app/models/conflicts_summary.rb new file mode 100644 index 0000000..7eb6b5d --- /dev/null +++ b/app/models/conflicts_summary.rb @@ -0,0 +1,18 @@ +class ConflictsSummary + include ActiveModel::Model + + attr_accessor :talk_ids + + def talk_ids + @talk_ids ||= [] + end + + def conflicts + talk_ids.map do |talk_id| + { + talk_id: talk_id, + conflicts: ConflictsTable.new(talk_id: talk_id, other_talks_ids: talk_ids.reject { |id| id == talk_id }).conflicts + } + end + end +end diff --git a/app/views/conflicts_summaries/show.json.jbuilder b/app/views/conflicts_summaries/show.json.jbuilder new file mode 100644 index 0000000..9e8d3fd --- /dev/null +++ b/app/views/conflicts_summaries/show.json.jbuilder @@ -0,0 +1 @@ +json.merge! @conflicts_summary.conflicts diff --git a/config/routes.rb b/config/routes.rb index 7ae80e6..dc83a4c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,5 +3,6 @@ Rails.application.routes.draw do root to: 'home#index' resource :summary, only: :show resource :conflicts, only: :show + resource :conflicts_summary, only: :show # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end