Run Rubocop autocorrect on app/controllers
This commit is contained in:
parent
4fc95185fb
commit
0c7c69ee5e
@ -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
|
||||||
.then { |affinities| render json: affinities }
|
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 }
|
||||||
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
|
||||||
|
@ -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,9 +42,9 @@ 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 = {})
|
||||||
options.merge(path_params: { slug: ActsAsTenant.current_tenant&.slug })
|
options.merge(path_params: { slug: ActsAsTenant.current_tenant&.slug })
|
||||||
end
|
end
|
||||||
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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] } })
|
||||||
|
@ -1,29 +1,43 @@
|
|||||||
|
# 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:,
|
||||||
projected: {
|
guests:
|
||||||
total: expense_summary['total_projected'],
|
}
|
||||||
guests: expense_summary['projected_guests']
|
end
|
||||||
},
|
|
||||||
confirmed: {
|
private
|
||||||
total: expense_summary['total_confirmed'],
|
|
||||||
guests: expense_summary['confirmed_guests']
|
def guests
|
||||||
},
|
guest_summary = Guest.group(:status).count
|
||||||
status: {
|
|
||||||
paid: 0
|
{
|
||||||
}
|
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: {
|
||||||
|
total: expense_summary['total_projected'],
|
||||||
|
guests: expense_summary['projected_guests']
|
||||||
},
|
},
|
||||||
guests: {
|
confirmed: {
|
||||||
total: guest_summary.except('considered').values.sum,
|
total: expense_summary['total_confirmed'],
|
||||||
confirmed: guest_summary['confirmed'].to_i,
|
guests: expense_summary['confirmed_guests']
|
||||||
declined: guest_summary['declined'].to_i,
|
},
|
||||||
tentative: guest_summary['tentative'].to_i,
|
status: {
|
||||||
invited: guest_summary['invited'].to_i
|
paid: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -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
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Copyright (C) 2024 Manuel Bustillo
|
# Copyright (C) 2024 Manuel Bustillo
|
||||||
|
|
||||||
class TokensController < ApplicationController
|
class TokensController < ApplicationController
|
||||||
|
@ -1,23 +1,27 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Copyright (C) 2024 Manuel Bustillo
|
# Copyright (C) 2024 Manuel Bustillo
|
||||||
|
|
||||||
class Users::ConfirmationsController < Devise::ConfirmationsController
|
module Users
|
||||||
clear_respond_to
|
class ConfirmationsController < Devise::ConfirmationsController
|
||||||
respond_to :json
|
clear_respond_to
|
||||||
|
respond_to :json
|
||||||
|
|
||||||
def show
|
def show
|
||||||
super do |resource|
|
super do |resource|
|
||||||
if resource.errors.empty?
|
if resource.errors.empty?
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json { render json: resource, status: :ok }
|
format.json { render json: resource, status: :ok }
|
||||||
format.any { redirect_to root_path }
|
format.any { redirect_to root_path }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
render json: {
|
||||||
|
message: 'Record invalid',
|
||||||
|
errors: resource.errors.full_messages
|
||||||
|
}, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
else
|
return
|
||||||
render json: {
|
|
||||||
message: 'Record invalid',
|
|
||||||
errors: resource.errors.full_messages
|
|
||||||
}, status: :unprocessable_entity
|
|
||||||
end
|
end
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,28 +1,32 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Copyright (C) 2024 Manuel Bustillo
|
# Copyright (C) 2024 Manuel Bustillo
|
||||||
|
|
||||||
class Users::RegistrationsController < Devise::RegistrationsController
|
module Users
|
||||||
clear_respond_to
|
class RegistrationsController < Devise::RegistrationsController
|
||||||
respond_to :json
|
clear_respond_to
|
||||||
|
respond_to :json
|
||||||
|
|
||||||
before_action :validate_captcha!, only: :create
|
before_action :validate_captcha!, only: :create
|
||||||
|
|
||||||
def create
|
def create
|
||||||
wedding = Wedding.create(slug: params[:slug])
|
wedding = Wedding.create(slug: params[:slug])
|
||||||
unless wedding.persisted?
|
unless wedding.persisted?
|
||||||
render json: { errors: wedding.errors.full_messages }, status: :unprocessable_entity
|
render json: { errors: wedding.errors.full_messages }, status: :unprocessable_entity
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
ActsAsTenant.with_tenant(wedding) do
|
ActsAsTenant.with_tenant(wedding) do
|
||||||
super do |user|
|
super do |user|
|
||||||
wedding.destroy unless user.persisted?
|
wedding.destroy unless user.persisted?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_tenant
|
def set_tenant
|
||||||
set_current_tenant(nil)
|
set_current_tenant(nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -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
|
||||||
clear_respond_to
|
class SessionsController < Devise::SessionsController
|
||||||
respond_to :json
|
clear_respond_to
|
||||||
end
|
respond_to :json
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user