From 6cf9c8d2ae41130b9cf5479ca5caac587b9cb2e4 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 6 Jan 2023 01:29:09 -0800 Subject: [PATCH 01/86] Create 20230106023753_change_awakening_type_default_value.rb --- .../20230106023753_change_awakening_type_default_value.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 db/migrate/20230106023753_change_awakening_type_default_value.rb diff --git a/db/migrate/20230106023753_change_awakening_type_default_value.rb b/db/migrate/20230106023753_change_awakening_type_default_value.rb new file mode 100644 index 0000000..89d0f01 --- /dev/null +++ b/db/migrate/20230106023753_change_awakening_type_default_value.rb @@ -0,0 +1,5 @@ +class ChangeAwakeningTypeDefaultValue < ActiveRecord::Migration[7.0] + def change + change_column :grid_characters, :awakening_type, :integer, null: false, default: 1 + end +end From 7404bcbac9691f0ac0272815ed25483ecc88990a Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 7 Jan 2023 05:33:16 -0800 Subject: [PATCH 02/86] Change mastery columns to use jsonb 5 columns better than 10 --- ...7121520_change_mastery_columns_to_jsonb.rb | 22 +++++++++++++++++++ db/schema.rb | 19 ++++++---------- 2 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20230107121520_change_mastery_columns_to_jsonb.rb diff --git a/db/migrate/20230107121520_change_mastery_columns_to_jsonb.rb b/db/migrate/20230107121520_change_mastery_columns_to_jsonb.rb new file mode 100644 index 0000000..b8319cc --- /dev/null +++ b/db/migrate/20230107121520_change_mastery_columns_to_jsonb.rb @@ -0,0 +1,22 @@ +class ChangeMasteryColumnsToJsonb < ActiveRecord::Migration[7.0] + def change + # Remove old columns + remove_column :grid_characters, :ring_modifier1, :integer + remove_column :grid_characters, :ring_modifier2, :integer + remove_column :grid_characters, :ring_modifier3, :integer + remove_column :grid_characters, :ring_modifier4, :integer + remove_column :grid_characters, :ring_strength1, :integer + remove_column :grid_characters, :ring_strength2, :integer + remove_column :grid_characters, :ring_strength3, :integer + remove_column :grid_characters, :ring_strength4, :integer + remove_column :grid_characters, :earring_modifier, :integer + remove_column :grid_characters, :earring_strength, :integer + + # Add new columns + add_column :grid_characters, :ring1, :jsonb, default: { modifier: nil, strength: nil } + add_column :grid_characters, :ring2, :jsonb, default: { modifier: nil, strength: nil } + add_column :grid_characters, :ring3, :jsonb, default: { modifier: nil, strength: nil } + add_column :grid_characters, :ring4, :jsonb, default: { modifier: nil, strength: nil } + add_column :grid_characters, :earring, :jsonb, default: { modifier: nil, strength: nil } + end +end diff --git a/db/schema.rb b/db/schema.rb index 0b5c6cb..e6a1429 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_01_03_180458) do +ActiveRecord::Schema[7.0].define(version: 2023_01_07_121520) do # These are extensions that must be enabled in order to support this database enable_extension "btree_gin" enable_extension "pg_trgm" @@ -67,19 +67,14 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_03_180458) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "perpetuity", default: false, null: false - t.integer "awakening_type", default: 0, null: false + t.integer "awakening_type", default: 1, null: false t.integer "awakening_level", default: 1, null: false t.integer "transcendence_step", default: 0, null: false - t.integer "ring_modifier1" - t.float "ring_strength1" - t.integer "ring_modifier2" - t.float "ring_strength2" - t.integer "ring_modifier3" - t.float "ring_strength3" - t.integer "ring_modifier4" - t.float "ring_strength4" - t.integer "earring_modifier" - t.float "earring_strength" + t.jsonb "ring1", default: {"modifier"=>nil, "strength"=>nil} + t.jsonb "ring2", default: {"modifier"=>nil, "strength"=>nil} + t.jsonb "ring3", default: {"modifier"=>nil, "strength"=>nil} + t.jsonb "ring4", default: {"modifier"=>nil, "strength"=>nil} + t.jsonb "earring", default: {"modifier"=>nil, "strength"=>nil} t.index ["character_id"], name: "index_grid_characters_on_character_id" t.index ["party_id"], name: "index_grid_characters_on_party_id" end From a2fff663d605a3802d16c3ab5c38831ec5e6f879 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 7 Jan 2023 07:49:28 -0800 Subject: [PATCH 03/86] More database updates for mastery cols * Awakening should be jsonb * All mastery columns are not nullable --- ...107150547_change_awakening_columns_to_jsonb.rb | 10 ++++++++++ ...107153724_make_mastery_columns_not_nullable.rb | 10 ++++++++++ db/schema.rb | 15 +++++++-------- 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20230107150547_change_awakening_columns_to_jsonb.rb create mode 100644 db/migrate/20230107153724_make_mastery_columns_not_nullable.rb diff --git a/db/migrate/20230107150547_change_awakening_columns_to_jsonb.rb b/db/migrate/20230107150547_change_awakening_columns_to_jsonb.rb new file mode 100644 index 0000000..3a48821 --- /dev/null +++ b/db/migrate/20230107150547_change_awakening_columns_to_jsonb.rb @@ -0,0 +1,10 @@ +class ChangeAwakeningColumnsToJsonb < ActiveRecord::Migration[7.0] + def change + # Remove old columns + remove_column :grid_characters, :awakening_type, :integer + remove_column :grid_characters, :awakening_level, :integer + + # Add new column + add_column :grid_characters, :awakening, :jsonb, default: { type: 1, level: 1 } + end +end diff --git a/db/migrate/20230107153724_make_mastery_columns_not_nullable.rb b/db/migrate/20230107153724_make_mastery_columns_not_nullable.rb new file mode 100644 index 0000000..976ca5a --- /dev/null +++ b/db/migrate/20230107153724_make_mastery_columns_not_nullable.rb @@ -0,0 +1,10 @@ +class MakeMasteryColumnsNotNullable < ActiveRecord::Migration[7.0] + def change + change_column :grid_characters, :ring1, :jsonb, null: false + change_column :grid_characters, :ring2, :jsonb, null: false + change_column :grid_characters, :ring3, :jsonb, null: false + change_column :grid_characters, :ring4, :jsonb, null: false + change_column :grid_characters, :earring, :jsonb, null: false + change_column :grid_characters, :awakening, :jsonb, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index e6a1429..4cea1cb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_01_07_121520) do +ActiveRecord::Schema[7.0].define(version: 2023_01_07_153724) do # These are extensions that must be enabled in order to support this database enable_extension "btree_gin" enable_extension "pg_trgm" @@ -67,14 +67,13 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_07_121520) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "perpetuity", default: false, null: false - t.integer "awakening_type", default: 1, null: false - t.integer "awakening_level", default: 1, null: false t.integer "transcendence_step", default: 0, null: false - t.jsonb "ring1", default: {"modifier"=>nil, "strength"=>nil} - t.jsonb "ring2", default: {"modifier"=>nil, "strength"=>nil} - t.jsonb "ring3", default: {"modifier"=>nil, "strength"=>nil} - t.jsonb "ring4", default: {"modifier"=>nil, "strength"=>nil} - t.jsonb "earring", default: {"modifier"=>nil, "strength"=>nil} + t.jsonb "ring1", default: {"modifier"=>nil, "strength"=>nil}, null: false + t.jsonb "ring2", default: {"modifier"=>nil, "strength"=>nil}, null: false + t.jsonb "ring3", default: {"modifier"=>nil, "strength"=>nil}, null: false + t.jsonb "ring4", default: {"modifier"=>nil, "strength"=>nil}, null: false + t.jsonb "earring", default: {"modifier"=>nil, "strength"=>nil}, null: false + t.jsonb "awakening", default: {"type"=>1, "level"=>1}, null: false t.index ["character_id"], name: "index_grid_characters_on_character_id" t.index ["party_id"], name: "index_grid_characters_on_party_id" end From beb9f5aa0cda365e7c4169310c3d17dd3c7831d2 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 7 Jan 2023 07:49:39 -0800 Subject: [PATCH 04/86] Add GridCharacters#update route --- config/routes.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/routes.rb b/config/routes.rb index 91094d7..8256840 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,7 @@ Rails.application.routes.draw do resources :parties, only: %i[index create update destroy] resources :users, only: %i[create update show] resources :grid_weapons, only: [:update] + resources :grid_characters, only: [:update] resources :favorites, only: [:create] get 'users/info/:id', to: 'users#info' From 5351123aa2901f912ed594c5ffb848a2081d5a37 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 7 Jan 2023 07:51:04 -0800 Subject: [PATCH 05/86] Add basic validation for various mastery bonuses * Ensure transcendence is possible on that character * Ensure transcendence_step is in bounds * Ensure Over Mastery Attack is a valid value * Ensure Over Mastery HP is a valid value * Ensure Over Mastery Attack is 2x Over Mastery HP * Ensure Awakening level is in bounds --- app/blueprints/api/v1/error_blueprint.rb | 4 +++ app/models/grid_character.rb | 46 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/app/blueprints/api/v1/error_blueprint.rb b/app/blueprints/api/v1/error_blueprint.rb index 78a431a..29796c0 100644 --- a/app/blueprints/api/v1/error_blueprint.rb +++ b/app/blueprints/api/v1/error_blueprint.rb @@ -14,6 +14,10 @@ module Api field :errors, if: ->(_field_name, _error, options) { options.key?(:exception) } do |_, options| options[:exception] end + + field :errors, if: ->(_field_name, object, options) { options.key?(:errors) } do |_, options| + options[:errors] + end end end end diff --git a/app/models/grid_character.rb b/app/models/grid_character.rb index 2e3e16b..e60bcf9 100644 --- a/app/models/grid_character.rb +++ b/app/models/grid_character.rb @@ -3,6 +3,42 @@ class GridCharacter < ApplicationRecord belongs_to :party + validate :awakening_level, on: :update + validate :transcendence, on: :update + validate :over_mastery_attack, on: :update + validate :over_mastery_hp, on: :update + validate :over_mastery_attack_matches_hp, on: :update + + def awakening_level + unless awakening.nil? + errors.add(:awakening, 'awakening level too low') if awakening["level"] < 1 + errors.add(:awakening, 'awakening level too high') if awakening["level"] > 9 + end + end + + def transcendence + errors.add(:transcendence_step, 'character has no transcendence') if transcendence_step > 0 && !character.ulb + errors.add(:transcendence_step, 'transcendence step too high') if transcendence_step > 5 && character.ulb + errors.add(:transcendence_step, 'transcendence step too low') if transcendence_step < 0 && character.ulb + + end + + def over_mastery_attack + errors.add(:ring1, 'invalid value') unless ring1["modifier"].nil? || atk_values.include?(ring1["strength"]) + end + + def over_mastery_hp + unless ring2["modifier"].nil? + errors.add(:ring2, 'invalid value') unless hp_values.include?(ring2["strength"]) + end + end + + def over_mastery_attack_matches_hp + unless ring1[:modifier].nil? && ring2[:modifier].nil? + errors.add(:over_mastery, 'over mastery attack and hp values do not match') unless ring2[:strength] == (ring1[:strength] / 2) + end + end + def character Character.find(character_id) end @@ -10,4 +46,14 @@ class GridCharacter < ApplicationRecord def blueprint GridCharacterBlueprint end + + private + + def atk_values + [300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000] + end + + def hp_values + [150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500] + end end From 3617088418f6e64e40558d46b3954cf47c605ec3 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 7 Jan 2023 07:51:40 -0800 Subject: [PATCH 06/86] Add update method for GridCharacter and other utils * Add check_authorization for before update and eventually destroy runs * Update permitted parameters --- .../api/v1/grid_characters_controller.rb | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v1/grid_characters_controller.rb b/app/controllers/api/v1/grid_characters_controller.rb index 2f68524..347ef93 100644 --- a/app/controllers/api/v1/grid_characters_controller.rb +++ b/app/controllers/api/v1/grid_characters_controller.rb @@ -6,6 +6,8 @@ module Api attr_reader :party, :incoming_character, :current_characters before_action :find_party, only: :create + before_action :set, only: [:update, :destroy] + before_action :check_authorization, only: [:update, :destroy] before_action :find_incoming_character, only: :create before_action :find_current_characters, only: :create @@ -37,6 +39,22 @@ module Api end end + def update + mastery = {} + [:ring1, :ring2, :ring3, :ring4, :earring, :awakening].each do |key| + value = character_params.to_h[key] + mastery[key] = value unless value.nil? + end + + @character.attributes = character_params.merge(mastery) + + if @character.save + return render json: GridCharacterBlueprint.render(@character, view: :full) if @character.save + else + render_validation_error_response(@character) + end + end + def resolve incoming = Character.find(resolve_params[:incoming]) conflicting = resolve_params[:conflicting].map { |id| GridCharacter.find(id) } @@ -103,6 +121,10 @@ module Api end.flatten end + def set + @character = GridCharacter.find(character_params[:id]) + end + def find_incoming_character @incoming_character = Character.find(character_params[:character_id]) end @@ -112,10 +134,21 @@ module Api render_unauthorized_response if current_user && (party.user != current_user) end + def check_authorization + render_unauthorized_response if @character.party.user != current_user + end + # Specify whitelisted properties that can be modified. def character_params - params.require(:character).permit(:id, :party_id, :character_id, :position, :uncap_level, :conflicting, - :incoming) + params.require(:character).permit(:id, :party_id, :character_id, :position, + :uncap_level, :transcendence_step, :perpetuity, + :ring1 => [:modifier, :strength], :ring2 => [:modifier, :strength], + :ring3 => [:modifier, :strength], :ring4 => [:modifier, :strength], + :earring => [:modifier, :strength], :awakening => [:type, :level]) + end + + def resolve_params + params.require(:resolve).permit(:position, :incoming, conflicting: []) end def render_conflict_view(conflict_characters, incoming_character, incoming_position) @@ -129,10 +162,6 @@ module Api def render_grid_character_view(grid_character) GridCharacterBlueprint.render(grid_character, view: :nested) end - - def resolve_params - params.require(:resolve).permit(:position, :incoming, conflicting: []) - end end end end From 8f9bd0077e727b02682354e7b22d925add0b7d92 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 7 Jan 2023 07:51:54 -0800 Subject: [PATCH 07/86] Add new fields to output of GridCharacter --- .../api/v1/grid_character_blueprint.rb | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/app/blueprints/api/v1/grid_character_blueprint.rb b/app/blueprints/api/v1/grid_character_blueprint.rb index c753940..4ef5e97 100644 --- a/app/blueprints/api/v1/grid_character_blueprint.rb +++ b/app/blueprints/api/v1/grid_character_blueprint.rb @@ -11,13 +11,40 @@ module Api view :nested do fields :position, :uncap_level, :perpetuity - field :awakening do |c| + field :transcendence_step, if: ->(_fn, obj, _opt) { + obj.character.ulb + } do |c| + c.transcendence_step + end + + field :awakening, if: ->(_fn, obj, _opt) { + !obj[:awakening].nil? + } do |c| { - type: c.awakening_type, - level: c.awakening_level + type: c.awakening[:type], + level: c.awakening[:level] } end + field :over_mastery, if: ->(_fn, obj, _opt) { + !obj.ring1['modifier'].nil? && !obj.ring2['modifier'].nil? + } do |c| + rings = [] + + rings.push(c.ring1) if !c.ring1['modifier'].nil? + rings.push(c.ring2) if !c.ring2['modifier'].nil? + rings.push(c.ring3) if !c.ring3['modifier'].nil? + rings.push(c.ring4) if !c.ring4['modifier'].nil? + + rings + end + + field :aetherial_mastery, if: ->(_fn, obj, _opt) { + !obj.earring['modifier'].nil? + } do |c| + c.earring + end + association :character, name: :object, blueprint: CharacterBlueprint end From 24b15c0740d80b9c0206d4ee6cfa71977cf1c14b Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 8 Jan 2023 07:03:09 -0800 Subject: [PATCH 08/86] Add amoeba gem for cloning ActiveRecord objects --- Gemfile | 3 +++ Gemfile.lock | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Gemfile b/Gemfile index 3565c3f..66eeb1b 100644 --- a/Gemfile +++ b/Gemfile @@ -46,6 +46,9 @@ gem 'will_paginate', '~> 3.3' # Migrate and update data alongside your database structure. gem 'data_migrate' +# A ruby gem to allow the copying of ActiveRecord objects and their associated children, configurable with a DSL on the model +gem 'amoeba' + group :doc do gem 'apipie-rails' gem 'sdoc' diff --git a/Gemfile.lock b/Gemfile.lock index 62087bc..a982265 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -67,6 +67,8 @@ GEM minitest (>= 5.1) tzinfo (~> 2.0) amazing_print (1.4.0) + amoeba (3.2.0) + activerecord (>= 4.2.0) api_matchers (0.6.2) activesupport (>= 3.2.5) nokogiri (>= 1.5.2) @@ -305,6 +307,7 @@ PLATFORMS DEPENDENCIES amazing_print + amoeba api_matchers apipie-rails awesome_nested_set From 70bbd476061bbb48a589e289ddf01c6c6408bc9b Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 8 Jan 2023 07:03:24 -0800 Subject: [PATCH 09/86] Add endpoint and stub method --- app/controllers/api/v1/parties_controller.rb | 3 +++ config/routes.rb | 1 + 2 files changed, 4 insertions(+) diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index 258de6a..ff4ea0b 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -57,6 +57,9 @@ module Api return render json: PartyBlueprint.render(@party, view: :destroyed, root: :checkin) if @party.destroy end + def remix + end + def index conditions = build_conditions(request.params) diff --git a/config/routes.rb b/config/routes.rb index 8256840..ee59a61 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,6 +16,7 @@ Rails.application.routes.draw do get 'parties/favorites', to: 'parties#favorites' get 'parties/:id', to: 'parties#show' + post 'parties/:id/remix', to: 'parties#remix' put 'parties/:id/jobs', to: 'jobs#update_job' put 'parties/:id/job_skills', to: 'jobs#update_job_skills' From c2576973bb6e96a7924098123452b0b176b83abe Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 8 Jan 2023 19:03:25 -0800 Subject: [PATCH 10/86] Add source party column to parties --- ...30108150956_add_source_party_to_parties.rb | 7 + db/schema.rb | 541 +++++++++--------- 2 files changed, 279 insertions(+), 269 deletions(-) create mode 100644 db/migrate/20230108150956_add_source_party_to_parties.rb diff --git a/db/migrate/20230108150956_add_source_party_to_parties.rb b/db/migrate/20230108150956_add_source_party_to_parties.rb new file mode 100644 index 0000000..f2e4071 --- /dev/null +++ b/db/migrate/20230108150956_add_source_party_to_parties.rb @@ -0,0 +1,7 @@ +class AddSourcePartyToParties < ActiveRecord::Migration[7.0] + def change + change_table(:parties) do |t| + t.references :source_party, type: :uuid, foreign_key: { to_table: 'parties' } + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 4cea1cb..7cfa3d0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,309 +10,312 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_01_07_153724) do +ActiveRecord::Schema[7.0].define(version: 20_230_108_150_956) do # These are extensions that must be enabled in order to support this database - enable_extension "btree_gin" - enable_extension "pg_trgm" - enable_extension "pgcrypto" - enable_extension "plpgsql" + enable_extension 'btree_gin' + enable_extension 'pg_trgm' + enable_extension 'pgcrypto' + enable_extension 'plpgsql' - create_table "characters", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.string "name_en" - t.string "name_jp" - t.string "granblue_id" - t.integer "rarity" - t.integer "element" - t.integer "proficiency1" - t.integer "proficiency2" - t.integer "gender" - t.integer "race1" - t.integer "race2" - t.boolean "flb", default: false, null: false - t.integer "min_hp" - t.integer "max_hp" - t.integer "max_hp_flb" - t.integer "min_atk" - t.integer "max_atk" - t.integer "max_atk_flb" - t.integer "base_da" - t.integer "base_ta" - t.float "ougi_ratio" - t.float "ougi_ratio_flb" - t.boolean "special", default: false, null: false - t.boolean "ulb", default: false, null: false - t.integer "max_hp_ulb" - t.integer "max_atk_ulb" - t.integer "character_id", default: [], null: false, array: true - t.index ["name_en"], name: "index_characters_on_name_en", opclass: :gin_trgm_ops, using: :gin + create_table 'characters', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.string 'name_en' + t.string 'name_jp' + t.string 'granblue_id' + t.integer 'rarity' + t.integer 'element' + t.integer 'proficiency1' + t.integer 'proficiency2' + t.integer 'gender' + t.integer 'race1' + t.integer 'race2' + t.boolean 'flb', default: false, null: false + t.integer 'min_hp' + t.integer 'max_hp' + t.integer 'max_hp_flb' + t.integer 'min_atk' + t.integer 'max_atk' + t.integer 'max_atk_flb' + t.integer 'base_da' + t.integer 'base_ta' + t.float 'ougi_ratio' + t.float 'ougi_ratio_flb' + t.boolean 'special', default: false, null: false + t.boolean 'ulb', default: false, null: false + t.integer 'max_hp_ulb' + t.integer 'max_atk_ulb' + t.integer 'character_id', default: [], null: false, array: true + t.index ['name_en'], name: 'index_characters_on_name_en', opclass: :gin_trgm_ops, using: :gin end - create_table "data_migrations", primary_key: "version", id: :string, force: :cascade do |t| + create_table 'data_migrations', primary_key: 'version', id: :string, force: :cascade do |t| end - create_table "favorites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.uuid "user_id" - t.uuid "party_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["party_id"], name: "index_favorites_on_party_id" - t.index ["user_id"], name: "index_favorites_on_user_id" + create_table 'favorites', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.uuid 'user_id' + t.uuid 'party_id' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['party_id'], name: 'index_favorites_on_party_id' + t.index ['user_id'], name: 'index_favorites_on_user_id' end - create_table "grid_characters", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.uuid "party_id" - t.uuid "character_id" - t.integer "uncap_level" - t.integer "position" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "perpetuity", default: false, null: false - t.integer "transcendence_step", default: 0, null: false - t.jsonb "ring1", default: {"modifier"=>nil, "strength"=>nil}, null: false - t.jsonb "ring2", default: {"modifier"=>nil, "strength"=>nil}, null: false - t.jsonb "ring3", default: {"modifier"=>nil, "strength"=>nil}, null: false - t.jsonb "ring4", default: {"modifier"=>nil, "strength"=>nil}, null: false - t.jsonb "earring", default: {"modifier"=>nil, "strength"=>nil}, null: false - t.jsonb "awakening", default: {"type"=>1, "level"=>1}, null: false - t.index ["character_id"], name: "index_grid_characters_on_character_id" - t.index ["party_id"], name: "index_grid_characters_on_party_id" + create_table 'grid_characters', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.uuid 'party_id' + t.uuid 'character_id' + t.integer 'uncap_level' + t.integer 'position' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.boolean 'perpetuity', default: false, null: false + t.integer 'transcendence_step', default: 0, null: false + t.jsonb 'ring1', default: { 'modifier' => nil, 'strength' => nil }, null: false + t.jsonb 'ring2', default: { 'modifier' => nil, 'strength' => nil }, null: false + t.jsonb 'ring3', default: { 'modifier' => nil, 'strength' => nil }, null: false + t.jsonb 'ring4', default: { 'modifier' => nil, 'strength' => nil }, null: false + t.jsonb 'earring', default: { 'modifier' => nil, 'strength' => nil }, null: false + t.jsonb 'awakening', default: { 'type' => 1, 'level' => 1 }, null: false + t.index ['character_id'], name: 'index_grid_characters_on_character_id' + t.index ['party_id'], name: 'index_grid_characters_on_party_id' end - create_table "grid_summons", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.uuid "party_id" - t.uuid "summon_id" - t.integer "uncap_level" - t.boolean "main" - t.boolean "friend" - t.integer "position" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "transcendence_step", default: 0, null: false - t.index ["party_id"], name: "index_grid_summons_on_party_id" - t.index ["summon_id"], name: "index_grid_summons_on_summon_id" + create_table 'grid_summons', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.uuid 'party_id' + t.uuid 'summon_id' + t.integer 'uncap_level' + t.boolean 'main' + t.boolean 'friend' + t.integer 'position' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.integer 'transcendence_step', default: 0, null: false + t.index ['party_id'], name: 'index_grid_summons_on_party_id' + t.index ['summon_id'], name: 'index_grid_summons_on_summon_id' end - create_table "grid_weapons", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.uuid "party_id" - t.uuid "weapon_id" - t.uuid "weapon_key1_id" - t.uuid "weapon_key2_id" - t.integer "uncap_level" - t.boolean "mainhand" - t.integer "position" - t.datetime "created_at", null: false - t.datetime "updated_at", 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.integer "awakening_type" - t.integer "awakening_level", default: 1, null: false - t.index ["party_id"], name: "index_grid_weapons_on_party_id" - t.index ["weapon_id"], name: "index_grid_weapons_on_weapon_id" + create_table 'grid_weapons', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.uuid 'party_id' + t.uuid 'weapon_id' + t.uuid 'weapon_key1_id' + t.uuid 'weapon_key2_id' + t.integer 'uncap_level' + t.boolean 'mainhand' + t.integer 'position' + t.datetime 'created_at', null: false + t.datetime 'updated_at', 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.integer 'awakening_type' + t.integer 'awakening_level', default: 1, null: false + t.index ['party_id'], name: 'index_grid_weapons_on_party_id' + t.index ['weapon_id'], name: 'index_grid_weapons_on_weapon_id' end - create_table "job_skills", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.uuid "job_id" - t.string "name_en", null: false - t.string "name_jp", null: false - t.string "slug", null: false - t.integer "color", null: false - t.boolean "main", default: false - t.boolean "sub", default: false - t.boolean "emp", default: false - t.integer "order" - t.boolean "base", default: false - t.index ["job_id"], name: "index_job_skills_on_job_id" + create_table 'job_skills', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.uuid 'job_id' + t.string 'name_en', null: false + t.string 'name_jp', null: false + t.string 'slug', null: false + t.integer 'color', null: false + t.boolean 'main', default: false + t.boolean 'sub', default: false + t.boolean 'emp', default: false + t.integer 'order' + t.boolean 'base', default: false + t.index ['job_id'], name: 'index_job_skills_on_job_id' end - create_table "jobs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.string "name_en" - t.string "name_jp" - t.integer "proficiency1" - t.integer "proficiency2" - t.string "row" - t.boolean "ml", default: false - t.integer "order" - t.uuid "base_job_id" - t.index ["base_job_id"], name: "index_jobs_on_base_job_id" + create_table 'jobs', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.string 'name_en' + t.string 'name_jp' + t.integer 'proficiency1' + t.integer 'proficiency2' + t.string 'row' + t.boolean 'ml', default: false + t.integer 'order' + t.uuid 'base_job_id' + t.index ['base_job_id'], name: 'index_jobs_on_base_job_id' end - create_table "oauth_access_grants", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.uuid "resource_owner_id", null: false - t.uuid "application_id", null: false - t.string "token", null: false - t.integer "expires_in", null: false - t.text "redirect_uri", null: false - t.datetime "created_at", precision: nil, null: false - t.datetime "revoked_at", precision: nil - t.string "scopes" - t.index ["token"], name: "index_oauth_access_grants_on_token", unique: true + create_table 'oauth_access_grants', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.uuid 'resource_owner_id', null: false + t.uuid 'application_id', null: false + t.string 'token', null: false + t.integer 'expires_in', null: false + t.text 'redirect_uri', null: false + t.datetime 'created_at', precision: nil, null: false + t.datetime 'revoked_at', precision: nil + t.string 'scopes' + t.index ['token'], name: 'index_oauth_access_grants_on_token', unique: true end - create_table "oauth_access_tokens", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.uuid "resource_owner_id" - t.uuid "application_id" - t.string "token", null: false - t.string "refresh_token" - t.integer "expires_in" - t.datetime "revoked_at", precision: nil - t.datetime "created_at", precision: nil, null: false - t.string "scopes" - t.string "previous_refresh_token", default: "", null: false - t.index ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true - t.index ["resource_owner_id"], name: "index_oauth_access_tokens_on_resource_owner_id" - t.index ["token"], name: "index_oauth_access_tokens_on_token", unique: true + create_table 'oauth_access_tokens', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.uuid 'resource_owner_id' + t.uuid 'application_id' + t.string 'token', null: false + t.string 'refresh_token' + t.integer 'expires_in' + t.datetime 'revoked_at', precision: nil + t.datetime 'created_at', precision: nil, null: false + t.string 'scopes' + t.string 'previous_refresh_token', default: '', null: false + t.index ['refresh_token'], name: 'index_oauth_access_tokens_on_refresh_token', unique: true + t.index ['resource_owner_id'], name: 'index_oauth_access_tokens_on_resource_owner_id' + t.index ['token'], name: 'index_oauth_access_tokens_on_token', unique: true end - create_table "oauth_applications", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.string "name", null: false - t.string "uid", null: false - t.string "secret", null: false - t.text "redirect_uri", null: false - t.string "scopes", default: "", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["uid"], name: "index_oauth_applications_on_uid", unique: true + create_table 'oauth_applications', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.string 'name', null: false + t.string 'uid', null: false + t.string 'secret', null: false + t.text 'redirect_uri', null: false + t.string 'scopes', default: '', null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['uid'], name: 'index_oauth_applications_on_uid', unique: true end - create_table "parties", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.uuid "user_id" - t.string "shortcode" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "extra", default: false, null: false - t.string "name" - t.text "description" - t.uuid "raid_id" - t.integer "element" - t.integer "weapons_count" - t.uuid "job_id" - t.integer "ml" - t.uuid "skill1_id" - t.uuid "skill2_id" - t.uuid "skill3_id" - t.uuid "skill0_id" - t.boolean "full_auto", default: false, null: false - t.boolean "auto_guard", default: false, null: false - t.boolean "charge_attack", default: true, null: false - t.integer "clear_time", default: 0, null: false - t.integer "button_count" - t.integer "chain_count" - t.integer "turn_count" - t.index ["job_id"], name: "index_parties_on_job_id" - t.index ["skill0_id"], name: "index_parties_on_skill0_id" - t.index ["skill1_id"], name: "index_parties_on_skill1_id" - t.index ["skill2_id"], name: "index_parties_on_skill2_id" - t.index ["skill3_id"], name: "index_parties_on_skill3_id" - t.index ["user_id"], name: "index_parties_on_user_id" + create_table 'parties', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.uuid 'user_id' + t.string 'shortcode' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.boolean 'extra', default: false, null: false + t.string 'name' + t.text 'description' + t.uuid 'raid_id' + t.integer 'element' + t.integer 'weapons_count' + t.uuid 'job_id' + t.integer 'ml' + t.uuid 'skill1_id' + t.uuid 'skill2_id' + t.uuid 'skill3_id' + t.uuid 'skill0_id' + t.boolean 'full_auto', default: false, null: false + t.boolean 'auto_guard', default: false, null: false + t.boolean 'charge_attack', default: true, null: false + t.integer 'clear_time', default: 0, null: false + t.integer 'button_count' + t.integer 'chain_count' + t.integer 'turn_count' + t.uuid 'source_party_id' + t.index ['job_id'], name: 'index_parties_on_job_id' + t.index ['skill0_id'], name: 'index_parties_on_skill0_id' + t.index ['skill1_id'], name: 'index_parties_on_skill1_id' + t.index ['skill2_id'], name: 'index_parties_on_skill2_id' + t.index ['skill3_id'], name: 'index_parties_on_skill3_id' + t.index ['source_party_id'], name: 'index_parties_on_source_party_id' + t.index ['user_id'], name: 'index_parties_on_user_id' end - create_table "raids", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.string "name_en" - t.string "name_jp" - t.integer "level" - t.integer "group" - t.integer "element" - t.string "slug" + create_table 'raids', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.string 'name_en' + t.string 'name_jp' + t.integer 'level' + t.integer 'group' + t.integer 'element' + t.string 'slug' end - create_table "summons", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.string "name_en" - t.string "name_jp" - t.string "granblue_id" - t.integer "rarity" - t.integer "element" - t.string "series" - t.boolean "flb", default: false, null: false - t.boolean "ulb", default: false, null: false - t.integer "max_level", default: 100, null: false - t.integer "min_hp" - t.integer "max_hp" - t.integer "max_hp_flb" - t.integer "max_hp_ulb" - t.integer "min_atk" - t.integer "max_atk" - t.integer "max_atk_flb" - t.integer "max_atk_ulb" - t.boolean "subaura", default: false, null: false - t.boolean "limit", default: false, null: false - t.boolean "xlb", default: false, null: false - t.index ["name_en"], name: "index_summons_on_name_en", opclass: :gin_trgm_ops, using: :gin + create_table 'summons', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.string 'name_en' + t.string 'name_jp' + t.string 'granblue_id' + t.integer 'rarity' + t.integer 'element' + t.string 'series' + t.boolean 'flb', default: false, null: false + t.boolean 'ulb', default: false, null: false + t.integer 'max_level', default: 100, null: false + t.integer 'min_hp' + t.integer 'max_hp' + t.integer 'max_hp_flb' + t.integer 'max_hp_ulb' + t.integer 'min_atk' + t.integer 'max_atk' + t.integer 'max_atk_flb' + t.integer 'max_atk_ulb' + t.boolean 'subaura', default: false, null: false + t.boolean 'limit', default: false, null: false + t.boolean 'xlb', default: false, null: false + t.index ['name_en'], name: 'index_summons_on_name_en', opclass: :gin_trgm_ops, using: :gin end - create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.string "email" - t.string "password_digest" - t.string "username" - t.integer "granblue_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "picture", default: "gran" - t.string "language", default: "en", null: false - t.boolean "private", default: false, null: false - t.string "element", default: "water", null: false - t.integer "gender", default: 0, null: false - t.string "theme", default: "system", null: false + create_table 'users', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.string 'email' + t.string 'password_digest' + t.string 'username' + t.integer 'granblue_id' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.string 'picture', default: 'gran' + t.string 'language', default: 'en', null: false + t.boolean 'private', default: false, null: false + t.string 'element', default: 'water', null: false + t.integer 'gender', default: 0, null: false + t.string 'theme', default: 'system', null: false end - create_table "weapon_keys", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.string "name_en" - t.string "name_jp" - t.integer "series" - t.integer "slot" - t.integer "group" - t.integer "order" - t.string "slug" + create_table 'weapon_keys', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.string 'name_en' + t.string 'name_jp' + t.integer 'series' + t.integer 'slot' + t.integer 'group' + t.integer 'order' + t.string 'slug' end - create_table "weapons", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.string "name_en" - t.string "name_jp" - t.string "granblue_id" - t.integer "rarity" - t.integer "element" - t.integer "proficiency" - t.integer "series", default: -1, null: false - t.boolean "flb", default: false, null: false - t.boolean "ulb", default: false, null: false - t.integer "max_level", default: 100, null: false - t.integer "max_skill_level", default: 10, null: false - t.integer "min_hp" - t.integer "max_hp" - t.integer "max_hp_flb" - t.integer "max_hp_ulb" - t.integer "min_atk" - t.integer "max_atk" - t.integer "max_atk_flb" - t.integer "max_atk_ulb" - t.boolean "extra", default: false, null: false - t.integer "ax_type" - t.boolean "awakening", default: true, null: false - t.boolean "limit", default: false, null: false - t.boolean "ax", default: false, null: false - t.index ["name_en"], name: "index_weapons_on_name_en", opclass: :gin_trgm_ops, using: :gin + create_table 'weapons', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| + t.string 'name_en' + t.string 'name_jp' + t.string 'granblue_id' + t.integer 'rarity' + t.integer 'element' + t.integer 'proficiency' + t.integer 'series', default: -1, null: false + t.boolean 'flb', default: false, null: false + t.boolean 'ulb', default: false, null: false + t.integer 'max_level', default: 100, null: false + t.integer 'max_skill_level', default: 10, null: false + t.integer 'min_hp' + t.integer 'max_hp' + t.integer 'max_hp_flb' + t.integer 'max_hp_ulb' + t.integer 'min_atk' + t.integer 'max_atk' + t.integer 'max_atk_flb' + t.integer 'max_atk_ulb' + t.boolean 'extra', default: false, null: false + t.integer 'ax_type' + t.boolean 'awakening', default: true, null: false + t.boolean 'limit', default: false, null: false + t.boolean 'ax', default: false, null: false + t.index ['name_en'], name: 'index_weapons_on_name_en', opclass: :gin_trgm_ops, using: :gin end - add_foreign_key "favorites", "parties" - add_foreign_key "favorites", "users" - add_foreign_key "grid_characters", "characters" - add_foreign_key "grid_characters", "parties" - add_foreign_key "grid_summons", "parties" - add_foreign_key "grid_summons", "summons" - add_foreign_key "grid_weapons", "parties" - add_foreign_key "grid_weapons", "weapon_keys", column: "weapon_key3_id" - add_foreign_key "grid_weapons", "weapons" - add_foreign_key "jobs", "jobs", column: "base_job_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 "parties", "job_skills", column: "skill0_id" - add_foreign_key "parties", "job_skills", column: "skill1_id" - add_foreign_key "parties", "job_skills", column: "skill2_id" - add_foreign_key "parties", "job_skills", column: "skill3_id" - add_foreign_key "parties", "jobs" - add_foreign_key "parties", "raids" - add_foreign_key "parties", "users" + add_foreign_key 'favorites', 'parties' + add_foreign_key 'favorites', 'users' + add_foreign_key 'grid_characters', 'characters' + add_foreign_key 'grid_characters', 'parties' + add_foreign_key 'grid_summons', 'parties' + add_foreign_key 'grid_summons', 'summons' + add_foreign_key 'grid_weapons', 'parties' + add_foreign_key 'grid_weapons', 'weapon_keys', column: 'weapon_key3_id' + add_foreign_key 'grid_weapons', 'weapons' + add_foreign_key 'jobs', 'jobs', column: 'base_job_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 'parties', 'job_skills', column: 'skill0_id' + add_foreign_key 'parties', 'job_skills', column: 'skill1_id' + add_foreign_key 'parties', 'job_skills', column: 'skill2_id' + add_foreign_key 'parties', 'job_skills', column: 'skill3_id' + add_foreign_key 'parties', 'jobs' + add_foreign_key 'parties', 'parties', column: 'source_party_id' + add_foreign_key 'parties', 'raids' + add_foreign_key 'parties', 'users' end From 2a465aca3ba5bc0be458c792e8e775a4e1e30c84 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 8 Jan 2023 20:13:09 -0800 Subject: [PATCH 11/86] Move shortcode setting to before_save on Party model --- app/controllers/api/v1/parties_controller.rb | 13 +------------ app/models/party.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index ff4ea0b..f5171d8 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -8,12 +8,7 @@ module Api before_action :set, only: %w[update destroy] def create - party = Party.new(shortcode: random_string) - party.user = current_user if current_user - - if party_params - party.attributes = party_params - end + party = Party.new(party_params.merge(user: current_user)) # unless party_params.empty? # party.attributes = party_params @@ -125,12 +120,6 @@ module Api end end - def random_string - num_chars = 6 - o = [('a'..'z'), ('A'..'Z'), (0..9)].map(&:to_a).flatten - (0...num_chars).map { o[rand(o.length)] }.join - end - def set_from_slug @party = Party.where('shortcode = ?', params[:id]).first @party.favorited = current_user && @party ? @party.is_favorited(current_user) : false diff --git a/app/models/party.rb b/app/models/party.rb index e9840ff..b8066d0 100644 --- a/app/models/party.rb +++ b/app/models/party.rb @@ -43,6 +43,7 @@ class Party < ApplicationRecord has_many :favorites + before_save :set_shortcode ##### ActiveRecord Validations validate :skills_are_unique @@ -58,6 +59,16 @@ class Party < ApplicationRecord private + def set_shortcode + self.shortcode = random_string + end + + def random_string + num_chars = 6 + o = [('a'..'z'), ('A'..'Z'), (0..9)].map(&:to_a).flatten + (0...num_chars).map { o[rand(o.length)] }.join + end + def skills_are_unique skills = [skill0, skill1, skill2, skill3].compact From 433bd19f6de8cce3b18b4ccc163a18ed8a281486 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 8 Jan 2023 21:45:31 -0800 Subject: [PATCH 12/86] Fix party creation --- app/controllers/api/v1/parties_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index f5171d8..cb03cc9 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -8,7 +8,9 @@ module Api before_action :set, only: %w[update destroy] def create - party = Party.new(party_params.merge(user: current_user)) + party = Party.new + party.user = current_user if current_user + party.attributes = party_params if party_params # unless party_params.empty? # party.attributes = party_params From b0b446aba37b616ecedb9d2450c9b8f629036440 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 8 Jan 2023 21:46:16 -0800 Subject: [PATCH 13/86] Fix set_from_slug --- app/controllers/api/v1/parties_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index cb03cc9..9ac5de4 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -124,7 +124,11 @@ module Api def set_from_slug @party = Party.where('shortcode = ?', params[:id]).first - @party.favorited = current_user && @party ? @party.is_favorited(current_user) : false + if @party + @party.favorited = current_user && @party ? @party.is_favorited(current_user) : false + else + render_not_found_response('party') + end end def set From 1925678888fff15847f1fdd9dec8729bde28a5e5 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 8 Jan 2023 21:46:32 -0800 Subject: [PATCH 14/86] Return when no params --- app/controllers/api/v1/parties_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index 9ac5de4..5db36d6 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -136,6 +136,8 @@ module Api end def party_params + return unless params[:party].present? + params.require(:party).permit( :user_id, :extra, @@ -154,7 +156,7 @@ module Api :button_count, :turn_count, :chain_count - ) if params[:party].present? + ) end end end From a3e76d53e7f76c05b6678c55dab8274c30e1f3d9 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 8 Jan 2023 21:48:10 -0800 Subject: [PATCH 15/86] Add amoeba configuration to Party --- app/models/party.rb | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/app/models/party.rb b/app/models/party.rb index b8066d0..40330d8 100644 --- a/app/models/party.rb +++ b/app/models/party.rb @@ -2,6 +2,16 @@ class Party < ApplicationRecord ##### ActiveRecord Associations + belongs_to :source_party, + class_name: 'Party', + foreign_key: :source_party_id, + optional: true + + has_many :derivative_parties, + class_name: 'Party', + foreign_key: :source_party_id, + inverse_of: :source_party + belongs_to :user, optional: true belongs_to :raid, optional: true belongs_to :job, optional: true @@ -29,21 +39,37 @@ class Party < ApplicationRecord has_many :characters, foreign_key: 'party_id', class_name: 'GridCharacter', - dependent: :destroy + dependent: :destroy, + inverse_of: :party has_many :weapons, foreign_key: 'party_id', class_name: 'GridWeapon', - dependent: :destroy + dependent: :destroy, + inverse_of: :party has_many :summons, foreign_key: 'party_id', class_name: 'GridSummon', - dependent: :destroy + dependent: :destroy, + inverse_of: :party has_many :favorites - before_save :set_shortcode + before_create :set_shortcode + + ##### Amoeba configuration + amoeba do + enable + + nullify :description + nullify :shortcode + + include_association :characters + include_association :weapons + include_association :summons + end + ##### ActiveRecord Validations validate :skills_are_unique From fa2962ae1cc8b396d65f01467ba74af68570db9d Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 8 Jan 2023 21:48:36 -0800 Subject: [PATCH 16/86] Add remix method to parties controller --- app/controllers/api/v1/parties_controller.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index 5db36d6..ced5028 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -55,6 +55,19 @@ module Api end def remix + new_party = @party.amoeba_dup + new_party.attributes = { + user: current_user, + + source_party: @party + } + + if new_party.save + render json: PartyBlueprint.render(new_party, view: :full, root: :party, + meta: { remix: true }) + else + render_validation_error_response(new_party) + end end def index @@ -111,7 +124,7 @@ module Api def build_conditions(params) unless params['recency'].blank? start_time = (DateTime.current - params['recency'].to_i.seconds) - .to_datetime.beginning_of_day + .to_datetime.beginning_of_day end {}.tap do |hash| From b6e8dd93b1d6f5a6df62c6125e5bf8c61a4eb985 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 8 Jan 2023 21:49:25 -0800 Subject: [PATCH 17/86] Add party validation and inverse to GridObject associations --- app/models/grid_character.rb | 5 ++++- app/models/grid_summon.rb | 5 ++++- app/models/grid_weapon.rb | 6 +++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/models/grid_character.rb b/app/models/grid_character.rb index e60bcf9..b6bb12e 100644 --- a/app/models/grid_character.rb +++ b/app/models/grid_character.rb @@ -1,7 +1,10 @@ # frozen_string_literal: true class GridCharacter < ApplicationRecord - belongs_to :party + belongs_to :party, + counter_cache: :weapons_count, + inverse_of: :characters + validates_presence_of :party validate :awakening_level, on: :update validate :transcendence, on: :update diff --git a/app/models/grid_summon.rb b/app/models/grid_summon.rb index 9857a9b..565a708 100644 --- a/app/models/grid_summon.rb +++ b/app/models/grid_summon.rb @@ -1,7 +1,10 @@ # frozen_string_literal: true class GridSummon < ApplicationRecord - belongs_to :party + belongs_to :party, + counter_cache: :weapons_count, + inverse_of: :summons + validates_presence_of :party def summon Summon.find(summon_id) diff --git a/app/models/grid_weapon.rb b/app/models/grid_weapon.rb index 98c35cc..72d93cc 100644 --- a/app/models/grid_weapon.rb +++ b/app/models/grid_weapon.rb @@ -2,7 +2,9 @@ class GridWeapon < ApplicationRecord belongs_to :party, - counter_cache: :weapons_count + counter_cache: :weapons_count, + inverse_of: :weapons + validates_presence_of :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 @@ -29,6 +31,8 @@ class GridWeapon < ApplicationRecord return unless weapon.limit party.weapons.find do |party_weapon| + return unless party_weapon.id + id_match = weapon.id == party_weapon.id series_match = weapon.series == party_weapon.weapon.series both_opus_or_draconic = weapon.opus_or_draconic? && party_weapon.weapon.opus_or_draconic? From 79b9b4e22563bf68393c19e47376b7cac14c28c4 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 9 Jan 2023 00:05:18 -0800 Subject: [PATCH 18/86] Exclude certain values from remixing --- app/models/grid_character.rb | 36 ++++++++++++++++++++++++------------ app/models/grid_weapon.rb | 8 ++++++++ app/models/party.rb | 2 -- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/app/models/grid_character.rb b/app/models/grid_character.rb index b6bb12e..0e03291 100644 --- a/app/models/grid_character.rb +++ b/app/models/grid_character.rb @@ -12,34 +12,46 @@ class GridCharacter < ApplicationRecord validate :over_mastery_hp, on: :update validate :over_mastery_attack_matches_hp, on: :update + ##### Amoeba configuration + amoeba do + nullify :ring1 + nullify :ring2 + nullify :ring3 + nullify :ring4 + nullify :earring + nullify :perpetuity + end + def awakening_level - unless awakening.nil? - errors.add(:awakening, 'awakening level too low') if awakening["level"] < 1 - errors.add(:awakening, 'awakening level too high') if awakening["level"] > 9 - end + return if awakening.nil? + + errors.add(:awakening, 'awakening level too low') if awakening['level'] < 1 + errors.add(:awakening, 'awakening level too high') if awakening['level'] > 9 end def transcendence errors.add(:transcendence_step, 'character has no transcendence') if transcendence_step > 0 && !character.ulb errors.add(:transcendence_step, 'transcendence step too high') if transcendence_step > 5 && character.ulb errors.add(:transcendence_step, 'transcendence step too low') if transcendence_step < 0 && character.ulb - end def over_mastery_attack - errors.add(:ring1, 'invalid value') unless ring1["modifier"].nil? || atk_values.include?(ring1["strength"]) + errors.add(:ring1, 'invalid value') unless ring1['modifier'].nil? || atk_values.include?(ring1['strength']) end def over_mastery_hp - unless ring2["modifier"].nil? - errors.add(:ring2, 'invalid value') unless hp_values.include?(ring2["strength"]) - end + return if ring2['modifier'].nil? + + errors.add(:ring2, 'invalid value') unless hp_values.include?(ring2['strength']) end def over_mastery_attack_matches_hp - unless ring1[:modifier].nil? && ring2[:modifier].nil? - errors.add(:over_mastery, 'over mastery attack and hp values do not match') unless ring2[:strength] == (ring1[:strength] / 2) - end + return if ring1[:modifier].nil? && ring2[:modifier].nil? + + return if ring2[:strength] == (ring1[:strength] / 2) + + errors.add(:over_mastery, + 'over mastery attack and hp values do not match') end def character diff --git a/app/models/grid_weapon.rb b/app/models/grid_weapon.rb index 72d93cc..1048290 100644 --- a/app/models/grid_weapon.rb +++ b/app/models/grid_weapon.rb @@ -13,6 +13,14 @@ class GridWeapon < ApplicationRecord validate :compatible_with_position, on: :create validate :no_conflicts, on: :create + ##### Amoeba configuration + amoeba do + nullify :ax_modifier1 + nullify :ax_modifier2 + nullify :ax_strength1 + nullify :ax_strength2 + end + # Helper methods def blueprint GridWeaponBlueprint diff --git a/app/models/party.rb b/app/models/party.rb index 40330d8..87dd9d4 100644 --- a/app/models/party.rb +++ b/app/models/party.rb @@ -60,8 +60,6 @@ class Party < ApplicationRecord ##### Amoeba configuration amoeba do - enable - nullify :description nullify :shortcode From f73593d8e12c3554a01bd0c8647561a92dae5824 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 9 Jan 2023 00:29:01 -0800 Subject: [PATCH 19/86] Blank values using defaults instead of null --- app/models/grid_character.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/grid_character.rb b/app/models/grid_character.rb index 0e03291..b3f7f38 100644 --- a/app/models/grid_character.rb +++ b/app/models/grid_character.rb @@ -14,12 +14,12 @@ class GridCharacter < ApplicationRecord ##### Amoeba configuration amoeba do - nullify :ring1 - nullify :ring2 - nullify :ring3 - nullify :ring4 - nullify :earring - nullify :perpetuity + set ring1: { modifier: nil, strength: nil } + set ring2: { modifier: nil, strength: nil } + set ring3: { modifier: nil, strength: nil } + set ring4: { modifier: nil, strength: nil } + set earring: { modifier: nil, strength: nil } + set perpetuity: false end def awakening_level From 18ca78a272e4be630b5829dc9351e3bdaf789800 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 9 Jan 2023 00:29:12 -0800 Subject: [PATCH 20/86] Implement localized remix names --- app/controllers/api/v1/parties_controller.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index ced5028..81578b5 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -58,7 +58,7 @@ module Api new_party = @party.amoeba_dup new_party.attributes = { user: current_user, - + name: remixed_name(@party.name), source_party: @party } @@ -135,6 +135,24 @@ module Api end end + def remixed_name(name) + blanked_name = { + en: name.blank? ? 'Untitled team' : name, + ja: name.blank? ? '無名の編成' : name + } + + if current_user + case current_user.language + when 'en' + "Remix of #{blanked_name[:en]}" + when 'ja' + "#{blanked_name[:ja]}のリミックス" + end + else + "Remix of #{blanked_name[:en]}" + end + end + def set_from_slug @party = Party.where('shortcode = ?', params[:id]).first if @party From 73022778f67b138e7b35377531d5a284a9832034 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 9 Jan 2023 01:51:38 -0800 Subject: [PATCH 21/86] Add server-side validation for OM and AM rings Note: Over mastery is not validating properly yet --- app/models/grid_character.rb | 168 +++++++++++++++++++++++++++++++---- 1 file changed, 153 insertions(+), 15 deletions(-) diff --git a/app/models/grid_character.rb b/app/models/grid_character.rb index e60bcf9..ac8faea 100644 --- a/app/models/grid_character.rb +++ b/app/models/grid_character.rb @@ -5,40 +5,60 @@ class GridCharacter < ApplicationRecord validate :awakening_level, on: :update validate :transcendence, on: :update - validate :over_mastery_attack, on: :update - validate :over_mastery_hp, on: :update + validate :validate_over_mastery_values, on: :update + validate :validate_aetherial_mastery_value, on: :update validate :over_mastery_attack_matches_hp, on: :update def awakening_level - unless awakening.nil? - errors.add(:awakening, 'awakening level too low') if awakening["level"] < 1 - errors.add(:awakening, 'awakening level too high') if awakening["level"] > 9 - end + return if awakening.nil? + + errors.add(:awakening, 'awakening level too low') if awakening['level'] < 1 + errors.add(:awakening, 'awakening level too high') if awakening['level'] > 9 end def transcendence - errors.add(:transcendence_step, 'character has no transcendence') if transcendence_step > 0 && !character.ulb + errors.add(:transcendence_step, 'character has no transcendence') if transcendence_step.positive? && !character.ulb errors.add(:transcendence_step, 'transcendence step too high') if transcendence_step > 5 && character.ulb - errors.add(:transcendence_step, 'transcendence step too low') if transcendence_step < 0 && character.ulb - + errors.add(:transcendence_step, 'transcendence step too low') if transcendence_step.negative? && character.ulb end def over_mastery_attack - errors.add(:ring1, 'invalid value') unless ring1["modifier"].nil? || atk_values.include?(ring1["strength"]) + errors.add(:ring1, 'invalid value') unless ring1['modifier'].nil? || atk_values.include?(ring1['strength']) end def over_mastery_hp - unless ring2["modifier"].nil? - errors.add(:ring2, 'invalid value') unless hp_values.include?(ring2["strength"]) - end + return if ring2['modifier'].nil? + + errors.add(:ring2, 'invalid value') unless hp_values.include?(ring2['strength']) end def over_mastery_attack_matches_hp - unless ring1[:modifier].nil? && ring2[:modifier].nil? - errors.add(:over_mastery, 'over mastery attack and hp values do not match') unless ring2[:strength] == (ring1[:strength] / 2) + return if ring1[:modifier].nil? && ring2[:modifier].nil? + + return if ring2[:strength] == (ring1[:strength] / 2) + + errors.add(:over_mastery, + 'over mastery attack and hp values do not match') + end + + def validate_over_mastery_values + [ring1, ring2, ring3, ring4].each_with_index do |ring, index| + next if ring['modifier'].nil? + + modifier = over_mastery_modifiers[ring['modifier']] + check_value({ "ring#{index}": { ring[modifier] => ring['strength'] } }, + 'over_mastery') end end + def validate_aetherial_mastery_value + return if earring['modifier'].nil? + + modifier = aetherial_mastery_modifiers[earring['modifier']].to_sym + check_value({ "earring": { modifier => earring['strength'] } }, + 'aetherial_mastery') + end + def character Character.find(character_id) end @@ -49,6 +69,124 @@ class GridCharacter < ApplicationRecord private + def check_value(property, type) + # Input format + # { ring1: { atk: 300 } } + + key = property.keys.first + modifier = property[key].keys.first + + return if modifier.nil? + + case type + when 'over_mastery' + errors.add(key, 'invalid value') unless over_mastery_values.include?(key['strength']) + when 'aetherial_mastery' + errors.add(key, 'value too low') if aetherial_mastery_values[modifier][:min] > self[key]['strength'] + errors.add(key, 'value too high') if aetherial_mastery_values[modifier][:max] < self[key]['strength'] + end + end + + def over_mastery_modifiers + { + 1 => 'atk', + 2 => 'hp', + 3 => 'debuff_success', + 4 => 'skill_cap', + 5 => 'ca_dmg', + 6 => 'ca_cap', + 7 => 'stamina', + 8 => 'enmity', + 9 => 'crit', + 10 => 'da', + 11 => 'ta', + 12 => 'def', + 13 => 'heal', + 14 => 'debuff_resist', + 15 => 'dodge' + } + end + + def over_mastery_values + { + atk: [300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000], + hp: [150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500], + debuff_success: [6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + skill_cap: [6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + ca_dmg: [10, 12, 14, 16, 18, 20, 22, 24, 27, 30], + ca_cap: [6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + crit: [10, 12, 14, 16, 18, 20, 22, 24, 27, 30], + enmity: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], + stamina: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], + def: [6, 7, 8, 9, 10, 12, 14, 16, 18, 20], + heal: [3, 6, 9, 12, 15, 18, 21, 24, 27, 30], + debuff_resist: [6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + dodge: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], + da: [6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + ta: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + } + end + + def aetherial_mastery_modifiers + { + 1 => 'da', + 2 => 'ta', + 3 => 'ele_atk', + 4 => 'ele_resist', + 5 => 'stamina', + 6 => 'enmity', + 7 => 'supplemental', + 8 => 'crit', + 9 => 'counter_dodge', + 10 => 'counter_dmg' + } + end + + def aetherial_mastery_values + { + da: { + min: 10, + max: 17 + }, + ta: { + min: 5, + max: 12 + }, + ele_atk: { + min: 15, + max: 22 + }, + ele_resist: { + min: 5, + max: 12 + }, + stamina: { + min: 5, + max: 12 + }, + enmity: { + min: 5, + max: 12 + }, + supplemental: { + min: 5, + max: 12 + }, + crit: { + min: 18, + max: 35 + }, + counter_dodge: { + min: 5, + max: 12 + }, + counter_dmg: { + min: 10, + max: 17 + } + } + end + def atk_values [300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000] end From 633db43e949078d22a16490463b4e4765282e964 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 20 Jan 2023 21:39:20 -0800 Subject: [PATCH 22/86] Implement removing characters and weapons --- .../api/v1/grid_character_blueprint.rb | 27 +++++++++---------- .../api/v1/grid_weapon_blueprint.rb | 4 +++ .../api/v1/grid_characters_controller.rb | 21 +++++++++------ .../api/v1/grid_weapons_controller.rb | 17 +++++++----- app/models/grid_character.rb | 2 ++ config/routes.rb | 4 +-- 6 files changed, 44 insertions(+), 31 deletions(-) diff --git a/app/blueprints/api/v1/grid_character_blueprint.rb b/app/blueprints/api/v1/grid_character_blueprint.rb index 4ef5e97..4ecf072 100644 --- a/app/blueprints/api/v1/grid_character_blueprint.rb +++ b/app/blueprints/api/v1/grid_character_blueprint.rb @@ -11,35 +11,30 @@ module Api view :nested do fields :position, :uncap_level, :perpetuity - field :transcendence_step, if: ->(_fn, obj, _opt) { + field :transcendence_step, if: lambda { |_fn, obj, _opt| obj.character.ulb } do |c| c.transcendence_step end - field :awakening, if: ->(_fn, obj, _opt) { - !obj[:awakening].nil? - } do |c| - { - type: c.awakening[:type], - level: c.awakening[:level] - } + field :awakening do |c| + c.awakening end - field :over_mastery, if: ->(_fn, obj, _opt) { + field :over_mastery, if: lambda { |_fn, obj, _opt| !obj.ring1['modifier'].nil? && !obj.ring2['modifier'].nil? } do |c| rings = [] - rings.push(c.ring1) if !c.ring1['modifier'].nil? - rings.push(c.ring2) if !c.ring2['modifier'].nil? - rings.push(c.ring3) if !c.ring3['modifier'].nil? - rings.push(c.ring4) if !c.ring4['modifier'].nil? + rings.push(c.ring1) unless c.ring1['modifier'].nil? + rings.push(c.ring2) unless c.ring2['modifier'].nil? + rings.push(c.ring3) unless c.ring3['modifier'].nil? + rings.push(c.ring4) unless c.ring4['modifier'].nil? rings end - field :aetherial_mastery, if: ->(_fn, obj, _opt) { + field :aetherial_mastery, if: lambda { |_fn, obj, _opt| !obj.earring['modifier'].nil? } do |c| c.earring @@ -52,6 +47,10 @@ module Api include_view :nested association :party, blueprint: PartyBlueprint, view: :minimal end + + view :destroyed do + fields :position, :created_at, :updated_at + end end end end diff --git a/app/blueprints/api/v1/grid_weapon_blueprint.rb b/app/blueprints/api/v1/grid_weapon_blueprint.rb index a2ff815..3e409e8 100644 --- a/app/blueprints/api/v1/grid_weapon_blueprint.rb +++ b/app/blueprints/api/v1/grid_weapon_blueprint.rb @@ -43,6 +43,10 @@ module Api include_view :nested association :party, blueprint: PartyBlueprint, view: :minimal end + + view :destroyed do + fields :mainhand, :position, :created_at, :updated_at + end end end end diff --git a/app/controllers/api/v1/grid_characters_controller.rb b/app/controllers/api/v1/grid_characters_controller.rb index 347ef93..23d9381 100644 --- a/app/controllers/api/v1/grid_characters_controller.rb +++ b/app/controllers/api/v1/grid_characters_controller.rb @@ -6,8 +6,8 @@ module Api attr_reader :party, :incoming_character, :current_characters before_action :find_party, only: :create - before_action :set, only: [:update, :destroy] - before_action :check_authorization, only: [:update, :destroy] + before_action :set, only: %i[update destroy] + before_action :check_authorization, only: %i[update destroy] before_action :find_incoming_character, only: :create before_action :find_current_characters, only: :create @@ -41,7 +41,7 @@ module Api def update 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] mastery[key] = value unless value.nil? end @@ -49,8 +49,10 @@ module Api @character.attributes = character_params.merge(mastery) if @character.save + ap 'Saved character' return render json: GridCharacterBlueprint.render(@character, view: :full) if @character.save else + ap 'Could not save' render_validation_error_response(@character) end end @@ -94,7 +96,10 @@ module Api end # 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 @@ -122,7 +127,7 @@ module Api end def set - @character = GridCharacter.find(character_params[:id]) + @character = GridCharacter.find(params[:id]) end def find_incoming_character @@ -142,9 +147,9 @@ module Api def character_params params.require(:character).permit(:id, :party_id, :character_id, :position, :uncap_level, :transcendence_step, :perpetuity, - :ring1 => [:modifier, :strength], :ring2 => [:modifier, :strength], - :ring3 => [:modifier, :strength], :ring4 => [:modifier, :strength], - :earring => [:modifier, :strength], :awakening => [:type, :level]) + ring1: %i[modifier strength], ring2: %i[modifier strength], + ring3: %i[modifier strength], ring4: %i[modifier strength], + earring: %i[modifier strength], awakening: %i[type level]) end def resolve_params diff --git a/app/controllers/api/v1/grid_weapons_controller.rb b/app/controllers/api/v1/grid_weapons_controller.rb index 94c9563..7282161 100644 --- a/app/controllers/api/v1/grid_weapons_controller.rb +++ b/app/controllers/api/v1/grid_weapons_controller.rb @@ -3,7 +3,7 @@ module Api module V1 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 @@ -56,7 +56,10 @@ module Api end # 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 weapon = GridWeapon.find(weapon_params[:id]) @@ -115,15 +118,15 @@ module Api # Render the conflict view as a string def render_conflict_view(conflict_weapon, incoming_weapon, incoming_position) ConflictBlueprint.render(nil, view: :weapons, - conflict_weapon: conflict_weapon, - incoming_weapon: incoming_weapon, - incoming_position: incoming_position) + conflict_weapon: conflict_weapon, + incoming_weapon: incoming_weapon, + incoming_position: incoming_position) end def render_grid_weapon_view(grid_weapon, conflict_position) GridWeaponBlueprint.render(grid_weapon, view: :full, - root: :grid_weapon, - meta: { replaced: conflict_position }) + root: :grid_weapon, + meta: { replaced: conflict_position }) end def save_weapon(weapon) diff --git a/app/models/grid_character.rb b/app/models/grid_character.rb index ac8faea..db4a3b3 100644 --- a/app/models/grid_character.rb +++ b/app/models/grid_character.rb @@ -54,6 +54,8 @@ class GridCharacter < ApplicationRecord def validate_aetherial_mastery_value return if earring['modifier'].nil? + return unless earring['modifier'].positive? + modifier = aetherial_mastery_modifiers[earring['modifier']].to_sym check_value({ "earring": { modifier => earring['strength'] } }, 'aetherial_mastery') diff --git a/config/routes.rb b/config/routes.rb index 8256840..38775d6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,8 +8,8 @@ Rails.application.routes.draw do namespace :v1 do resources :parties, only: %i[index create update destroy] resources :users, only: %i[create update show] - resources :grid_weapons, only: [:update] - resources :grid_characters, only: [:update] + resources :grid_weapons, only: %i[update destroy] + resources :grid_characters, only: %i[update destroy] resources :favorites, only: [:create] get 'users/info/:id', to: 'users#info' From c5f2c9d0805286272e1c93501a10866180b2903b Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 21 Jan 2023 15:41:16 -0800 Subject: [PATCH 23/86] Implement deleting summons --- app/blueprints/api/v1/grid_summon_blueprint.rb | 4 ++++ app/controllers/api/v1/grid_summons_controller.rb | 12 ++++++++++-- app/controllers/api/v1/grid_weapons_controller.rb | 1 - config/routes.rb | 1 + 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/blueprints/api/v1/grid_summon_blueprint.rb b/app/blueprints/api/v1/grid_summon_blueprint.rb index af2cec6..1a27594 100644 --- a/app/blueprints/api/v1/grid_summon_blueprint.rb +++ b/app/blueprints/api/v1/grid_summon_blueprint.rb @@ -17,6 +17,10 @@ module Api include_view :nested association :party, blueprint: PartyBlueprint, view: :minimal end + + view :destroyed do + fields :main, :friend, :position, :created_at, :updated_at + end end end end diff --git a/app/controllers/api/v1/grid_summons_controller.rb b/app/controllers/api/v1/grid_summons_controller.rb index cf9ea7d..6fbc3f1 100644 --- a/app/controllers/api/v1/grid_summons_controller.rb +++ b/app/controllers/api/v1/grid_summons_controller.rb @@ -3,6 +3,8 @@ module Api module V1 class GridSummonsController < Api::V1::ApiController + before_action :set, only: %w[destroy] + def create party = Party.find(summon_params[:party_id]) canonical_summon = Summon.find(summon_params[:summon_id]) @@ -31,11 +33,17 @@ module Api render json: GridSummonBlueprint.render(summon, view: :nested, root: :grid_summon) end - # TODO: Implement removing summons - def destroy; end + def destroy + render_unauthorized_response if @summon.party.user != current_user + return render json: GridSummonBlueprint.render(@summon, view: :destroyed) if @summon.destroy + end private + def set + @summon = GridSummon.where('id = ?', 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) diff --git a/app/controllers/api/v1/grid_weapons_controller.rb b/app/controllers/api/v1/grid_weapons_controller.rb index 7282161..652fdbc 100644 --- a/app/controllers/api/v1/grid_weapons_controller.rb +++ b/app/controllers/api/v1/grid_weapons_controller.rb @@ -55,7 +55,6 @@ module Api render json: GridWeaponBlueprint.render(@weapon, view: :nested) if @weapon.update(weapon_params) end - # TODO: Implement removing characters def destroy render_unauthorized_response if @weapon.party.user != current_user return render json: GridCharacterBlueprint.render(@weapon, view: :destroyed) if @weapon.destroy diff --git a/config/routes.rb b/config/routes.rb index 38775d6..e9a6b9f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,6 +10,7 @@ Rails.application.routes.draw do resources :users, only: %i[create update show] resources :grid_weapons, only: %i[update destroy] resources :grid_characters, only: %i[update destroy] + resources :grid_summons, only: %i[destroy] resources :favorites, only: [:create] get 'users/info/:id', to: 'users#info' From 67cc1138e6e2d96ad0b93be50f866c8ca5156ae7 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 21 Jan 2023 18:44:25 -0800 Subject: [PATCH 24/86] Implements limits on GridSummons --- .../api/v1/grid_summons_controller.rb | 55 +++++++++++++++++-- app/models/grid_summon.rb | 35 ++++++++++++ 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/grid_summons_controller.rb b/app/controllers/api/v1/grid_summons_controller.rb index 6fbc3f1..2a40033 100644 --- a/app/controllers/api/v1/grid_summons_controller.rb +++ b/app/controllers/api/v1/grid_summons_controller.rb @@ -5,12 +5,26 @@ module Api class GridSummonsController < Api::V1::ApiController before_action :set, only: %w[destroy] + attr_reader :party, :incoming_summon + + before_action :find_party, only: :create + before_action :find_incoming_summon, only: :create + def create - party = Party.find(summon_params[:party_id]) - canonical_summon = Summon.find(summon_params[:summon_id]) + # Create the GridSummon with the desired parameters + summon = GridSummon.new + summon.attributes = summon_params.merge(party_id: party.id, summon_id: incoming_summon.id) - render_unauthorized_response if current_user && (party.user != current_user) + if summon.validate + ap 'Validating' + save_summon(summon) + else + ap 'Handling conflict' + handle_conflict(summon) + end + end + def save_summon(summon) if (grid_summon = GridSummon.where( party_id: party.id, position: summon_params[:position] @@ -18,8 +32,23 @@ module Api GridSummon.destroy(grid_summon.id) end - summon = GridSummon.create!(summon_params.merge(party_id: party.id, summon_id: canonical_summon.id)) - render json: GridSummonBlueprint.render(summon, view: :nested), status: :created if summon.save! + return unless summon.save + + output = render_grid_summon_view(summon) + render json: output, status: :created + end + + def handle_conflict(summon) + conflict_summon = summon.conflicts(party) + return unless conflict_summon.summon.id == incoming_summon.id + + old_position = conflict_summon.position + conflict_summon.position = summon_params[:position] + + return unless conflict_summon.save + + output = render_grid_summon_view(conflict_summon, old_position) + render json: output end def update_uncap_level @@ -40,6 +69,22 @@ module Api private + def find_incoming_summon + @incoming_summon = Summon.find_by(id: summon_params[:summon_id]) + end + + def find_party + # BUG: I can create grid weapons even when I'm not logged in on an authenticated party + @party = Party.find(summon_params[:party_id]) + render_unauthorized_response if current_user && (party.user != current_user) + end + + def render_grid_summon_view(grid_summon, conflict_position = nil) + GridSummonBlueprint.render(grid_summon, view: :nested, + root: :grid_summon, + meta: { replaced: conflict_position }) + end + def set @summon = GridSummon.where('id = ?', params[:id]).first end diff --git a/app/models/grid_summon.rb b/app/models/grid_summon.rb index 9857a9b..aa65f3c 100644 --- a/app/models/grid_summon.rb +++ b/app/models/grid_summon.rb @@ -3,6 +3,9 @@ class GridSummon < ApplicationRecord belongs_to :party + validate :compatible_with_position, on: :create + validate :no_conflicts, on: :create + def summon Summon.find(summon_id) end @@ -10,4 +13,36 @@ class GridSummon < ApplicationRecord def blueprint GridSummonBlueprint end + + # Returns conflicting summons if they exist + def conflicts(party) + return unless summon.limit + + party.summons.find do |party_summon| + ap 'Normal summon:' + ap summon + ap 'Party summon:' + ap party_summon + + summon if summon.id == party_summon.summon.id + end + end + + private + + # Validates whether there is a conflict with the party + def no_conflicts + ap conflicts(party) + + # Check if the grid weapon conflicts with any of the other grid weapons in the party + errors.add(:series, 'must not conflict with existing summons') unless conflicts(party).nil? + end + + # Validates whether the weapon can be added to the desired position + def compatible_with_position + ap [4, 5].include?(position.to_i) && !summon.subaura + return unless [4, 5].include?(position.to_i) && !summon.subaura + + errors.add(:position, 'must have subaura for position') + end end From 65d80244762212112e614a2da8fc99cd2b769180 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 19:57:49 -0800 Subject: [PATCH 25/86] Add XLB stat fields --- db/migrate/20230123035602_add_max_hpatkxlb_to_summon.rb | 6 ++++++ db/schema.rb | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20230123035602_add_max_hpatkxlb_to_summon.rb diff --git a/db/migrate/20230123035602_add_max_hpatkxlb_to_summon.rb b/db/migrate/20230123035602_add_max_hpatkxlb_to_summon.rb new file mode 100644 index 0000000..a5b5651 --- /dev/null +++ b/db/migrate/20230123035602_add_max_hpatkxlb_to_summon.rb @@ -0,0 +1,6 @@ +class AddMaxHpatkxlbToSummon < ActiveRecord::Migration[7.0] + def change + add_column :summons, :max_atk_xlb, :integer + add_column :summons, :max_hp_xlb, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 4cea1cb..28c80a7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_01_07_153724) do +ActiveRecord::Schema[7.0].define(version: 2023_01_23_035602) do # These are extensions that must be enabled in order to support this database enable_extension "btree_gin" enable_extension "pg_trgm" @@ -202,11 +202,13 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_07_153724) do t.integer "button_count" t.integer "chain_count" t.integer "turn_count" + t.uuid "source_party_id" t.index ["job_id"], name: "index_parties_on_job_id" t.index ["skill0_id"], name: "index_parties_on_skill0_id" t.index ["skill1_id"], name: "index_parties_on_skill1_id" t.index ["skill2_id"], name: "index_parties_on_skill2_id" t.index ["skill3_id"], name: "index_parties_on_skill3_id" + t.index ["source_party_id"], name: "index_parties_on_source_party_id" t.index ["user_id"], name: "index_parties_on_user_id" end @@ -240,6 +242,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_07_153724) do t.boolean "subaura", default: false, null: false t.boolean "limit", default: false, null: false t.boolean "xlb", default: false, null: false + t.integer "max_atk_xlb" + t.integer "max_hp_xlb" t.index ["name_en"], name: "index_summons_on_name_en", opclass: :gin_trgm_ops, using: :gin end @@ -313,6 +317,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_07_153724) do add_foreign_key "parties", "job_skills", column: "skill2_id" add_foreign_key "parties", "job_skills", column: "skill3_id" add_foreign_key "parties", "jobs" + add_foreign_key "parties", "parties", column: "source_party_id" add_foreign_key "parties", "raids" add_foreign_key "parties", "users" end From cf270f02434e65d25b1089cac195d044659d153b Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 19:57:57 -0800 Subject: [PATCH 26/86] Add XLB and stats to JSON output --- app/blueprints/api/v1/summon_blueprint.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/blueprints/api/v1/summon_blueprint.rb b/app/blueprints/api/v1/summon_blueprint.rb index 3db846d..7c9b84a 100644 --- a/app/blueprints/api/v1/summon_blueprint.rb +++ b/app/blueprints/api/v1/summon_blueprint.rb @@ -15,7 +15,8 @@ module Api field :uncap do |w| { flb: w.flb, - ulb: w.ulb + ulb: w.ulb, + xlb: w.xlb } end @@ -24,7 +25,8 @@ module Api min_hp: w.min_hp, max_hp: w.max_hp, max_hp_flb: w.max_hp_flb, - max_hp_ulb: w.max_hp_ulb + max_hp_ulb: w.max_hp_ulb, + max_hp_xlb: w.max_hp_xlb } end @@ -33,7 +35,8 @@ module Api min_atk: w.min_atk, max_atk: w.max_atk, max_atk_flb: w.max_atk_flb, - max_atk_ulb: w.max_atk_ulb + max_atk_ulb: w.max_atk_ulb, + max_atk_xlb: w.max_atk_xlb } end end From cfee8b0b31486acf5ad76427a066135b666d2354 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 19:58:45 -0800 Subject: [PATCH 27/86] Support for frontend transcendence Set transcendence step when updating uncap level --- app/controllers/api/v1/grid_characters_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/v1/grid_characters_controller.rb b/app/controllers/api/v1/grid_characters_controller.rb index 23d9381..4f0ec8b 100644 --- a/app/controllers/api/v1/grid_characters_controller.rb +++ b/app/controllers/api/v1/grid_characters_controller.rb @@ -90,6 +90,7 @@ module Api render_unauthorized_response if current_user && (character.party.user != current_user) character.uncap_level = character_params[:uncap_level] + character.transcendence_step = character_params[:transcendence_step] return unless character.save! render json: GridCharacterBlueprint.render(character, view: :nested, root: :grid_character) From bb79f68a2cc63b34ff2b2e1a33f625f275922163 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 20:37:15 -0800 Subject: [PATCH 28/86] Remove extraneous code --- app/controllers/api/v1/grid_characters_controller.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/v1/grid_characters_controller.rb b/app/controllers/api/v1/grid_characters_controller.rb index 4f0ec8b..8e1e3e0 100644 --- a/app/controllers/api/v1/grid_characters_controller.rb +++ b/app/controllers/api/v1/grid_characters_controller.rb @@ -48,13 +48,9 @@ module Api @character.attributes = character_params.merge(mastery) - if @character.save - ap 'Saved character' - return render json: GridCharacterBlueprint.render(@character, view: :full) if @character.save - else - ap 'Could not save' - render_validation_error_response(@character) - end + return render json: GridCharacterBlueprint.render(@character, view: :full) if @character.save + + render_validation_error_response(@character) end def resolve From 8c1fae02d4840fca64022e135fb5f235de5efdf6 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 20:37:52 -0800 Subject: [PATCH 29/86] Add update method to GridSummonsController --- app/controllers/api/v1/grid_summons_controller.rb | 10 +++++++++- config/routes.rb | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/grid_summons_controller.rb b/app/controllers/api/v1/grid_summons_controller.rb index 2a40033..a34a035 100644 --- a/app/controllers/api/v1/grid_summons_controller.rb +++ b/app/controllers/api/v1/grid_summons_controller.rb @@ -3,7 +3,7 @@ module Api module V1 class GridSummonsController < Api::V1::ApiController - before_action :set, only: %w[destroy] + before_action :set, only: %w[update destroy] attr_reader :party, :incoming_summon @@ -24,6 +24,14 @@ module Api end end + def update + @summon.attributes = summon_params + + return render json: GridSummonBlueprint.render(@summon, view: :full) if @summon.save + + render_validation_error_response(@character) + end + def save_summon(summon) if (grid_summon = GridSummon.where( party_id: party.id, diff --git a/config/routes.rb b/config/routes.rb index e9a6b9f..70bdf6d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,7 +10,7 @@ Rails.application.routes.draw do resources :users, only: %i[create update show] resources :grid_weapons, only: %i[update destroy] resources :grid_characters, only: %i[update destroy] - resources :grid_summons, only: %i[destroy] + resources :grid_summons, only: %i[update destroy] resources :favorites, only: [:create] get 'users/info/:id', to: 'users#info' From 422651668ef10b9fbac36bffe4612cc3f9361041 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 20:41:24 -0800 Subject: [PATCH 30/86] Permit transcendence_step --- app/controllers/api/v1/grid_summons_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/grid_summons_controller.rb b/app/controllers/api/v1/grid_summons_controller.rb index a34a035..6dfd6d4 100644 --- a/app/controllers/api/v1/grid_summons_controller.rb +++ b/app/controllers/api/v1/grid_summons_controller.rb @@ -99,7 +99,8 @@ module Api # Specify whitelisted properties that can be modified. 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, :uncap_level, + :transcendence_step) end end end From 717c08ea8fa9f26cf8a314767a9a362b13603450 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 21:01:58 -0800 Subject: [PATCH 31/86] Update summon task to download XLB images --- lib/tasks/export_summon.rake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/tasks/export_summon.rake b/lib/tasks/export_summon.rake index 5942ab1..7c81afd 100644 --- a/lib/tasks/export_summon.rake +++ b/lib/tasks/export_summon.rake @@ -36,6 +36,11 @@ namespace :granblue do f.write("#{build_summon_url("#{s.granblue_id}_02", size)} \n") end + + if s.xlb + f.write("#{build_summon_url("#{s.granblue_id}_03", + size)} \n") + end end end From b248fb62ea5ab4d1cec8f799482e84e90031ec85 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 21:02:06 -0800 Subject: [PATCH 32/86] Add transcendence_step to output --- app/blueprints/api/v1/grid_summon_blueprint.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/blueprints/api/v1/grid_summon_blueprint.rb b/app/blueprints/api/v1/grid_summon_blueprint.rb index 1a27594..116b7ab 100644 --- a/app/blueprints/api/v1/grid_summon_blueprint.rb +++ b/app/blueprints/api/v1/grid_summon_blueprint.rb @@ -5,11 +5,11 @@ module Api class GridSummonBlueprint < ApiBlueprint view :uncap do association :party, blueprint: PartyBlueprint, view: :minimal - fields :position, :uncap_level + fields :position, :uncap_level, :transcendence_step end view :nested do - fields :main, :friend, :position, :uncap_level + fields :main, :friend, :position, :uncap_level, :transcendence_step association :summon, name: :object, blueprint: SummonBlueprint end From 5460a1d1678a076277024384cbdcb17c6df2c02c Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 21:02:19 -0800 Subject: [PATCH 33/86] Reset transcendence step on uncap --- app/controllers/api/v1/grid_summons_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/grid_summons_controller.rb b/app/controllers/api/v1/grid_summons_controller.rb index 6dfd6d4..788f3d5 100644 --- a/app/controllers/api/v1/grid_summons_controller.rb +++ b/app/controllers/api/v1/grid_summons_controller.rb @@ -27,7 +27,7 @@ module Api def update @summon.attributes = summon_params - return render json: GridSummonBlueprint.render(@summon, view: :full) if @summon.save + return render json: GridSummonBlueprint.render(@summon, view: :nested, root: :grid_summon) if @summon.save render_validation_error_response(@character) end @@ -65,6 +65,8 @@ module Api 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) From bd15d91cdd17ec9ad7435fcb37c0011e12584c0d Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 21:24:00 -0800 Subject: [PATCH 34/86] Fix grid character creation Grid characters were only replacing the character when replacing an existing character, so the mods were persisted. This creates a new GridCharacter every time a replacement happens and destroys the old one. --- .../api/v1/grid_characters_controller.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/v1/grid_characters_controller.rb b/app/controllers/api/v1/grid_characters_controller.rb index 23d9381..74f521e 100644 --- a/app/controllers/api/v1/grid_characters_controller.rb +++ b/app/controllers/api/v1/grid_characters_controller.rb @@ -21,17 +21,16 @@ module Api conflict_view = render_conflict_view(conflict_characters, incoming_character, character_params[:position]) render json: conflict_view else - # Replace the grid character in the position if it is already filled + # Destroy the grid character in the position if it is already filled if GridCharacter.where(party_id: party.id, position: character_params[:position]).exists? character = GridCharacter.where(party_id: party.id, position: character_params[:position]).limit(1)[0] - character.character_id = incoming_character.id - - # Otherwise, create a new grid character - else - character = GridCharacter.create!(character_params.merge(party_id: party.id, - character_id: incoming_character.id)) + character.destroy end + # Then, create a new grid character + character = GridCharacter.create!(character_params.merge(party_id: party.id, + character_id: incoming_character.id)) + if character.save! grid_character_view = render_grid_character_view(character) render json: grid_character_view, status: :created From 54948e4435364cc7368030586f942eebf06de528 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 21:56:08 -0800 Subject: [PATCH 35/86] Add slug to Jobs table --- db/migrate/20230123055508_add_slug_to_jobs.rb | 5 +++++ db/schema.rb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20230123055508_add_slug_to_jobs.rb diff --git a/db/migrate/20230123055508_add_slug_to_jobs.rb b/db/migrate/20230123055508_add_slug_to_jobs.rb new file mode 100644 index 0000000..cfc731d --- /dev/null +++ b/db/migrate/20230123055508_add_slug_to_jobs.rb @@ -0,0 +1,5 @@ +class AddSlugToJobs < ActiveRecord::Migration[7.0] + def change + add_column :jobs, :slug, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 28c80a7..a3787e4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_01_23_035602) do +ActiveRecord::Schema[7.0].define(version: 2023_01_23_055508) do # These are extensions that must be enabled in order to support this database enable_extension "btree_gin" enable_extension "pg_trgm" @@ -137,6 +137,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_23_035602) do t.boolean "ml", default: false t.integer "order" t.uuid "base_job_id" + t.string "slug" t.index ["base_job_id"], name: "index_jobs_on_base_job_id" end From 67146e3ab38a15fec42fa1500fd878c801117eb7 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 21:59:43 -0800 Subject: [PATCH 36/86] Add Granblue ID instead of slug --- db/migrate/20230123055508_add_granblue_id_to_jobs.rb | 5 +++++ db/migrate/20230123055508_add_slug_to_jobs.rb | 5 ----- db/schema.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20230123055508_add_granblue_id_to_jobs.rb delete mode 100644 db/migrate/20230123055508_add_slug_to_jobs.rb diff --git a/db/migrate/20230123055508_add_granblue_id_to_jobs.rb b/db/migrate/20230123055508_add_granblue_id_to_jobs.rb new file mode 100644 index 0000000..6cf8764 --- /dev/null +++ b/db/migrate/20230123055508_add_granblue_id_to_jobs.rb @@ -0,0 +1,5 @@ +class AddGranblueIdToJobs < ActiveRecord::Migration[7.0] + def change + add_column :jobs, :granblue_id, :string + end +end diff --git a/db/migrate/20230123055508_add_slug_to_jobs.rb b/db/migrate/20230123055508_add_slug_to_jobs.rb deleted file mode 100644 index cfc731d..0000000 --- a/db/migrate/20230123055508_add_slug_to_jobs.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddSlugToJobs < ActiveRecord::Migration[7.0] - def change - add_column :jobs, :slug, :string - end -end diff --git a/db/schema.rb b/db/schema.rb index a3787e4..27a45bc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -137,7 +137,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_23_055508) do t.boolean "ml", default: false t.integer "order" t.uuid "base_job_id" - t.string "slug" + t.string "granblue_id" t.index ["base_job_id"], name: "index_jobs_on_base_job_id" end From 4ee65aecd30f71e801399bd6e452d6c5d3057904 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 22:25:02 -0800 Subject: [PATCH 37/86] Add Rake task for creating a list of Job icon URLs --- lib/tasks/export_all.rake | 6 +++++- lib/tasks/export_job.rake | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 lib/tasks/export_job.rake diff --git a/lib/tasks/export_all.rake b/lib/tasks/export_all.rake index 80198be..1af2841 100644 --- a/lib/tasks/export_all.rake +++ b/lib/tasks/export_all.rake @@ -32,7 +32,11 @@ namespace :granblue do Rake::Task['granblue:export:summon'].invoke('square') Rake::Task['granblue:export:summon'].reenable - puts 'Exported 9 files' + # Run job tasks + Rake::Task['granblue:export:job'].invoke + Rake::Task['granblue:export:job'].reenable + + puts 'Exported 10 files' end end end diff --git a/lib/tasks/export_job.rake b/lib/tasks/export_job.rake new file mode 100644 index 0000000..87bdb4d --- /dev/null +++ b/lib/tasks/export_job.rake @@ -0,0 +1,33 @@ +namespace :granblue do + namespace :export do + def build_job_icon_url(id) + # Set up URL + base_url = 'https://prd-game-a-granbluefantasy.akamaized.net/assets_en/img/sp/ui/icon/job' + extension = '.png' + + "#{base_url}/#{id}#{extension}" + end + + desc 'Exports a list of weapon URLs for a given size' + task :job do |_t, _args| + # Include weapon model + Dir.glob("#{Rails.root}/app/models/job.rb").each { |file| require file } + + # Set up filepath + dir = "#{Rails.root}/export/" + filename = "#{dir}/job-icon.txt" + FileUtils.mkdir(dir) unless Dir.exist?(dir) + + # Write to file + File.open(filename, 'w') do |f| + Job.all.each do |w| + f.write("#{build_job_icon_url(w.granblue_id.to_s)} \n") + end + end + + # CLI output + count = `wc -l #{filename}`.split.first.to_i + puts "Wrote #{count} job URLs for icon size" + end + end +end From ed76afe44c3c519cb54af16e1f766f37106e184a Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 22:31:25 -0800 Subject: [PATCH 38/86] Add granblue_id to Job output --- app/blueprints/api/v1/job_blueprint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/blueprints/api/v1/job_blueprint.rb b/app/blueprints/api/v1/job_blueprint.rb index 319a62b..43fabec 100644 --- a/app/blueprints/api/v1/job_blueprint.rb +++ b/app/blueprints/api/v1/job_blueprint.rb @@ -17,7 +17,7 @@ module Api ] end - fields :row, :ml, :order + fields :granblue_id, :row, :ml, :order end end end From 098fdbffa89189ac37b32dc2f471f6eb2f2eab9e Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 23:45:49 -0800 Subject: [PATCH 39/86] Attempt moving Gemfile --- Gemfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 3565c3f..d0d8356 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,6 @@ source 'https://rubygems.org' ruby '3.0.0' -gem 'bootsnap' gem 'pg' gem 'rack-cors' gem 'rails' @@ -46,6 +45,8 @@ gem 'will_paginate', '~> 3.3' # Migrate and update data alongside your database structure. gem 'data_migrate' +gem 'bootsnap' + group :doc do gem 'apipie-rails' gem 'sdoc' From fcbf97fe0a9511cce70b49d4f7c6693c8b3fd0fd Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 23 Jan 2023 00:00:38 -0800 Subject: [PATCH 40/86] Recreate schema.rb --- db/schema.rb | 378 +++++++++++++++++++++++++-------------------------- 1 file changed, 189 insertions(+), 189 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 41d51d3..267548e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,120 +12,120 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_23_055508) do # These are extensions that must be enabled in order to support this database - enable_extension 'btree_gin' - enable_extension 'pg_trgm' - enable_extension 'pgcrypto' - enable_extension 'plpgsql' + enable_extension "btree_gin" + enable_extension "pg_trgm" + enable_extension "pgcrypto" + enable_extension "plpgsql" - create_table 'characters', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| - t.string 'name_en' - t.string 'name_jp' - t.string 'granblue_id' - t.integer 'rarity' - t.integer 'element' - t.integer 'proficiency1' - t.integer 'proficiency2' - t.integer 'gender' - t.integer 'race1' - t.integer 'race2' - t.boolean 'flb', default: false, null: false - t.integer 'min_hp' - t.integer 'max_hp' - t.integer 'max_hp_flb' - t.integer 'min_atk' - t.integer 'max_atk' - t.integer 'max_atk_flb' - t.integer 'base_da' - t.integer 'base_ta' - t.float 'ougi_ratio' - t.float 'ougi_ratio_flb' - t.boolean 'special', default: false, null: false - t.boolean 'ulb', default: false, null: false - t.integer 'max_hp_ulb' - t.integer 'max_atk_ulb' - t.integer 'character_id', default: [], null: false, array: true - t.index ['name_en'], name: 'index_characters_on_name_en', opclass: :gin_trgm_ops, using: :gin + create_table "characters", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "name_en" + t.string "name_jp" + t.string "granblue_id" + t.integer "rarity" + t.integer "element" + t.integer "proficiency1" + t.integer "proficiency2" + t.integer "gender" + t.integer "race1" + t.integer "race2" + t.boolean "flb", default: false, null: false + t.integer "min_hp" + t.integer "max_hp" + t.integer "max_hp_flb" + t.integer "min_atk" + t.integer "max_atk" + t.integer "max_atk_flb" + t.integer "base_da" + t.integer "base_ta" + t.float "ougi_ratio" + t.float "ougi_ratio_flb" + t.boolean "special", default: false, null: false + t.boolean "ulb", default: false, null: false + t.integer "max_hp_ulb" + t.integer "max_atk_ulb" + t.integer "character_id", default: [], null: false, array: true + t.index ["name_en"], name: "index_characters_on_name_en", opclass: :gin_trgm_ops, using: :gin end - create_table 'data_migrations', primary_key: 'version', id: :string, force: :cascade do |t| + create_table "favorites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "user_id" + t.uuid "party_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["party_id"], name: "index_favorites_on_party_id" + t.index ["user_id"], name: "index_favorites_on_user_id" end - create_table 'favorites', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| - t.uuid 'user_id' - t.uuid 'party_id' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.index ['party_id'], name: 'index_favorites_on_party_id' - t.index ['user_id'], name: 'index_favorites_on_user_id' + create_table "grid_characters", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "party_id" + t.uuid "character_id" + t.integer "uncap_level" + t.integer "position" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "perpetuity", default: false, null: false + t.integer "transcendence_step", default: 0, null: false + t.jsonb "ring1", default: {"modifier"=>nil, "strength"=>nil}, null: false + t.jsonb "ring2", default: {"modifier"=>nil, "strength"=>nil}, null: false + t.jsonb "ring3", default: {"modifier"=>nil, "strength"=>nil}, null: false + t.jsonb "ring4", default: {"modifier"=>nil, "strength"=>nil}, null: false + t.jsonb "earring", default: {"modifier"=>nil, "strength"=>nil}, null: false + t.jsonb "awakening", default: {"type"=>1, "level"=>1}, null: false + t.index ["character_id"], name: "index_grid_characters_on_character_id" + t.index ["party_id"], name: "index_grid_characters_on_party_id" end - create_table 'grid_characters', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| - t.uuid 'party_id' - t.uuid 'character_id' - t.integer 'uncap_level' - t.integer 'position' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.boolean 'perpetuity', default: false, null: false - t.integer 'transcendence_step', default: 0, null: false - t.jsonb 'ring1', default: { 'modifier' => nil, 'strength' => nil }, null: false - t.jsonb 'ring2', default: { 'modifier' => nil, 'strength' => nil }, null: false - t.jsonb 'ring3', default: { 'modifier' => nil, 'strength' => nil }, null: false - t.jsonb 'ring4', default: { 'modifier' => nil, 'strength' => nil }, null: false - t.jsonb 'earring', default: { 'modifier' => nil, 'strength' => nil }, null: false - t.jsonb 'awakening', default: { 'type' => 1, 'level' => 1 }, null: false - t.index ['character_id'], name: 'index_grid_characters_on_character_id' - t.index ['party_id'], name: 'index_grid_characters_on_party_id' + create_table "grid_summons", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "party_id" + t.uuid "summon_id" + t.integer "uncap_level" + t.boolean "main" + t.boolean "friend" + t.integer "position" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "transcendence_step", default: 0, null: false + t.index ["party_id"], name: "index_grid_summons_on_party_id" + t.index ["summon_id"], name: "index_grid_summons_on_summon_id" end - create_table 'grid_summons', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| - t.uuid 'party_id' - t.uuid 'summon_id' - t.integer 'uncap_level' - t.boolean 'main' - t.boolean 'friend' - t.integer 'position' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.integer 'transcendence_step', default: 0, null: false - t.index ['party_id'], name: 'index_grid_summons_on_party_id' - t.index ['summon_id'], name: 'index_grid_summons_on_summon_id' + create_table "grid_weapons", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "party_id" + t.uuid "weapon_id" + t.uuid "weapon_key1_id" + t.uuid "weapon_key2_id" + t.integer "uncap_level" + t.boolean "mainhand" + t.integer "position" + t.datetime "created_at", null: false + t.datetime "updated_at", 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.integer "awakening_type" + t.integer "awakening_level", default: 1, null: false + 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_key1_id"], name: "index_grid_weapons_on_weapon_key1_id" + t.index ["weapon_key2_id"], name: "index_grid_weapons_on_weapon_key2_id" + t.index ["weapon_key3_id"], name: "index_grid_weapons_on_weapon_key3_id" end - create_table 'grid_weapons', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| - t.uuid 'party_id' - t.uuid 'weapon_id' - t.uuid 'weapon_key1_id' - t.uuid 'weapon_key2_id' - t.integer 'uncap_level' - t.boolean 'mainhand' - t.integer 'position' - t.datetime 'created_at', null: false - t.datetime 'updated_at', 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.integer 'awakening_type' - t.integer 'awakening_level', default: 1, null: false - t.index ['party_id'], name: 'index_grid_weapons_on_party_id' - t.index ['weapon_id'], name: 'index_grid_weapons_on_weapon_id' - end - - create_table 'job_skills', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| - t.uuid 'job_id' - t.string 'name_en', null: false - t.string 'name_jp', null: false - t.string 'slug', null: false - t.integer 'color', null: false - t.boolean 'main', default: false - t.boolean 'sub', default: false - t.boolean 'emp', default: false - t.integer 'order' - t.boolean 'base', default: false - t.index ['job_id'], name: 'index_job_skills_on_job_id' + create_table "job_skills", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "job_id" + t.string "name_en", null: false + t.string "name_jp", null: false + t.string "slug", null: false + t.integer "color", null: false + t.boolean "main", default: false + t.boolean "sub", default: false + t.boolean "emp", default: false + t.integer "order" + t.boolean "base", default: false + t.index ["job_id"], name: "index_job_skills_on_job_id" end create_table "jobs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -141,42 +141,42 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_23_055508) do t.index ["base_job_id"], name: "index_jobs_on_base_job_id" end - create_table 'oauth_access_grants', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| - t.uuid 'resource_owner_id', null: false - t.uuid 'application_id', null: false - t.string 'token', null: false - t.integer 'expires_in', null: false - t.text 'redirect_uri', null: false - t.datetime 'created_at', precision: nil, null: false - t.datetime 'revoked_at', precision: nil - t.string 'scopes' - t.index ['token'], name: 'index_oauth_access_grants_on_token', unique: true + create_table "oauth_access_grants", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "resource_owner_id", null: false + t.uuid "application_id", null: false + t.string "token", null: false + t.integer "expires_in", null: false + t.text "redirect_uri", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "revoked_at", precision: nil + t.string "scopes" + t.index ["token"], name: "index_oauth_access_grants_on_token", unique: true end - create_table 'oauth_access_tokens', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| - t.uuid 'resource_owner_id' - t.uuid 'application_id' - t.string 'token', null: false - t.string 'refresh_token' - t.integer 'expires_in' - t.datetime 'revoked_at', precision: nil - t.datetime 'created_at', precision: nil, null: false - t.string 'scopes' - t.string 'previous_refresh_token', default: '', null: false - t.index ['refresh_token'], name: 'index_oauth_access_tokens_on_refresh_token', unique: true - t.index ['resource_owner_id'], name: 'index_oauth_access_tokens_on_resource_owner_id' - t.index ['token'], name: 'index_oauth_access_tokens_on_token', unique: true + create_table "oauth_access_tokens", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "resource_owner_id" + t.uuid "application_id" + t.string "token", null: false + t.string "refresh_token" + t.integer "expires_in" + t.datetime "revoked_at", precision: nil + t.datetime "created_at", precision: nil, null: false + t.string "scopes" + t.string "previous_refresh_token", default: "", null: false + t.index ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true + t.index ["resource_owner_id"], name: "index_oauth_access_tokens_on_resource_owner_id" + t.index ["token"], name: "index_oauth_access_tokens_on_token", unique: true end - create_table 'oauth_applications', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| - t.string 'name', null: false - t.string 'uid', null: false - t.string 'secret', null: false - t.text 'redirect_uri', null: false - t.string 'scopes', default: '', null: false - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.index ['uid'], name: 'index_oauth_applications_on_uid', unique: true + create_table "oauth_applications", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "name", null: false + t.string "uid", null: false + t.string "secret", null: false + t.text "redirect_uri", null: false + t.string "scopes", default: "", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["uid"], name: "index_oauth_applications_on_uid", unique: true end create_table "parties", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -213,13 +213,13 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_23_055508) do t.index ["user_id"], name: "index_parties_on_user_id" end - create_table 'raids', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| - t.string 'name_en' - t.string 'name_jp' - t.integer 'level' - t.integer 'group' - t.integer 'element' - t.string 'slug' + create_table "raids", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "name_en" + t.string "name_jp" + t.integer "level" + t.integer "group" + t.integer "element" + t.string "slug" end create_table "summons", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -248,57 +248,57 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_23_055508) do t.index ["name_en"], name: "index_summons_on_name_en", opclass: :gin_trgm_ops, using: :gin end - create_table 'users', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| - t.string 'email' - t.string 'password_digest' - t.string 'username' - t.integer 'granblue_id' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.string 'picture', default: 'gran' - t.string 'language', default: 'en', null: false - t.boolean 'private', default: false, null: false - t.string 'element', default: 'water', null: false - t.integer 'gender', default: 0, null: false - t.string 'theme', default: 'system', null: false + create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "email" + t.string "password_digest" + t.string "username" + t.integer "granblue_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "picture", default: "gran" + t.string "language", default: "en", null: false + t.boolean "private", default: false, null: false + t.string "element", default: "water", null: false + t.integer "gender", default: 0, null: false + t.string "theme", default: "system", null: false end - create_table 'weapon_keys', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| - t.string 'name_en' - t.string 'name_jp' - t.integer 'series' - t.integer 'slot' - t.integer 'group' - t.integer 'order' - t.string 'slug' + create_table "weapon_keys", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "name_en" + t.string "name_jp" + t.integer "series" + t.integer "slot" + t.integer "group" + t.integer "order" + t.string "slug" end - create_table 'weapons', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| - t.string 'name_en' - t.string 'name_jp' - t.string 'granblue_id' - t.integer 'rarity' - t.integer 'element' - t.integer 'proficiency' - t.integer 'series', default: -1, null: false - t.boolean 'flb', default: false, null: false - t.boolean 'ulb', default: false, null: false - t.integer 'max_level', default: 100, null: false - t.integer 'max_skill_level', default: 10, null: false - t.integer 'min_hp' - t.integer 'max_hp' - t.integer 'max_hp_flb' - t.integer 'max_hp_ulb' - t.integer 'min_atk' - t.integer 'max_atk' - t.integer 'max_atk_flb' - t.integer 'max_atk_ulb' - t.boolean 'extra', default: false, null: false - t.integer 'ax_type' - t.boolean 'awakening', default: true, null: false - t.boolean 'limit', default: false, null: false - t.boolean 'ax', default: false, null: false - t.index ['name_en'], name: 'index_weapons_on_name_en', opclass: :gin_trgm_ops, using: :gin + create_table "weapons", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "name_en" + t.string "name_jp" + t.string "granblue_id" + t.integer "rarity" + t.integer "element" + t.integer "proficiency" + t.integer "series", default: -1, null: false + t.boolean "flb", default: false, null: false + t.boolean "ulb", default: false, null: false + t.integer "max_level", default: 100, null: false + t.integer "max_skill_level", default: 10, null: false + t.integer "min_hp" + t.integer "max_hp" + t.integer "max_hp_flb" + t.integer "max_hp_ulb" + t.integer "min_atk" + t.integer "max_atk" + t.integer "max_atk_flb" + t.integer "max_atk_ulb" + t.boolean "extra", default: false, null: false + t.integer "ax_type" + t.boolean "awakening", default: true, null: false + t.boolean "limit", default: false, null: false + t.boolean "ax", default: false, null: false + t.index ["name_en"], name: "index_weapons_on_name_en", opclass: :gin_trgm_ops, using: :gin end add_foreign_key "favorites", "parties" From 31240936abdee7c0199f5fdb590b7b3a3f20734f Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 23 Jan 2023 00:00:56 -0800 Subject: [PATCH 41/86] Move bootsnap back --- Gemfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 038f94d..66eeb1b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source 'https://rubygems.org' ruby '3.0.0' +gem 'bootsnap' gem 'pg' gem 'rack-cors' gem 'rails' @@ -48,8 +49,6 @@ gem 'data_migrate' # A ruby gem to allow the copying of ActiveRecord objects and their associated children, configurable with a DSL on the model gem 'amoeba' -gem 'bootsnap' - group :doc do gem 'apipie-rails' gem 'sdoc' From cbfe7ce2da4c291ac8a4445e61b328002647708f Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 23 Jan 2023 00:42:55 -0800 Subject: [PATCH 42/86] Attempt to fix staging by updating gems --- Gemfile.lock | 140 +++++++++++++++++++++++++-------------------------- db/schema.rb | 1 + 2 files changed, 71 insertions(+), 70 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a982265..b9ea1dd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,67 +1,67 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.0.4) - actionpack (= 7.0.4) - activesupport (= 7.0.4) + actioncable (7.0.4.1) + actionpack (= 7.0.4.1) + activesupport (= 7.0.4.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.4) - actionpack (= 7.0.4) - activejob (= 7.0.4) - activerecord (= 7.0.4) - activestorage (= 7.0.4) - activesupport (= 7.0.4) + actionmailbox (7.0.4.1) + actionpack (= 7.0.4.1) + activejob (= 7.0.4.1) + activerecord (= 7.0.4.1) + activestorage (= 7.0.4.1) + activesupport (= 7.0.4.1) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.4) - actionpack (= 7.0.4) - actionview (= 7.0.4) - activejob (= 7.0.4) - activesupport (= 7.0.4) + actionmailer (7.0.4.1) + actionpack (= 7.0.4.1) + actionview (= 7.0.4.1) + activejob (= 7.0.4.1) + activesupport (= 7.0.4.1) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) - actionpack (7.0.4) - actionview (= 7.0.4) - activesupport (= 7.0.4) + actionpack (7.0.4.1) + actionview (= 7.0.4.1) + activesupport (= 7.0.4.1) rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.4) - actionpack (= 7.0.4) - activerecord (= 7.0.4) - activestorage (= 7.0.4) - activesupport (= 7.0.4) + actiontext (7.0.4.1) + actionpack (= 7.0.4.1) + activerecord (= 7.0.4.1) + activestorage (= 7.0.4.1) + activesupport (= 7.0.4.1) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.4) - activesupport (= 7.0.4) + actionview (7.0.4.1) + activesupport (= 7.0.4.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.4) - activesupport (= 7.0.4) + activejob (7.0.4.1) + activesupport (= 7.0.4.1) globalid (>= 0.3.6) - activemodel (7.0.4) - activesupport (= 7.0.4) - activerecord (7.0.4) - activemodel (= 7.0.4) - activesupport (= 7.0.4) - activestorage (7.0.4) - actionpack (= 7.0.4) - activejob (= 7.0.4) - activerecord (= 7.0.4) - activesupport (= 7.0.4) + activemodel (7.0.4.1) + activesupport (= 7.0.4.1) + activerecord (7.0.4.1) + activemodel (= 7.0.4.1) + activesupport (= 7.0.4.1) + activestorage (7.0.4.1) + actionpack (= 7.0.4.1) + activejob (= 7.0.4.1) + activerecord (= 7.0.4.1) + activesupport (= 7.0.4.1) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.4) + activesupport (7.0.4.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -73,7 +73,7 @@ GEM activesupport (>= 3.2.5) nokogiri (>= 1.5.2) rspec (>= 3.1) - apipie-rails (0.9.0) + apipie-rails (0.9.1) actionpack (>= 5.0) activesupport (>= 5.0) ast (2.4.2) @@ -124,7 +124,7 @@ GEM gemoji (4.0.1) gemoji-parser (1.3.1) gemoji (>= 2.1.0) - globalid (1.0.0) + globalid (1.0.1) activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) @@ -134,13 +134,13 @@ GEM rexml kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) - listen (3.7.1) + listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.8.0) + mail (2.8.0.1) mini_mime (>= 0.1.1) net-imap net-pop @@ -161,7 +161,7 @@ GEM net-smtp (0.3.3) net-protocol nio4r (2.5.8) - nokogiri (1.13.10) + nokogiri (1.14.0) mini_portile2 (~> 2.8.0) racc (~> 1.4) oj (3.13.23) @@ -172,38 +172,38 @@ GEM pg_search (2.3.6) activerecord (>= 5.2) activesupport (>= 5.2) - psych (5.0.1) + psych (5.0.2) stringio puma (6.0.2) nio4r (~> 2.0) racc (1.6.2) - rack (2.2.5) + rack (2.2.6.2) rack-cors (1.1.1) rack (>= 2.0.0) rack-test (2.0.2) rack (>= 1.3) - rails (7.0.4) - actioncable (= 7.0.4) - actionmailbox (= 7.0.4) - actionmailer (= 7.0.4) - actionpack (= 7.0.4) - actiontext (= 7.0.4) - actionview (= 7.0.4) - activejob (= 7.0.4) - activemodel (= 7.0.4) - activerecord (= 7.0.4) - activestorage (= 7.0.4) - activesupport (= 7.0.4) + rails (7.0.4.1) + actioncable (= 7.0.4.1) + actionmailbox (= 7.0.4.1) + actionmailer (= 7.0.4.1) + actionpack (= 7.0.4.1) + actiontext (= 7.0.4.1) + actionview (= 7.0.4.1) + activejob (= 7.0.4.1) + activemodel (= 7.0.4.1) + activerecord (= 7.0.4.1) + activestorage (= 7.0.4.1) + activesupport (= 7.0.4.1) bundler (>= 1.15.0) - railties (= 7.0.4) + railties (= 7.0.4.1) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.4.4) + rails-html-sanitizer (1.5.0) loofah (~> 2.19, >= 2.19.1) - railties (7.0.4) - actionpack (= 7.0.4) - activesupport (= 7.0.4) + railties (7.0.4.1) + actionpack (= 7.0.4.1) + activesupport (= 7.0.4.1) method_source rake (>= 12.2) thor (~> 1.0) @@ -215,7 +215,7 @@ GEM ffi (~> 1.0) rdoc (6.5.0) psych (>= 4.0.0) - regexp_parser (2.6.1) + regexp_parser (2.6.2) responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) @@ -228,10 +228,10 @@ GEM rspec-mocks (~> 3.12.0) rspec-core (3.12.0) rspec-support (~> 3.12.0) - rspec-expectations (3.12.1) + rspec-expectations (3.12.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-mocks (3.12.1) + rspec-mocks (3.12.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-rails (6.0.1) @@ -245,20 +245,20 @@ GEM rspec-support (3.12.0) rspec_junit_formatter (0.6.0) rspec-core (>= 2, < 4, != 2.12.0) - rubocop (1.42.0) + rubocop (1.43.0) json (~> 2.3) parallel (~> 1.10) - parser (>= 3.1.2.1) + parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) rubocop-ast (>= 1.24.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) + unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.24.1) parser (>= 3.1.1.0) ruby-progressbar (1.11.0) - sdoc (2.5.0) + sdoc (2.6.0) rdoc (>= 5.0) shoulda-matchers (5.3.0) activesupport (>= 5.2.0) @@ -283,7 +283,7 @@ GEM thor (~> 1.0) tilt (~> 2.0) yard (~> 0.9, >= 0.9.24) - spring (4.1.0) + spring (4.1.1) spring-commands-rspec (1.0.4) spring (>= 0.9.1) stringio (3.0.4) @@ -292,7 +292,7 @@ GEM timeout (0.3.1) tzinfo (2.0.5) concurrent-ruby (~> 1.0) - unicode-display_width (2.4.0) + unicode-display_width (2.4.2) webrick (1.7.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) diff --git a/db/schema.rb b/db/schema.rb index 267548e..36444f5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -16,6 +16,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_23_055508) do enable_extension "pg_trgm" enable_extension "pgcrypto" enable_extension "plpgsql" + enable_extension "timescaledb" create_table "characters", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name_en" From 5b7a61c3bb3dddb40b96cfcdf8ff6891b1059a59 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 23 Jan 2023 00:53:57 -0800 Subject: [PATCH 43/86] Add sprockets to gemfile --- Gemfile | 1 + Gemfile.lock | 8 ++++++++ config/application.rb | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 66eeb1b..0b7ae76 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gem 'bootsnap' gem 'pg' gem 'rack-cors' gem 'rails' +gem 'sprockets-rails' # A Ruby Web Server Built For Concurrency gem 'puma' diff --git a/Gemfile.lock b/Gemfile.lock index b9ea1dd..4b196af 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -286,6 +286,13 @@ GEM spring (4.1.1) spring-commands-rspec (1.0.4) spring (>= 0.9.1) + sprockets (4.0.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.2) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) stringio (3.0.4) thor (1.2.1) tilt (2.0.11) @@ -341,6 +348,7 @@ DEPENDENCIES solargraph spring spring-commands-rspec + sprockets-rails will_paginate (~> 3.3) RUBY VERSION diff --git a/config/application.rb b/config/application.rb index 91ad666..b8b060c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -10,7 +10,7 @@ require "action_controller/railtie" require "action_text/engine" require "action_view/railtie" require "action_cable/engine" -# require "sprockets/railtie" +require "sprockets/railtie" require "rails/test_unit/railtie" # Require the gems listed in Gemfile, including any gems From 3ced0c6523d718acbf4446ae8c74001c7d6ab7c6 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 23 Jan 2023 01:01:08 -0800 Subject: [PATCH 44/86] Upgrade to rails 7 --- Gemfile.lock | 10 +- app/assets/config/manifest.js | 0 bin/rails | 11 +- bin/rake | 9 +- bin/setup | 24 ++-- config/application.rb | 16 ++- config/boot.rb | 6 +- config/environment.rb | 2 +- config/environments/development.rb | 85 ++++++----- config/environments/production.rb | 65 +++------ config/environments/test.rb | 34 +++-- config/initializers/cors.rb | 6 +- .../initializers/filter_parameter_logging.rb | 8 +- config/initializers/inflections.rb | 8 +- .../new_framework_defaults_7_0.rb | 135 ++++++++++++++++++ 15 files changed, 264 insertions(+), 155 deletions(-) create mode 100644 app/assets/config/manifest.js create mode 100644 config/initializers/new_framework_defaults_7_0.rb diff --git a/Gemfile.lock b/Gemfile.lock index 4b196af..c8cef33 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -286,12 +286,12 @@ GEM spring (4.1.1) spring-commands-rspec (1.0.4) spring (>= 0.9.1) - sprockets (4.0.2) + sprockets (4.2.0) concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.2) - actionpack (>= 4.0) - activesupport (>= 4.0) + rack (>= 2.2.4, < 4) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) sprockets (>= 3.0.0) stringio (3.0.4) thor (1.2.1) diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000..e69de29 diff --git a/bin/rails b/bin/rails index 5badb2f..efc0377 100755 --- a/bin/rails +++ b/bin/rails @@ -1,9 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path('../spring', __FILE__) -rescue LoadError => e - raise unless e.message.include?('spring') -end -APP_PATH = File.expand_path('../config/application', __dir__) -require_relative '../config/boot' -require 'rails/commands' +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/bin/rake b/bin/rake index d87d5f5..4fbf10b 100755 --- a/bin/rake +++ b/bin/rake @@ -1,9 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path('../spring', __FILE__) -rescue LoadError => e - raise unless e.message.include?('spring') -end -require_relative '../config/boot' -require 'rake' +require_relative "../config/boot" +require "rake" Rake.application.run diff --git a/bin/setup b/bin/setup index 0e39e8c..ec47b79 100755 --- a/bin/setup +++ b/bin/setup @@ -1,33 +1,33 @@ #!/usr/bin/env ruby -require 'fileutils' +require "fileutils" # path to your application root. -APP_ROOT = File.expand_path('..', __dir__) +APP_ROOT = File.expand_path("..", __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end FileUtils.chdir APP_ROOT do - # This script is a way to setup or update your development environment automatically. - # This script is idempotent, so that you can run it at anytime and get an expectable outcome. + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. # Add necessary setup steps to this file. - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") # puts "\n== Copying sample files ==" - # unless File.exist?('config/database.yml') - # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" # end puts "\n== Preparing database ==" - system! 'bin/rails db:prepare' + system! "bin/rails db:prepare" puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' + system! "bin/rails log:clear tmp:clear" puts "\n== Restarting application server ==" - system! 'bin/rails restart' + system! "bin/rails restart" end diff --git a/config/application.rb b/config/application.rb index b8b060c..d5011bc 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,4 +1,4 @@ -require_relative 'boot' +require_relative "boot" require "rails" # Pick the frameworks you want: @@ -7,10 +7,11 @@ require "active_job/railtie" require "active_record/railtie" require "active_storage/engine" require "action_controller/railtie" +# require "action_mailer/railtie" +# require "action_mailbox/engine" require "action_text/engine" require "action_view/railtie" require "action_cable/engine" -require "sprockets/railtie" require "rails/test_unit/railtie" # Require the gems listed in Gemfile, including any gems @@ -22,10 +23,13 @@ module HenseiApi # Initialize configuration defaults for originally generated Rails version. config.load_defaults 7.0 - # Settings in config/environments/* take precedence over those specified here. - # Application configuration can go into files in config/initializers - # -- all .rb files in that directory are automatically loaded after loading - # the framework and any gems in your application. + # Configuration for the application, engines, and railties goes here. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") # Only loads a smaller set of middleware suitable for API only apps. # Middleware like session, flash, cookies can be added back manually. diff --git a/config/boot.rb b/config/boot.rb index b9e460c..988a5dd 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,4 +1,4 @@ -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -require 'bundler/setup' # Set up gems listed in the Gemfile. -require 'bootsnap/setup' # Speed up boot time by caching expensive operations. +require "bundler/setup" # Set up gems listed in the Gemfile. +require "bootsnap/setup" # Speed up boot time by caching expensive operations. diff --git a/config/environment.rb b/config/environment.rb index 426333b..cac5315 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ # Load the Rails application. -require_relative 'application' +require_relative "application" # Initialize the Rails application. Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index 6e13811..02cf2fe 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,60 +1,59 @@ +require "active_support/core_ext/integer/time" + Rails.application.configure do - config.after_initialize do - ActiveRecord::Base.logger = Rails.logger.clone - ActiveRecord::Base.logger.level = Logger::INFO - end + # Settings specified here will take precedence over those in config/application.rb. - # Settings specified here will take precedence over those in config/application.rb. - config.hosts << "grid-api.ngrok.io" + # In the development environment your application's code is reloaded any time + # it changes. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false - # In the development environment your application's code is reloaded on - # every request. This slows down response time but is perfect for development - # since you don't have to restart the web server when you make code changes. - config.cache_classes = false + # Do not eager load code on boot. + config.eager_load = false - # Do not eager load code on boot. - config.eager_load = false + # Show full error reports. + config.consider_all_requests_local = true - # Show full error reports. - config.consider_all_requests_local = true + # Enable server timing + config.server_timing = true - # Enable/disable caching. By default caching is disabled. - # Run rails dev:cache to toggle caching. - if Rails.root.join('tmp', 'caching-dev.txt').exist? - config.cache_store = :memory_store - config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.to_i}" - } - else - config.action_controller.perform_caching = false + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join("tmp/caching-dev.txt").exist? + config.cache_store = :memory_store + config.public_file_server.headers = { + "Cache-Control" => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false - config.cache_store = :null_store - end - - config.action_controller.allow_forgery_protection = false + config.cache_store = :null_store + end - # Store uploaded files on the local file system (see config/storage.yml for options). - config.active_storage.service = :local + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local - # Don't care if the mailer can't send. - # config.action_mailer.raise_delivery_errors = false + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log - # config.action_mailer.perform_caching = false + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise - # Print deprecation notices to the Rails logger. - config.active_support.deprecation = :log + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] - # Raise an error on page load if there are pending migrations. - config.active_record.migration_error = :page_load + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load - # Highlight code that triggered database queries in logs. - config.active_record.verbose_query_logs = true + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true - # Raises error for missing translations. - # config.action_view.raise_on_missing_translations = true + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true - # Use an evented file watcher to asynchronously detect changes in source code, - # routes, locales, etc. This feature depends on the listen gem. - config.file_watcher = ActiveSupport::EventedFileUpdateChecker + # Uncomment if you wish to allow Action Cable access from any origin. + # config.action_cable.disable_request_forgery_protection = true end diff --git a/config/environments/production.rb b/config/environments/production.rb index c70ea32..bf24f9a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,3 +1,5 @@ +require "active_support/core_ext/integer/time" + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -11,9 +13,7 @@ Rails.application.configure do config.eager_load = true # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false - - config.action_controller.allow_forgery_protection = false + config.consider_all_requests_local = false # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). @@ -21,32 +21,32 @@ Rails.application.configure do # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = 'http://assets.example.com' + # config.asset_host = "http://assets.example.com" # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache + # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local # Mount Action Cable outside main process or domain. # config.action_cable.mount_path = nil - # config.action_cable.url = 'wss://example.com/cable' - # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + # config.action_cable.url = "wss://example.com/cable" + # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true - # Use the lowest log level to ensure availability of diagnostic information - # when problems arise. - config.log_level = :debug + # Include generic and useful information about system operation, but avoid logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). + config.log_level = :info # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -55,53 +55,26 @@ Rails.application.configure do # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "hensei_api_production" - # config.action_mailer.perform_caching = false - - # Ignore bad email addresses and do not raise email delivery errors. - # Set this to true and configure the email server for immediate delivery to raise delivery errors. - # config.action_mailer.raise_delivery_errors = false - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true - # Send deprecation notices to registered listeners. - config.active_support.deprecation = :notify + # Don't log any deprecations. + config.active_support.report_deprecations = false # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Use a different logger for distributed setups. - # require 'syslog/logger' - # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + # require "syslog/logger" + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) + logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) + config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false - - # Inserts middleware to perform automatic connection switching. - # The `database_selector` hash is used to pass options to the DatabaseSelector - # middleware. The `delay` is used to determine how long to wait after a write - # to send a subsequent read to the primary. - # - # The `database_resolver` class is used by the middleware to determine which - # database is appropriate to use based on the time delay. - # - # The `database_resolver_context` class is used by the middleware to set - # timestamps for the last write to the primary. The resolver uses the context - # class timestamps to determine how long to wait before reading from the - # replica. - # - # By default Rails will store a last write timestamp in the session. The - # DatabaseSelector middleware is designed as such you can define your own - # strategy for connection switching and pass that into the middleware through - # these configuration options. - # config.active_record.database_selector = { delay: 2.seconds } - # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver - # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session end diff --git a/config/environments/test.rb b/config/environments/test.rb index 0cb2424..8b5160c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,3 +1,5 @@ +require "active_support/core_ext/integer/time" + # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped @@ -6,18 +8,18 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - config.cache_classes = false - config.action_view.cache_template_loading = true + # Turn false under Spring and add config.action_view.cache_template_loading = true. + config.cache_classes = true - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. - config.eager_load = false + # Eager loading loads your whole application. When running a single test locally, + # this probably isn't necessary. It's a good idea to do in a continuous integration + # system, or in some way before deploying your code. + config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + "Cache-Control" => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. @@ -34,16 +36,18 @@ Rails.application.configure do # Store uploaded files on the local file system in a temporary directory. config.active_storage.service = :test - config.action_mailer.perform_caching = false - - # Tell Action Mailer not to deliver emails to the real world. - # The :test delivery method accumulates sent emails in the - # ActionMailer::Base.deliveries array. - config.action_mailer.delivery_method = :test - # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + # Raises error for missing translations. - # config.action_view.raise_on_missing_translations = true + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true end diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb index 3742905..7d7e544 100644 --- a/config/initializers/cors.rb +++ b/config/initializers/cors.rb @@ -10,11 +10,11 @@ Rails.application.config.middleware.insert_before 0, Rack::Cors do if Rails.env.production? origins %w[app.granblue.team hensei-web-production.up.railway.app] else - origins %w[127.0.0.1:1234 grid.ngrok.io] + origins %w[staging.granblue.team 127.0.0.1:1234] end - resource '*', + resource "*", headers: :any, - methods: %i[get post put patch delete options head] + methods: [:get, :post, :put, :patch, :delete, :options, :head] end end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 4a994e1..adc6568 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,8 @@ # Be sure to restart your server when you modify this file. -# Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += [:password] +# Configure parameters to be filtered from the log file. Use this to limit dissemination of +# sensitive information. See the ActiveSupport::ParameterFilter documentation for supported +# notations and behaviors. +Rails.application.config.filter_parameters += [ + :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ac033bf..3860f65 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -4,13 +4,13 @@ # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.plural /^(ox)$/i, '\1en' -# inflect.singular /^(ox)en/i, '\1' -# inflect.irregular 'person', 'people' +# inflect.plural /^(ox)$/i, "\\1en" +# inflect.singular /^(ox)en/i, "\\1" +# inflect.irregular "person", "people" # inflect.uncountable %w( fish sheep ) # end # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.acronym 'RESTful' +# inflect.acronym "RESTful" # end diff --git a/config/initializers/new_framework_defaults_7_0.rb b/config/initializers/new_framework_defaults_7_0.rb new file mode 100644 index 0000000..4d58024 --- /dev/null +++ b/config/initializers/new_framework_defaults_7_0.rb @@ -0,0 +1,135 @@ +# Be sure to restart your server when you modify this file. +# +# This file eases your Rails 7.0 framework defaults upgrade. +# +# Uncomment each configuration one by one to switch to the new default. +# Once your application is ready to run with all new defaults, you can remove +# this file and set the `config.load_defaults` to `7.0`. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. +# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html + +# `button_to` view helper will render `