rubocop-autocorrect #202

Merged
bustikiller merged 19 commits from rubocop-autocorrect into main 2024-12-28 18:26:28 +00:00
11 changed files with 115 additions and 72 deletions
Showing only changes of commit 0c7c69ee5e - Show all commits

View File

@ -6,22 +6,27 @@ class AffinitiesController < ApplicationController
before_action :set_group before_action :set_group
def index def index
overridden_affinities = @group.affinities overridden = @group.affinities.each_with_object({}) do |affinity, acc|
.each_with_object({}) { |affinity, acc| acc[affinity.another_group(@group).id] = affinity.discomfort } acc[affinity.another_group(@group).id] = affinity.discomfort
Group.where.not(id: @group.id).pluck(:id).index_with { |group_id| GroupAffinity::MAX_DISCOMFORT - (overridden_affinities[group_id] || GroupAffinity::NEUTRAL) } 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 } .then { |affinities| render json: affinities }
end end
def bulk_update def bulk_update
params.expect(affinities: [[:group_id, :affinity]]).map(&:to_h).map do |affinity| affinities = params.expect(affinities: [%i[group_id affinity]]).map(&:to_h).map do |affinity|
{ {
group_a_id: @group.id, group_a_id: @group.id,
group_b_id: affinity[:group_id], group_b_id: affinity[:group_id],
discomfort: GroupAffinity::MAX_DISCOMFORT - affinity[:affinity] discomfort: GroupAffinity::MAX_DISCOMFORT - affinity[:affinity]
} }
end.then { |affinities| GroupAffinity.upsert_all(affinities) } end
render json: {}, status: :ok
GroupAffinity.upsert_all(affinities)
render json: {}, status: :ok
rescue ActiveRecord::InvalidForeignKey rescue ActiveRecord::InvalidForeignKey
render json: { error: 'At least one of the group IDs provided does not exist.' }, status: :bad_request render json: { error: 'At least one of the group IDs provided does not exist.' }, status: :bad_request
rescue ActiveRecord::StatementInvalid rescue ActiveRecord::StatementInvalid

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
@ -40,7 +42,7 @@ class ApplicationController < ActionController::Base
end end
def captcha_params def captcha_params
params.expect(captcha: [:id, :answer]) params.expect(captcha: %i[id answer])
end end
def default_url_options(options = {}) def default_url_options(options = {})
@ -53,7 +55,7 @@ class ApplicationController < ActionController::Base
def development_swagger? def development_swagger?
Rails.env.test? || Rails.env.test? ||
Rails.env.development? && request.headers['referer']&.include?('/api-docs/index.html') (Rails.env.development? && request.headers['referer']&.include?('/api-docs/index.html'))
end end
def set_csrf_cookie def set_csrf_cookie

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
class ExpensesController < ApplicationController class ExpensesController < ApplicationController
@ -6,7 +8,7 @@ class ExpensesController < ApplicationController
end end
def index def index
render json: Expense.all.order(pricing_type: :asc, amount: :desc).as_json(only: %i[id name amount pricing_type]) render json: Expense.order(pricing_type: :asc, amount: :desc).as_json(only: %i[id name amount pricing_type])
end end
def create def create

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
class GroupsController < ApplicationController class GroupsController < ApplicationController
@ -39,6 +41,6 @@ class GroupsController < ApplicationController
end end
def group_params def group_params
params.expect(group: [:name, :icon, :color]) params.expect(group: %i[name icon color])
end end
end end

View File

@ -1,10 +1,12 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'csv' require 'csv'
class GuestsController < ApplicationController class GuestsController < ApplicationController
def index def index
render json: Guest.all.includes(:group) render json: Guest.includes(:group)
.left_joins(:group) .left_joins(:group)
.order('groups.name' => :asc, name: :asc) .order('groups.name' => :asc, name: :asc)
.as_json(only: %i[id name status], include: { group: { only: %i[id name] } }) .as_json(only: %i[id name status], include: { group: { only: %i[id name] } })

View File

@ -1,11 +1,33 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
class SummaryController < ApplicationController class SummaryController < ApplicationController
def index def index
expense_summary = Expenses::TotalQuery.new(wedding: ActsAsTenant.current_tenant).call
guest_summary = Guest.group(:status).count
render json: { render json: {
expenses: { expenses:,
guests:
}
end
private
def guests
guest_summary = Guest.group(:status).count
{
total: guest_summary.except('considered').values.sum,
confirmed: guest_summary['confirmed'].to_i,
declined: guest_summary['declined'].to_i,
tentative: guest_summary['tentative'].to_i,
invited: guest_summary['invited'].to_i
}
end
def expenses
expense_summary = Expenses::TotalQuery.new(wedding: ActsAsTenant.current_tenant).call
{
projected: { projected: {
total: expense_summary['total_projected'], total: expense_summary['total_projected'],
guests: expense_summary['projected_guests'] guests: expense_summary['projected_guests']
@ -17,14 +39,6 @@ class SummaryController < ApplicationController
status: { status: {
paid: 0 paid: 0
} }
},
guests: {
total: guest_summary.except('considered').values.sum,
confirmed: guest_summary['confirmed'].to_i,
declined: guest_summary['declined'].to_i,
tentative: guest_summary['tentative'].to_i,
invited: guest_summary['invited'].to_i
}
} }
end end
end end

View File

@ -1,8 +1,10 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
class TablesArrangementsController < ApplicationController class TablesArrangementsController < ApplicationController
def index def index
render json: TablesArrangement.all.order(discomfort: :asc).limit(3).as_json(only: %i[id name discomfort]) render json: TablesArrangement.order(discomfort: :asc).limit(3).as_json(only: %i[id name discomfort])
end end
def show def show

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
class TokensController < ApplicationController class TokensController < ApplicationController

View File

@ -1,6 +1,9 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
class Users::ConfirmationsController < Devise::ConfirmationsController module Users
class ConfirmationsController < Devise::ConfirmationsController
clear_respond_to clear_respond_to
respond_to :json respond_to :json
@ -21,3 +24,4 @@ class Users::ConfirmationsController < Devise::ConfirmationsController
end end
end end
end end
end

View File

@ -1,6 +1,9 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
class Users::RegistrationsController < Devise::RegistrationsController module Users
class RegistrationsController < Devise::RegistrationsController
clear_respond_to clear_respond_to
respond_to :json respond_to :json
@ -26,3 +29,4 @@ class Users::RegistrationsController < Devise::RegistrationsController
set_current_tenant(nil) set_current_tenant(nil)
end end
end end
end

View File

@ -1,6 +1,10 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
class Users::SessionsController < Devise::SessionsController module Users
class SessionsController < Devise::SessionsController
clear_respond_to clear_respond_to
respond_to :json respond_to :json
end end
end