Implement a conflicts summary model

This commit is contained in:
Petko Bordjukov 2016-10-12 21:51:36 +03:00
parent a39af296ba
commit 37a414328f
4 changed files with 31 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -0,0 +1 @@
json.merge! @conflicts_summary.conflicts

View File

@ -3,5 +3,6 @@ Rails.application.routes.draw do
root to: 'home#index' root to: 'home#index'
resource :summary, only: :show resource :summary, only: :show
resource :conflicts, 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 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end end