diff --git a/app/blueprints/api/v1/party_blueprint.rb b/app/blueprints/api/v1/party_blueprint.rb index 6b8e19f..556188d 100644 --- a/app/blueprints/api/v1/party_blueprint.rb +++ b/app/blueprints/api/v1/party_blueprint.rb @@ -40,6 +40,14 @@ module Api p.is_remix end + field :guidebooks do |p| + { + '0' => !p.guidebook0.nil? ? GuidebookBlueprint.render_as_hash(p.guidebook0) : nil, + '1' => !p.guidebook1.nil? ? GuidebookBlueprint.render_as_hash(p.guidebook1) : nil, + '2' => !p.guidebook2.nil? ? GuidebookBlueprint.render_as_hash(p.guidebook2) : nil + } + end + association :raid, blueprint: RaidBlueprint diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index 5767706..44f8e6b 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -241,6 +241,8 @@ module Api end def party_params + ap "Params are..." + ap params return unless params[:party].present? params.require(:party).permit( @@ -263,7 +265,10 @@ module Api :clear_time, :button_count, :turn_count, - :chain_count + :chain_count, + :guidebook0_id, + :guidebook1_id, + :guidebook2_id ) end end diff --git a/app/models/party.rb b/app/models/party.rb index 8345471..3bbc2e0 100644 --- a/app/models/party.rb +++ b/app/models/party.rb @@ -41,6 +41,21 @@ class Party < ApplicationRecord class_name: 'JobSkill', optional: true + belongs_to :guidebook0, + foreign_key: 'guidebook0_id', + class_name: 'Guidebook', + optional: true + + belongs_to :guidebook1, + foreign_key: 'guidebook1_id', + class_name: 'Guidebook', + optional: true + + belongs_to :guidebook2, + foreign_key: 'guidebook2_id', + class_name: 'Guidebook', + optional: true + has_many :characters, foreign_key: 'party_id', class_name: 'GridCharacter', diff --git a/db/migrate/20230418071647_rename_guidebooks_to_guidebook_i_ds.rb b/db/migrate/20230418071647_rename_guidebooks_to_guidebook_i_ds.rb new file mode 100644 index 0000000..7b80062 --- /dev/null +++ b/db/migrate/20230418071647_rename_guidebooks_to_guidebook_i_ds.rb @@ -0,0 +1,5 @@ +class RenameGuidebooksToGuidebookIDs < ActiveRecord::Migration[7.0] + def change + rename_column :parties, :guidebooks, :guidebook_ids + end +end diff --git a/db/migrate/20230419033648_split_guidebooks_on_party.rb b/db/migrate/20230419033648_split_guidebooks_on_party.rb new file mode 100644 index 0000000..08dc2d2 --- /dev/null +++ b/db/migrate/20230419033648_split_guidebooks_on_party.rb @@ -0,0 +1,8 @@ +class SplitGuidebooksOnParty < ActiveRecord::Migration[7.0] + def change + remove_column :parties, :guidebook_ids + add_reference :parties, :guidebook0, type: :uuid, foreign_key: { to_table: :guidebooks } + add_reference :parties, :guidebook1, type: :uuid, foreign_key: { to_table: :guidebooks } + add_reference :parties, :guidebook2, type: :uuid, foreign_key: { to_table: :guidebooks } + end +end diff --git a/db/schema.rb b/db/schema.rb index 0430cc4..903c657 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_04_18_061932) do +ActiveRecord::Schema[7.0].define(version: 2023_04_19_033648) do # These are extensions that must be enabled in order to support this database enable_extension "btree_gin" enable_extension "pg_trgm" @@ -306,8 +306,13 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_18_061932) do t.string "edit_key" t.uuid "local_id" t.integer "ultimate_mastery" - t.uuid "guidebooks", default: [], null: false, array: true + t.uuid "guidebook0_id" + t.uuid "guidebook1_id" + t.uuid "guidebook2_id" t.index ["accessory_id"], name: "index_parties_on_accessory_id" + t.index ["guidebook0_id"], name: "index_parties_on_guidebook0_id" + t.index ["guidebook1_id"], name: "index_parties_on_guidebook1_id" + t.index ["guidebook2_id"], name: "index_parties_on_guidebook2_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" @@ -423,6 +428,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_18_061932) do 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", "guidebooks", column: "guidebook0_id" + add_foreign_key "parties", "guidebooks", column: "guidebook1_id" + add_foreign_key "parties", "guidebooks", column: "guidebook2_id" add_foreign_key "parties", "job_accessories", column: "accessory_id" add_foreign_key "parties", "job_skills", column: "skill0_id" add_foreign_key "parties", "job_skills", column: "skill1_id"