Compare commits
No commits in common. "0ade367fb5f93897c544266cd7c8f9fc10be7645" and "65a265b900aeb1ec96c36d99200951d8d5408823" have entirely different histories.
0ade367fb5
...
65a265b900
@ -3,7 +3,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class AffinitiesController < ApplicationController
|
class AffinitiesController < ApplicationController
|
||||||
before_action :set_group, except: :reset
|
before_action :set_group
|
||||||
|
|
||||||
def index
|
def index
|
||||||
overridden = @group.affinities.each_with_object({}) do |affinity, acc|
|
overridden = @group.affinities.each_with_object({}) do |affinity, acc|
|
||||||
@ -39,20 +39,6 @@ class AffinitiesController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset
|
|
||||||
affinities = Group.pluck(:id).combination(2).map do |(group_a_id, group_b_id)|
|
|
||||||
{
|
|
||||||
group_a_id:,
|
|
||||||
group_b_id:,
|
|
||||||
discomfort: Tables::DiscomfortCalculator.cohesion_discomfort(id_a: group_a_id, id_b: group_b_id).to_f
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
GroupAffinity.upsert_all(affinities)
|
|
||||||
|
|
||||||
render json: {}, status: :ok
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def for_each_group
|
def for_each_group
|
||||||
|
@ -24,7 +24,6 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
|
|
||||||
resources :groups, only: %i[index create update destroy] do
|
resources :groups, only: %i[index create update destroy] do
|
||||||
post 'affinities/reset', to: 'affinities#reset', on: :collection
|
|
||||||
resources :affinities, only: %i[index] do
|
resources :affinities, only: %i[index] do
|
||||||
put :bulk_update, on: :collection
|
put :bulk_update, on: :collection
|
||||||
get :default, on: :collection
|
get :default, on: :collection
|
||||||
|
@ -5,17 +5,6 @@
|
|||||||
require 'swagger_helper'
|
require 'swagger_helper'
|
||||||
|
|
||||||
RSpec.describe 'affinities' do
|
RSpec.describe 'affinities' do
|
||||||
path '/{slug}/groups/affinities/reset' do
|
|
||||||
parameter Swagger::Schema::SLUG
|
|
||||||
|
|
||||||
post('reset affinities') do
|
|
||||||
tags 'Affinities'
|
|
||||||
description 'Reset all affinities to default values based on the distance between groups in the hierarchy.'
|
|
||||||
|
|
||||||
response_empty200
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
path '/{slug}/groups/{group_id}/affinities' do
|
path '/{slug}/groups/{group_id}/affinities' do
|
||||||
parameter Swagger::Schema::SLUG
|
parameter Swagger::Schema::SLUG
|
||||||
parameter name: 'group_id', in: :path, type: :string, format: :uuid, description: 'group_id'
|
parameter name: 'group_id', in: :path, type: :string, format: :uuid, description: 'group_id'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user