diff --git a/app/blueprints/api/v1/raid_group_blueprint.rb b/app/blueprints/api/v1/raid_group_blueprint.rb new file mode 100644 index 0000000..3052ca4 --- /dev/null +++ b/app/blueprints/api/v1/raid_group_blueprint.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Api + module V1 + class RaidGroupBlueprint < ApiBlueprint + field :name do |group| + { + en: group.name_en, + ja: group.name_jp + } + end + + fields :difficulty, :order, :section, :extra, :hl + + association :raids, blueprint: RaidBlueprint, view: :nested + end + end +end diff --git a/app/models/raid_group.rb b/app/models/raid_group.rb new file mode 100644 index 0000000..3c1010b --- /dev/null +++ b/app/models/raid_group.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class RaidGroup < ApplicationRecord + has_many :raids, class_name: 'Raid', foreign_key: :group_id + + def blueprint + RaidGroupBlueprint + end +end diff --git a/db/migrate/20230529210259_add_raid_groups_table.rb b/db/migrate/20230529210259_add_raid_groups_table.rb new file mode 100644 index 0000000..593b5db --- /dev/null +++ b/db/migrate/20230529210259_add_raid_groups_table.rb @@ -0,0 +1,10 @@ +class AddRaidGroupsTable < ActiveRecord::Migration[7.0] + create_table :raid_groups, id: :uuid, default: -> { "gen_random_uuid()" } do |t| + t.string :name_en, null: false + t.string :name_jp, null: false + t.integer :difficulty + t.integer :order, null: false + t.integer :section, default: 1, null: false + t.boolean :extra, default: false, null: false + end +end diff --git a/db/migrate/20230529215259_add_raid_group_to_raids.rb b/db/migrate/20230529215259_add_raid_group_to_raids.rb new file mode 100644 index 0000000..e708a20 --- /dev/null +++ b/db/migrate/20230529215259_add_raid_group_to_raids.rb @@ -0,0 +1,6 @@ +class AddRaidGroupToRaids < ActiveRecord::Migration[7.0] + def change + add_reference :raids, :group, null: true, to_table: 'raid_groups', type: :uuid + add_foreign_key :raids, :raid_groups, column: :group_id + end +end diff --git a/db/migrate/20230530000739_add_hl_to_raid_groups.rb b/db/migrate/20230530000739_add_hl_to_raid_groups.rb new file mode 100644 index 0000000..c302776 --- /dev/null +++ b/db/migrate/20230530000739_add_hl_to_raid_groups.rb @@ -0,0 +1,5 @@ +class AddHlToRaidGroups < ActiveRecord::Migration[7.0] + def change + add_column :raid_groups, :hl, :boolean, default: true, null: false + end +end diff --git a/db/migrate/20230531115422_remove_group_integer_from_raids.rb b/db/migrate/20230531115422_remove_group_integer_from_raids.rb new file mode 100644 index 0000000..e315719 --- /dev/null +++ b/db/migrate/20230531115422_remove_group_integer_from_raids.rb @@ -0,0 +1,5 @@ +class RemoveGroupIntegerFromRaids < ActiveRecord::Migration[7.0] + def change + remove_column :raids, :group, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index ad74e64..658b336 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_05_03_224353) do +ActiveRecord::Schema[7.0].define(version: 2023_05_31_115422) do # These are extensions that must be enabled in order to support this database enable_extension "btree_gin" enable_extension "pg_trgm" @@ -345,13 +345,24 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_03_224353) do t.index ["user_id"], name: "index_parties_on_user_id" end + create_table "raid_groups", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "name_en", null: false + t.string "name_jp", null: false + t.integer "difficulty" + t.integer "order", null: false + t.integer "section", default: 1, null: false + t.boolean "extra", default: false, null: false + t.boolean "hl", default: true, null: false + 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" + t.uuid "group_id" + t.index ["group_id"], name: "index_raids_on_group_id" end create_table "sparks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -479,4 +490,5 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_03_224353) do add_foreign_key "parties", "parties", column: "source_party_id" add_foreign_key "parties", "raids" add_foreign_key "parties", "users" + add_foreign_key "raids", "raid_groups", column: "group_id" end