Implement a conflicts summary model
This commit is contained in:
parent
a39af296ba
commit
37a414328f
11
app/controllers/conflicts_summaries_controller.rb
Normal file
11
app/controllers/conflicts_summaries_controller.rb
Normal 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
|
18
app/models/conflicts_summary.rb
Normal file
18
app/models/conflicts_summary.rb
Normal 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
|
1
app/views/conflicts_summaries/show.json.jbuilder
Normal file
1
app/views/conflicts_summaries/show.json.jbuilder
Normal file
@ -0,0 +1 @@
|
||||
json.merge! @conflicts_summary.conflicts
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user