Add quick summons
* Adds quick summon migration * Add route to update quick summon * Add logic to update quick summon
This commit is contained in:
parent
56ccbe3dbb
commit
d162084ed7
4 changed files with 38 additions and 20 deletions
|
|
@ -9,7 +9,7 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
view :nested do
|
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
|
association :summon, name: :object, blueprint: SummonBlueprint
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ module Api
|
||||||
class GridSummonsController < Api::V1::ApiController
|
class GridSummonsController < Api::V1::ApiController
|
||||||
attr_reader :party, :incoming_summon
|
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_party, only: :create
|
||||||
before_action :find_incoming_summon, 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
|
def create
|
||||||
# Create the GridSummon with the desired parameters
|
# Create the GridSummon with the desired parameters
|
||||||
|
|
@ -30,6 +30,31 @@ module Api
|
||||||
render_validation_error_response(@character)
|
render_validation_error_response(@character)
|
||||||
end
|
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)
|
def save_summon(summon)
|
||||||
if (grid_summon = GridSummon.where(
|
if (grid_summon = GridSummon.where(
|
||||||
party_id: party.id,
|
party_id: party.id,
|
||||||
|
|
@ -58,19 +83,6 @@ module Api
|
||||||
render json: output
|
render json: output
|
||||||
end
|
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
|
def destroy
|
||||||
render_unauthorized_response if @summon.party.user != current_user
|
render_unauthorized_response if @summon.party.user != current_user
|
||||||
return render json: GridSummonBlueprint.render(@summon, view: :destroyed) if @summon.destroy
|
return render json: GridSummonBlueprint.render(@summon, view: :destroyed) if @summon.destroy
|
||||||
|
|
@ -103,13 +115,13 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def set
|
def set
|
||||||
@summon = GridSummon.where('id = ?', params[:id]).first
|
@summon = GridSummon.where('id = ?', summon_params[:id]).first
|
||||||
end
|
end
|
||||||
|
|
||||||
# Specify whitelisted properties that can be modified.
|
# Specify whitelisted properties that can be modified.
|
||||||
def summon_params
|
def summon_params
|
||||||
params.require(:summon).permit(:id, :party_id, :summon_id, :position, :main, :friend, :uncap_level,
|
params.require(:summon).permit(:id, :party_id, :summon_id, :position, :main, :friend,
|
||||||
:transcendence_step)
|
:quick_summon, :uncap_level, :transcendence_step)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
post 'summons', to: 'grid_summons#create'
|
post 'summons', to: 'grid_summons#create'
|
||||||
post 'summons/update_uncap', to: 'grid_summons#update_uncap_level'
|
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 'summons', to: 'grid_summons#destroy'
|
||||||
|
|
||||||
delete 'favorites', to: 'favorites#destroy'
|
delete 'favorites', to: 'favorites#destroy'
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
Loading…
Reference in a new issue