From 986ef2fb5637d460e78eb9d608fec8736703fb08 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 27 Jan 2023 23:33:28 -0800 Subject: [PATCH 1/4] Add remix state and remixes to output --- app/blueprints/api/v1/party_blueprint.rb | 8 ++++++++ app/models/party.rb | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/blueprints/api/v1/party_blueprint.rb b/app/blueprints/api/v1/party_blueprint.rb index 0d118b1..a6bb8fe 100644 --- a/app/blueprints/api/v1/party_blueprint.rb +++ b/app/blueprints/api/v1/party_blueprint.rb @@ -36,6 +36,10 @@ module Api fields :name, :element, :shortcode, :favorited, :extra, :full_auto, :clear_time, :auto_guard, :created_at, :updated_at + field :remix do |p| + p.is_remix + end + association :raid, blueprint: RaidBlueprint @@ -45,6 +49,10 @@ module Api association :user, blueprint: UserBlueprint, view: :minimal + + association :remixes, + blueprint: PartyBlueprint, + view: :minimal end view :jobs do diff --git a/app/models/party.rb b/app/models/party.rb index 1b99313..6e52a5d 100644 --- a/app/models/party.rb +++ b/app/models/party.rb @@ -20,7 +20,7 @@ class Party < ApplicationRecord foreign_key: 'accessory_id', class_name: 'JobAccessory', optional: true - + belongs_to :skill0, foreign_key: 'skill0_id', class_name: 'JobSkill', @@ -82,6 +82,14 @@ class Party < ApplicationRecord user.favorite_parties.include? self end + def is_remix + self.source_party != nil + end + + def remixes + Party.where(source_party_id: self.id) + end + def blueprint PartyBlueprint end From 906faaeb1e676c28aebd71c976d2c07a09d2f38d Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 28 Jan 2023 00:01:40 -0800 Subject: [PATCH 2/4] Change view for remixes --- app/blueprints/api/v1/party_blueprint.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/blueprints/api/v1/party_blueprint.rb b/app/blueprints/api/v1/party_blueprint.rb index a6bb8fe..005bcb8 100644 --- a/app/blueprints/api/v1/party_blueprint.rb +++ b/app/blueprints/api/v1/party_blueprint.rb @@ -50,9 +50,10 @@ module Api blueprint: UserBlueprint, view: :minimal + # TODO: This should probably be paginated association :remixes, blueprint: PartyBlueprint, - view: :minimal + view: :collection end view :jobs do From 2c4d8b6fe16dc77708a9c9393418374320dd6a24 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 28 Jan 2023 00:23:06 -0800 Subject: [PATCH 3/4] Add source party to output --- app/blueprints/api/v1/party_blueprint.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/blueprints/api/v1/party_blueprint.rb b/app/blueprints/api/v1/party_blueprint.rb index 005bcb8..7424320 100644 --- a/app/blueprints/api/v1/party_blueprint.rb +++ b/app/blueprints/api/v1/party_blueprint.rb @@ -49,11 +49,6 @@ module Api association :user, blueprint: UserBlueprint, view: :minimal - - # TODO: This should probably be paginated - association :remixes, - blueprint: PartyBlueprint, - view: :collection end view :jobs do @@ -76,6 +71,15 @@ module Api association :accessory, blueprint: JobAccessoryBlueprint fields :description, :charge_attack, :button_count, :turn_count, :chain_count + + association :source_party, + blueprint: PartyBlueprint, + view: :minimal + + # TODO: This should probably be paginated + association :remixes, + blueprint: PartyBlueprint, + view: :collection end view :collection do From 6c084610addf46f3881d7d90787899e252dedfab Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 28 Jan 2023 01:19:46 -0800 Subject: [PATCH 4/4] Fix counter caches --- app/models/grid_character.rb | 2 +- app/models/grid_summon.rb | 2 +- ...230128091710_add_character_and_summon_counts_to_party.rb | 6 ++++++ db/schema.rb | 6 +++++- 4 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20230128091710_add_character_and_summon_counts_to_party.rb diff --git a/app/models/grid_character.rb b/app/models/grid_character.rb index 733fe00..7b5a8fb 100644 --- a/app/models/grid_character.rb +++ b/app/models/grid_character.rb @@ -2,7 +2,7 @@ class GridCharacter < ApplicationRecord belongs_to :party, - counter_cache: :weapons_count, + counter_cache: :characters_count, inverse_of: :characters validates_presence_of :party diff --git a/app/models/grid_summon.rb b/app/models/grid_summon.rb index 7da4930..945bea5 100644 --- a/app/models/grid_summon.rb +++ b/app/models/grid_summon.rb @@ -2,7 +2,7 @@ class GridSummon < ApplicationRecord belongs_to :party, - counter_cache: :weapons_count, + counter_cache: :summons_count, inverse_of: :summons validates_presence_of :party diff --git a/db/migrate/20230128091710_add_character_and_summon_counts_to_party.rb b/db/migrate/20230128091710_add_character_and_summon_counts_to_party.rb new file mode 100644 index 0000000..dfd901b --- /dev/null +++ b/db/migrate/20230128091710_add_character_and_summon_counts_to_party.rb @@ -0,0 +1,6 @@ +class AddCharacterAndSummonCountsToParty < ActiveRecord::Migration[7.0] + def change + add_column :parties, :characters_count, :integer + add_column :parties, :summons_count, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index fc58d23..2f26c93 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_26_040207) do +ActiveRecord::Schema[7.0].define(version: 2023_01_28_091710) do # These are extensions that must be enabled in order to support this database enable_extension "btree_gin" enable_extension "pg_trgm" @@ -154,6 +154,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_26_040207) do t.integer "order" t.uuid "base_job_id" t.string "granblue_id" + t.boolean "accessory", default: false + t.integer "accessory_type", default: 0 t.index ["base_job_id"], name: "index_jobs_on_base_job_id" end @@ -221,6 +223,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_26_040207) do t.integer "turn_count" t.uuid "source_party_id" t.uuid "accessory_id" + t.integer "characters_count" + t.integer "summons_count" t.index ["accessory_id"], name: "index_parties_on_accessory_id" t.index ["job_id"], name: "index_parties_on_job_id" t.index ["skill0_id"], name: "index_parties_on_skill0_id"