Implement removing characters and weapons
This commit is contained in:
parent
73022778f6
commit
633db43e94
6 changed files with 44 additions and 31 deletions
|
|
@ -11,35 +11,30 @@ module Api
|
||||||
view :nested do
|
view :nested do
|
||||||
fields :position, :uncap_level, :perpetuity
|
fields :position, :uncap_level, :perpetuity
|
||||||
|
|
||||||
field :transcendence_step, if: ->(_fn, obj, _opt) {
|
field :transcendence_step, if: lambda { |_fn, obj, _opt|
|
||||||
obj.character.ulb
|
obj.character.ulb
|
||||||
} do |c|
|
} do |c|
|
||||||
c.transcendence_step
|
c.transcendence_step
|
||||||
end
|
end
|
||||||
|
|
||||||
field :awakening, if: ->(_fn, obj, _opt) {
|
field :awakening do |c|
|
||||||
!obj[:awakening].nil?
|
c.awakening
|
||||||
} do |c|
|
|
||||||
{
|
|
||||||
type: c.awakening[:type],
|
|
||||||
level: c.awakening[:level]
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
field :over_mastery, if: ->(_fn, obj, _opt) {
|
field :over_mastery, if: lambda { |_fn, obj, _opt|
|
||||||
!obj.ring1['modifier'].nil? && !obj.ring2['modifier'].nil?
|
!obj.ring1['modifier'].nil? && !obj.ring2['modifier'].nil?
|
||||||
} do |c|
|
} do |c|
|
||||||
rings = []
|
rings = []
|
||||||
|
|
||||||
rings.push(c.ring1) if !c.ring1['modifier'].nil?
|
rings.push(c.ring1) unless c.ring1['modifier'].nil?
|
||||||
rings.push(c.ring2) if !c.ring2['modifier'].nil?
|
rings.push(c.ring2) unless c.ring2['modifier'].nil?
|
||||||
rings.push(c.ring3) if !c.ring3['modifier'].nil?
|
rings.push(c.ring3) unless c.ring3['modifier'].nil?
|
||||||
rings.push(c.ring4) if !c.ring4['modifier'].nil?
|
rings.push(c.ring4) unless c.ring4['modifier'].nil?
|
||||||
|
|
||||||
rings
|
rings
|
||||||
end
|
end
|
||||||
|
|
||||||
field :aetherial_mastery, if: ->(_fn, obj, _opt) {
|
field :aetherial_mastery, if: lambda { |_fn, obj, _opt|
|
||||||
!obj.earring['modifier'].nil?
|
!obj.earring['modifier'].nil?
|
||||||
} do |c|
|
} do |c|
|
||||||
c.earring
|
c.earring
|
||||||
|
|
@ -52,6 +47,10 @@ module Api
|
||||||
include_view :nested
|
include_view :nested
|
||||||
association :party, blueprint: PartyBlueprint, view: :minimal
|
association :party, blueprint: PartyBlueprint, view: :minimal
|
||||||
end
|
end
|
||||||
|
|
||||||
|
view :destroyed do
|
||||||
|
fields :position, :created_at, :updated_at
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,10 @@ module Api
|
||||||
include_view :nested
|
include_view :nested
|
||||||
association :party, blueprint: PartyBlueprint, view: :minimal
|
association :party, blueprint: PartyBlueprint, view: :minimal
|
||||||
end
|
end
|
||||||
|
|
||||||
|
view :destroyed do
|
||||||
|
fields :mainhand, :position, :created_at, :updated_at
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ module Api
|
||||||
attr_reader :party, :incoming_character, :current_characters
|
attr_reader :party, :incoming_character, :current_characters
|
||||||
|
|
||||||
before_action :find_party, only: :create
|
before_action :find_party, only: :create
|
||||||
before_action :set, only: [:update, :destroy]
|
before_action :set, only: %i[update destroy]
|
||||||
before_action :check_authorization, only: [:update, :destroy]
|
before_action :check_authorization, only: %i[update destroy]
|
||||||
before_action :find_incoming_character, only: :create
|
before_action :find_incoming_character, only: :create
|
||||||
before_action :find_current_characters, only: :create
|
before_action :find_current_characters, only: :create
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ module Api
|
||||||
|
|
||||||
def update
|
def update
|
||||||
mastery = {}
|
mastery = {}
|
||||||
[:ring1, :ring2, :ring3, :ring4, :earring, :awakening].each do |key|
|
%i[ring1 ring2 ring3 ring4 earring awakening].each do |key|
|
||||||
value = character_params.to_h[key]
|
value = character_params.to_h[key]
|
||||||
mastery[key] = value unless value.nil?
|
mastery[key] = value unless value.nil?
|
||||||
end
|
end
|
||||||
|
|
@ -49,8 +49,10 @@ module Api
|
||||||
@character.attributes = character_params.merge(mastery)
|
@character.attributes = character_params.merge(mastery)
|
||||||
|
|
||||||
if @character.save
|
if @character.save
|
||||||
|
ap 'Saved character'
|
||||||
return render json: GridCharacterBlueprint.render(@character, view: :full) if @character.save
|
return render json: GridCharacterBlueprint.render(@character, view: :full) if @character.save
|
||||||
else
|
else
|
||||||
|
ap 'Could not save'
|
||||||
render_validation_error_response(@character)
|
render_validation_error_response(@character)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -94,7 +96,10 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Implement removing characters
|
# TODO: Implement removing characters
|
||||||
def destroy; end
|
def destroy
|
||||||
|
render_unauthorized_response if @character.party.user != current_user
|
||||||
|
return render json: GridCharacterBlueprint.render(@character, view: :destroyed) if @character.destroy
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
@ -122,7 +127,7 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def set
|
def set
|
||||||
@character = GridCharacter.find(character_params[:id])
|
@character = GridCharacter.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_incoming_character
|
def find_incoming_character
|
||||||
|
|
@ -142,9 +147,9 @@ module Api
|
||||||
def character_params
|
def character_params
|
||||||
params.require(:character).permit(:id, :party_id, :character_id, :position,
|
params.require(:character).permit(:id, :party_id, :character_id, :position,
|
||||||
:uncap_level, :transcendence_step, :perpetuity,
|
:uncap_level, :transcendence_step, :perpetuity,
|
||||||
:ring1 => [:modifier, :strength], :ring2 => [:modifier, :strength],
|
ring1: %i[modifier strength], ring2: %i[modifier strength],
|
||||||
:ring3 => [:modifier, :strength], :ring4 => [:modifier, :strength],
|
ring3: %i[modifier strength], ring4: %i[modifier strength],
|
||||||
:earring => [:modifier, :strength], :awakening => [:type, :level])
|
earring: %i[modifier strength], awakening: %i[type level])
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolve_params
|
def resolve_params
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
module Api
|
module Api
|
||||||
module V1
|
module V1
|
||||||
class GridWeaponsController < Api::V1::ApiController
|
class GridWeaponsController < Api::V1::ApiController
|
||||||
before_action :set, except: %w[create update_uncap_level destroy]
|
before_action :set, except: %w[create update_uncap_level]
|
||||||
|
|
||||||
attr_reader :party, :incoming_weapon
|
attr_reader :party, :incoming_weapon
|
||||||
|
|
||||||
|
|
@ -56,7 +56,10 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Implement removing characters
|
# TODO: Implement removing characters
|
||||||
def destroy; end
|
def destroy
|
||||||
|
render_unauthorized_response if @weapon.party.user != current_user
|
||||||
|
return render json: GridCharacterBlueprint.render(@weapon, view: :destroyed) if @weapon.destroy
|
||||||
|
end
|
||||||
|
|
||||||
def update_uncap_level
|
def update_uncap_level
|
||||||
weapon = GridWeapon.find(weapon_params[:id])
|
weapon = GridWeapon.find(weapon_params[:id])
|
||||||
|
|
@ -115,15 +118,15 @@ module Api
|
||||||
# Render the conflict view as a string
|
# Render the conflict view as a string
|
||||||
def render_conflict_view(conflict_weapon, incoming_weapon, incoming_position)
|
def render_conflict_view(conflict_weapon, incoming_weapon, incoming_position)
|
||||||
ConflictBlueprint.render(nil, view: :weapons,
|
ConflictBlueprint.render(nil, view: :weapons,
|
||||||
conflict_weapon: conflict_weapon,
|
conflict_weapon: conflict_weapon,
|
||||||
incoming_weapon: incoming_weapon,
|
incoming_weapon: incoming_weapon,
|
||||||
incoming_position: incoming_position)
|
incoming_position: incoming_position)
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_grid_weapon_view(grid_weapon, conflict_position)
|
def render_grid_weapon_view(grid_weapon, conflict_position)
|
||||||
GridWeaponBlueprint.render(grid_weapon, view: :full,
|
GridWeaponBlueprint.render(grid_weapon, view: :full,
|
||||||
root: :grid_weapon,
|
root: :grid_weapon,
|
||||||
meta: { replaced: conflict_position })
|
meta: { replaced: conflict_position })
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_weapon(weapon)
|
def save_weapon(weapon)
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,8 @@ class GridCharacter < ApplicationRecord
|
||||||
def validate_aetherial_mastery_value
|
def validate_aetherial_mastery_value
|
||||||
return if earring['modifier'].nil?
|
return if earring['modifier'].nil?
|
||||||
|
|
||||||
|
return unless earring['modifier'].positive?
|
||||||
|
|
||||||
modifier = aetherial_mastery_modifiers[earring['modifier']].to_sym
|
modifier = aetherial_mastery_modifiers[earring['modifier']].to_sym
|
||||||
check_value({ "earring": { modifier => earring['strength'] } },
|
check_value({ "earring": { modifier => earring['strength'] } },
|
||||||
'aetherial_mastery')
|
'aetherial_mastery')
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ Rails.application.routes.draw do
|
||||||
namespace :v1 do
|
namespace :v1 do
|
||||||
resources :parties, only: %i[index create update destroy]
|
resources :parties, only: %i[index create update destroy]
|
||||||
resources :users, only: %i[create update show]
|
resources :users, only: %i[create update show]
|
||||||
resources :grid_weapons, only: [:update]
|
resources :grid_weapons, only: %i[update destroy]
|
||||||
resources :grid_characters, only: [:update]
|
resources :grid_characters, only: %i[update destroy]
|
||||||
resources :favorites, only: [:create]
|
resources :favorites, only: [:create]
|
||||||
|
|
||||||
get 'users/info/:id', to: 'users#info'
|
get 'users/info/:id', to: 'users#info'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue