Define an endpoint to return the default affinities of a group
All checks were successful
Build Nginx-based docker image / build-static-assets (pull_request) Successful in 16m44s
Add copyright notice / copyright_notice (pull_request) Successful in 1m45s
Check usage of free licenses / check-licenses (pull_request) Successful in 1m10s
Run unit tests / unit_tests (pull_request) Successful in 9m16s
All checks were successful
Build Nginx-based docker image / build-static-assets (pull_request) Successful in 16m44s
Add copyright notice / copyright_notice (pull_request) Successful in 1m45s
Check usage of free licenses / check-licenses (pull_request) Successful in 1m10s
Run unit tests / unit_tests (pull_request) Successful in 9m16s
This commit is contained in:
parent
37bbc1e4f1
commit
f997657cd3
@ -9,10 +9,10 @@ class AffinitiesController < ApplicationController
|
||||
overridden = @group.affinities.each_with_object({}) do |affinity, acc|
|
||||
acc[affinity.another_group(@group).id] = affinity.discomfort
|
||||
end
|
||||
Group.where.not(id: @group.id)
|
||||
.pluck(:id)
|
||||
.index_with { |group_id| GroupAffinity::MAX_DISCOMFORT - (overridden[group_id] || GroupAffinity::NEUTRAL) }
|
||||
.then { |affinities| render json: affinities }
|
||||
|
||||
for_each_group do |group_id|
|
||||
overridden[group_id] || GroupAffinity::NEUTRAL
|
||||
end
|
||||
end
|
||||
|
||||
def bulk_update
|
||||
@ -33,8 +33,21 @@ class AffinitiesController < ApplicationController
|
||||
render json: { error: 'Invalid group ID or discomfort provided.' }, status: :bad_request
|
||||
end
|
||||
|
||||
def default
|
||||
for_each_group do |group_id|
|
||||
Tables::DiscomfortCalculator.cohesion_discomfort(id_a: @group.id, id_b: group_id).to_f
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def for_each_group
|
||||
Group.where.not(id: @group.id)
|
||||
.pluck(:id)
|
||||
.index_with { |group_id| GroupAffinity::MAX_DISCOMFORT - yield(group_id) }
|
||||
.then { |affinities| render json: affinities }
|
||||
end
|
||||
|
||||
def set_group
|
||||
@group = Group.find(params[:group_id])
|
||||
end
|
||||
|
@ -26,6 +26,7 @@ Rails.application.routes.draw do
|
||||
resources :groups, only: %i[index create update destroy] do
|
||||
resources :affinities, only: %i[index] do
|
||||
put :bulk_update, on: :collection
|
||||
get :default, on: :collection
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -20,6 +20,21 @@ RSpec.describe 'affinities' do
|
||||
end
|
||||
end
|
||||
|
||||
path '/{slug}/groups/{group_id}/affinities/default' do
|
||||
parameter Swagger::Schema::SLUG
|
||||
parameter name: 'group_id', in: :path, type: :string, format: :uuid, description: 'group_id'
|
||||
|
||||
get('calculate default affinity') do
|
||||
tags 'Affinities'
|
||||
produces 'application/json'
|
||||
|
||||
response(200, 'successful') do
|
||||
schema type: :object, additionalProperties: { type: :integer, minimum: 0, maximum: 2 }
|
||||
xit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
path '/{slug}/groups/{group_id}/affinities/bulk_update' do
|
||||
parameter Swagger::Schema::SLUG
|
||||
parameter name: 'group_id', in: :path, type: :string, format: :uuid, description: 'group_id'
|
||||
|
Loading…
x
Reference in New Issue
Block a user