Merge pull request #6 from jedmund/weapon-mods
Add ability to add weapon modifications to grid weapons
This commit is contained in:
commit
4b57267386
20 changed files with 160 additions and 19 deletions
|
|
@ -1,12 +1,12 @@
|
||||||
class Api::V1::GridWeaponsController < Api::V1::ApiController
|
class Api::V1::GridWeaponsController < Api::V1::ApiController
|
||||||
|
before_action :set, except: ['create', 'update_uncap_level', 'destroy']
|
||||||
|
|
||||||
def create
|
def create
|
||||||
party = Party.find(weapon_params[:party_id])
|
party = Party.find(weapon_params[:party_id])
|
||||||
canonical_weapon = Weapon.find(weapon_params[:weapon_id])
|
canonical_weapon = Weapon.find(weapon_params[:weapon_id])
|
||||||
|
|
||||||
if current_user
|
if !current_user || party.user != current_user
|
||||||
if party.user != current_user
|
render_unauthorized_response
|
||||||
render_unauthorized_response
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if grid_weapon = GridWeapon.where(
|
if grid_weapon = GridWeapon.where(
|
||||||
|
|
@ -26,6 +26,20 @@ class Api::V1::GridWeaponsController < Api::V1::ApiController
|
||||||
render :show, status: :created if @weapon.save!
|
render :show, status: :created if @weapon.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if !current_user || @weapon.party.user != current_user
|
||||||
|
render_unauthorized_response
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: Server-side validation of weapon mods
|
||||||
|
# We don't want someone modifying the JSON and adding
|
||||||
|
# keys to weapons that cannot have them
|
||||||
|
|
||||||
|
# Maybe we make methods on the model to validate for us somehow
|
||||||
|
|
||||||
|
render :update, status: :ok if @weapon.update(weapon_params)
|
||||||
|
end
|
||||||
|
|
||||||
def update_uncap_level
|
def update_uncap_level
|
||||||
@weapon = GridWeapon.find(weapon_params[:id])
|
@weapon = GridWeapon.find(weapon_params[:id])
|
||||||
|
|
||||||
|
|
@ -39,13 +53,19 @@ class Api::V1::GridWeaponsController < Api::V1::ApiController
|
||||||
render :show, status: :ok if @weapon.save!
|
render :show, status: :ok if @weapon.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set
|
||||||
|
@weapon = GridWeapon.where("id = ?", params[:id]).first
|
||||||
|
end
|
||||||
|
|
||||||
# Specify whitelisted properties that can be modified.
|
# Specify whitelisted properties that can be modified.
|
||||||
def weapon_params
|
def weapon_params
|
||||||
params.require(:weapon).permit(:id, :party_id, :weapon_id, :position, :mainhand, :uncap_level)
|
params.require(:weapon).permit(
|
||||||
|
:id, :party_id, :weapon_id,
|
||||||
|
:position, :mainhand, :uncap_level, :element,
|
||||||
|
:weapon_key1_id, :weapon_key2_id, :weapon_key3_id,
|
||||||
|
:ax_modifier1, :ax_modifier2, :ax_strength1, :ax_strength2
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
11
app/controllers/api/v1/weapon_keys_controller.rb
Normal file
11
app/controllers/api/v1/weapon_keys_controller.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
class Api::V1::WeaponKeysController < Api::V1::ApiController
|
||||||
|
def all
|
||||||
|
conditions = {}
|
||||||
|
conditions[:series] = request.params['series']
|
||||||
|
conditions[:slot] = request.params['slot']
|
||||||
|
conditions[:group] = request.params['group'] unless request.params['group'].blank?
|
||||||
|
|
||||||
|
@keys = WeaponKey.where(conditions)
|
||||||
|
render :all, status: :ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,7 +1,20 @@
|
||||||
class GridWeapon < ApplicationRecord
|
class GridWeapon < ApplicationRecord
|
||||||
belongs_to :party
|
belongs_to :party
|
||||||
|
|
||||||
|
belongs_to :weapon_key1, class_name: 'WeaponKey', foreign_key: :weapon_key1_id, optional: true
|
||||||
|
belongs_to :weapon_key2, class_name: 'WeaponKey', foreign_key: :weapon_key2_id, optional: true
|
||||||
|
belongs_to :weapon_key3, class_name: 'WeaponKey', foreign_key: :weapon_key3_id, optional: true
|
||||||
|
|
||||||
def weapon
|
def weapon
|
||||||
Weapon.find(self.weapon_id)
|
Weapon.find(self.weapon_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def weapon_keys
|
||||||
|
weapon_keys = []
|
||||||
|
weapon_keys.push(self.weapon_key1) if self.weapon_key1 != nil
|
||||||
|
weapon_keys.push(self.weapon_key2) if self.weapon_key2 != nil
|
||||||
|
weapon_keys.push(self.weapon_key3) if self.weapon_key3 != nil
|
||||||
|
|
||||||
|
weapon_keys
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
attributes :id,
|
attributes :id,
|
||||||
:party_id,
|
:party_id,
|
||||||
:position,
|
:position,
|
||||||
:uncap_level
|
:uncap_level,
|
||||||
|
:perpetuity
|
||||||
|
|
||||||
node :object do |c|
|
node :object do |c|
|
||||||
partial("characters/base", :object => c.character)
|
partial("characters/base", :object => c.character)
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,26 @@ attributes :id,
|
||||||
:party_id,
|
:party_id,
|
||||||
:mainhand,
|
:mainhand,
|
||||||
:position,
|
:position,
|
||||||
:uncap_level
|
:uncap_level,
|
||||||
|
:element
|
||||||
|
|
||||||
node :object do |w|
|
node :object do |w|
|
||||||
partial("weapons/base", :object => w.weapon)
|
partial("weapons/base", :object => w.weapon)
|
||||||
|
end
|
||||||
|
|
||||||
|
node :weapon_keys, :if => lambda { |w| [2, 3, 17, 22].include?(w.weapon.series) } do |w|
|
||||||
|
partial("weapon_keys/base", :object => w.weapon_keys)
|
||||||
|
end
|
||||||
|
|
||||||
|
node :ax, :if => lambda { |w| w.weapon.ax > 0 } do |w|
|
||||||
|
[
|
||||||
|
{
|
||||||
|
:modifier => w.ax_modifier1,
|
||||||
|
:strength => w.ax_strength1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:modifier => w.ax_modifier2,
|
||||||
|
:strength => w.ax_strength2
|
||||||
|
}
|
||||||
|
]
|
||||||
end
|
end
|
||||||
3
app/views/api/v1/grid_weapons/update.json.rabl
Normal file
3
app/views/api/v1/grid_weapons/update.json.rabl
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
object @weapon
|
||||||
|
|
||||||
|
extends 'api/v1/grid_weapons/base'
|
||||||
3
app/views/api/v1/weapon_keys/all.json.rabl
Normal file
3
app/views/api/v1/weapon_keys/all.json.rabl
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
collection @keys
|
||||||
|
|
||||||
|
extends 'weapon_keys/base'
|
||||||
10
app/views/api/v1/weapon_keys/base.json.rabl
Normal file
10
app/views/api/v1/weapon_keys/base.json.rabl
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
object :weapon_key
|
||||||
|
|
||||||
|
attributes :id, :series, :slot, :group, :order
|
||||||
|
|
||||||
|
node :name do |k|
|
||||||
|
{
|
||||||
|
:en => k.name_en,
|
||||||
|
:jp => k.name_jp
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
@ -5,7 +5,11 @@ attributes :id,
|
||||||
:element,
|
:element,
|
||||||
:proficiency,
|
:proficiency,
|
||||||
:max_level,
|
:max_level,
|
||||||
:max_skill_level
|
:max_skill_level,
|
||||||
|
:limit,
|
||||||
|
:rarity,
|
||||||
|
:series,
|
||||||
|
:ax
|
||||||
|
|
||||||
node :name do |w|
|
node :name do |w|
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ Rails.application.routes.draw do
|
||||||
namespace :v1 do
|
namespace :v1 do
|
||||||
resources :parties, only: [:index, :create, :update, :destroy]
|
resources :parties, only: [:index, :create, :update, :destroy]
|
||||||
resources :users, only: [:create, :show]
|
resources :users, only: [:create, :show]
|
||||||
|
resources :grid_weapons, only: [:update]
|
||||||
resources :favorites, only: [:create]
|
resources :favorites, only: [:create]
|
||||||
|
|
||||||
get 'parties/favorites', to: 'parties#favorites'
|
get 'parties/favorites', to: 'parties#favorites'
|
||||||
|
|
@ -25,6 +26,7 @@ Rails.application.routes.draw do
|
||||||
get 'search/summons', to: 'search#summons'
|
get 'search/summons', to: 'search#summons'
|
||||||
|
|
||||||
get 'raids', to: 'raids#all'
|
get 'raids', to: 'raids#all'
|
||||||
|
get 'weapon_keys', to: 'weapon_keys#all'
|
||||||
|
|
||||||
post 'characters', to: 'grid_characters#create'
|
post 'characters', to: 'grid_characters#create'
|
||||||
post 'characters/update_uncap', to: 'grid_characters#update_uncap_level'
|
post 'characters/update_uncap', to: 'grid_characters#update_uncap_level'
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
class ChangeWeaponSeriesToNumber < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
change_column :weapons, :series, 'integer USING CAST(element AS integer)'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
class RemoveTimestampsFromWeaponKeys < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
remove_column :weapon_keys, :created_at, :datetime
|
||||||
|
remove_column :weapon_keys, :updated_at, :datetime
|
||||||
|
end
|
||||||
|
end
|
||||||
5
db/migrate/20220302050213_add_sub_type_to_weapon_keys.rb
Normal file
5
db/migrate/20220302050213_add_sub_type_to_weapon_keys.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddSubTypeToWeaponKeys < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
add_column :weapon_keys, :subtype, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddWeaponKey3ToGridWeapons < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
add_reference :grid_weapons, :weapon_key3, type: :uuid, foreign_key: { to_table: :weapon_keys }
|
||||||
|
end
|
||||||
|
end
|
||||||
8
db/migrate/20220302054011_add_ax_to_grid_weapons.rb
Normal file
8
db/migrate/20220302054011_add_ax_to_grid_weapons.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
class AddAxToGridWeapons < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
add_column :grid_weapons, :ax_modifier1, :integer
|
||||||
|
add_column :grid_weapons, :ax_strength1, :float
|
||||||
|
add_column :grid_weapons, :ax_modifier2, :integer
|
||||||
|
add_column :grid_weapons, :ax_strength2, :float
|
||||||
|
end
|
||||||
|
end
|
||||||
5
db/migrate/20220302054021_add_element_to_grid_weapons.rb
Normal file
5
db/migrate/20220302054021_add_element_to_grid_weapons.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddElementToGridWeapons < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
add_column :grid_weapons, :element, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddPerpetuityToGridCharacters < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
add_column :grid_characters, :perpetuity, :boolean
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
class RenameTypeAndSubTypeInWeaponKeys < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
rename_column :weapon_keys, :type, :slot
|
||||||
|
rename_column :weapon_keys, :subtype, :group
|
||||||
|
end
|
||||||
|
end
|
||||||
5
db/migrate/20220303092208_add_order_to_weapon_keys.rb
Normal file
5
db/migrate/20220303092208_add_order_to_weapon_keys.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddOrderToWeaponKeys < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
add_column :weapon_keys, :order, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
20
db/schema.rb
20
db/schema.rb
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2022_02_28_014758) do
|
ActiveRecord::Schema.define(version: 2022_03_03_092208) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pgcrypto"
|
enable_extension "pgcrypto"
|
||||||
|
|
@ -60,6 +60,7 @@ ActiveRecord::Schema.define(version: 2022_02_28_014758) do
|
||||||
t.integer "position"
|
t.integer "position"
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", precision: 6, null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
|
t.boolean "perpetuity"
|
||||||
t.index ["character_id"], name: "index_grid_characters_on_character_id"
|
t.index ["character_id"], name: "index_grid_characters_on_character_id"
|
||||||
t.index ["party_id"], name: "index_grid_characters_on_party_id"
|
t.index ["party_id"], name: "index_grid_characters_on_party_id"
|
||||||
end
|
end
|
||||||
|
|
@ -87,10 +88,14 @@ ActiveRecord::Schema.define(version: 2022_02_28_014758) do
|
||||||
t.integer "position"
|
t.integer "position"
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", precision: 6, null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
|
t.uuid "weapon_key3_id"
|
||||||
|
t.integer "ax_modifier1"
|
||||||
|
t.float "ax_strength1"
|
||||||
|
t.integer "ax_modifier2"
|
||||||
|
t.float "ax_strength2"
|
||||||
|
t.integer "element"
|
||||||
t.index ["party_id"], name: "index_grid_weapons_on_party_id"
|
t.index ["party_id"], name: "index_grid_weapons_on_party_id"
|
||||||
t.index ["weapon_id"], name: "index_grid_weapons_on_weapon_id"
|
t.index ["weapon_id"], name: "index_grid_weapons_on_weapon_id"
|
||||||
t.index ["weapon_key1_id"], name: "index_grid_weapons_on_weapon_key1_id"
|
|
||||||
t.index ["weapon_key2_id"], name: "index_grid_weapons_on_weapon_key2_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "oauth_access_grants", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
create_table "oauth_access_grants", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||||
|
|
@ -187,9 +192,9 @@ ActiveRecord::Schema.define(version: 2022_02_28_014758) do
|
||||||
t.string "name_en"
|
t.string "name_en"
|
||||||
t.string "name_jp"
|
t.string "name_jp"
|
||||||
t.integer "series"
|
t.integer "series"
|
||||||
t.integer "type"
|
t.integer "slot"
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.integer "group"
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.integer "order"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "weapons", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
create_table "weapons", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||||
|
|
@ -199,7 +204,7 @@ ActiveRecord::Schema.define(version: 2022_02_28_014758) do
|
||||||
t.integer "rarity"
|
t.integer "rarity"
|
||||||
t.integer "element"
|
t.integer "element"
|
||||||
t.integer "proficiency"
|
t.integer "proficiency"
|
||||||
t.string "series"
|
t.integer "series"
|
||||||
t.boolean "flb"
|
t.boolean "flb"
|
||||||
t.boolean "ulb"
|
t.boolean "ulb"
|
||||||
t.integer "max_level"
|
t.integer "max_level"
|
||||||
|
|
@ -217,6 +222,7 @@ ActiveRecord::Schema.define(version: 2022_02_28_014758) do
|
||||||
t.integer "ax"
|
t.integer "ax"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_foreign_key "grid_weapons", "weapon_keys", column: "weapon_key3_id"
|
||||||
add_foreign_key "oauth_access_grants", "oauth_applications", column: "application_id"
|
add_foreign_key "oauth_access_grants", "oauth_applications", column: "application_id"
|
||||||
add_foreign_key "oauth_access_tokens", "oauth_applications", column: "application_id"
|
add_foreign_key "oauth_access_tokens", "oauth_applications", column: "application_id"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue