Add quick summons

* Adds quick summon migration
* Add route to update quick summon
* Add logic to update quick summon
This commit is contained in:
Justin Edmund 2023-06-18 05:19:01 -07:00
parent 56ccbe3dbb
commit d162084ed7
4 changed files with 38 additions and 20 deletions

View file

@ -9,7 +9,7 @@ module Api
end
view :nested do
fields :main, :friend, :position, :uncap_level, :transcendence_step
fields :main, :friend, :position, :quick_summon, :uncap_level, :transcendence_step
association :summon, name: :object, blueprint: SummonBlueprint
end

View file

@ -4,11 +4,11 @@ module Api
module V1
class GridSummonsController < Api::V1::ApiController
attr_reader :party, :incoming_summon
before_action :set, only: %w[update destroy]
before_action :set, only: %w[update update_uncap_level update_quick_summon destroy]
before_action :find_party, only: :create
before_action :find_incoming_summon, only: :create
before_action :authorize, only: %i[create update destroy]
before_action :authorize, only: %i[create update update_uncap_level update_quick_summon destroy]
def create
# Create the GridSummon with the desired parameters
@ -30,6 +30,31 @@ module Api
render_validation_error_response(@character)
end
def update_uncap_level
@summon.uncap_level = summon_params[:uncap_level]
@summon.transcendence_step = 0
return unless @summon.save!
render json: GridSummonBlueprint.render(@summon, view: :nested, root: :grid_summon)
end
def update_quick_summon
quick_summons = @summon.party.summons.select(&:quick_summon)
quick_summons.each do |summon|
summon.update!(quick_summon: false)
end
@summon.update!(quick_summon: summon_params[:quick_summon])
return unless @summon.persisted?
quick_summons -= [@summon]
summons = [@summon] + quick_summons
render json: GridSummonBlueprint.render(summons, view: :nested, root: :summons)
end
def save_summon(summon)
if (grid_summon = GridSummon.where(
party_id: party.id,
@ -58,19 +83,6 @@ module Api
render json: output
end
def update_uncap_level
summon = GridSummon.find(summon_params[:id])
render_unauthorized_response if current_user && (summon.party.user != current_user)
summon.uncap_level = summon_params[:uncap_level]
summon.transcendence_step = 0
return unless summon.save!
render json: GridSummonBlueprint.render(summon, view: :nested, root: :grid_summon)
end
def destroy
render_unauthorized_response if @summon.party.user != current_user
return render json: GridSummonBlueprint.render(@summon, view: :destroyed) if @summon.destroy
@ -103,13 +115,13 @@ module Api
end
def set
@summon = GridSummon.where('id = ?', params[:id]).first
@summon = GridSummon.where('id = ?', summon_params[:id]).first
end
# Specify whitelisted properties that can be modified.
def summon_params
params.require(:summon).permit(:id, :party_id, :summon_id, :position, :main, :friend, :uncap_level,
:transcendence_step)
params.require(:summon).permit(:id, :party_id, :summon_id, :position, :main, :friend,
:quick_summon, :uncap_level, :transcendence_step)
end
end
end

View file

@ -60,6 +60,7 @@ Rails.application.routes.draw do
post 'summons', to: 'grid_summons#create'
post 'summons/update_uncap', to: 'grid_summons#update_uncap_level'
post 'summons/update_quick_summon', to: 'grid_summons#update_quick_summon'
delete 'summons', to: 'grid_summons#destroy'
delete 'favorites', to: 'favorites#destroy'

View file

@ -0,0 +1,5 @@
class AddQuickSummonToGridSummons < ActiveRecord::Migration[7.0]
def change
add_column :grid_summons, :quick_summon, :boolean, default: false, null: false
end
end