Support for Siero, raids rework and edit party rework (#96)

* Add guidebooks migration

* Implement business logic for reading Guidebooks

* Change to individual guidebook columns

* Properly output guidebook description

* Move to 1-index guidebooks

* Update party-related files for 1-index guidebooks

* Add tables for Siero

* Add raid groups table

* Update raid model

To belong to the RaidGroup class

* Update job class

To have many job skills

* Add endpoint for raid groups

* Update Raid blueprint with views

* Added down for creating table

* Add guidebooks flag and auto summon flag

* Guidebooks → RaidGroup
* Auto summon → Party

* Add views to Raid blueprint

* Add views and guidebook flag to RaidGroup blueprint

* Add auto summon and Raid view to Party blueprint
This commit is contained in:
Justin Edmund 2023-06-18 02:07:57 -07:00
parent 85379b0dea
commit 1e213f01a2
16 changed files with 132 additions and 12 deletions

View file

@ -34,7 +34,8 @@ module Api
view :minimal do
fields :name, :element, :shortcode, :favorited, :extra,
:full_auto, :clear_time, :auto_guard, :created_at, :updated_at
:full_auto, :clear_time, :auto_guard, :auto_summon,
:created_at, :updated_at
field :remix do |p|
p.is_remix
@ -49,7 +50,8 @@ module Api
end
association :raid,
blueprint: RaidBlueprint
blueprint: RaidBlueprint,
view: :full
association :job,
blueprint: JobBlueprint

View file

@ -3,14 +3,21 @@
module Api
module V1
class RaidBlueprint < ApiBlueprint
field :name do |raid|
{
en: raid.name_en,
ja: raid.name_jp
}
view :nested do
field :name do |raid|
{
en: raid.name_en,
ja: raid.name_jp
}
end
fields :slug, :level, :element
end
fields :slug, :level, :group, :element
view :full do
include_view :nested
association :group, blueprint: RaidGroupBlueprint, view: :flat
end
end
end
end

View file

@ -0,0 +1,23 @@
# frozen_string_literal: true
module Api
module V1
class RaidGroupBlueprint < ApiBlueprint
view :flat do
field :name do |group|
{
en: group.name_en,
ja: group.name_jp
}
end
fields :difficulty, :order, :section, :extra, :guidebooks, :hl
end
view :full do
include_view :flat
association :raids, blueprint: RaidBlueprint, view: :full
end
end
end
end

View file

@ -56,7 +56,7 @@ module Api
# TODO: Validate accessory with job
return render json: PartyBlueprint.render(@party, view: :full, root: :party) if @party.save
render_validation_error_response(@party)
end
@ -259,6 +259,7 @@ module Api
:skill3_id,
:full_auto,
:auto_guard,
:auto_summon,
:charge_attack,
:clear_time,
:button_count,

View file

@ -4,7 +4,11 @@ module Api
module V1
class RaidsController < Api::V1::ApiController
def all
render json: RaidBlueprint.render(Raid.all)
render json: RaidBlueprint.render(Raid.all, view: :full)
end
def groups
render json: RaidGroupBlueprint.render(RaidGroup.all, view: :full)
end
end
end

View file

@ -2,6 +2,7 @@
class Job < ApplicationRecord
belongs_to :party
has_many :skills, class_name: 'JobSkill'
belongs_to :base_job,
foreign_key: 'base_job_id',

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
class Raid < ApplicationRecord
belongs_to :group, class_name: 'RaidGroup', foreign_key: :group_id
def blueprint
RaidBlueprint
end

9
app/models/raid_group.rb Normal file
View file

@ -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

View file

@ -45,6 +45,7 @@ Rails.application.routes.draw do
get 'guidebooks', to: 'guidebooks#all'
get 'raids', to: 'raids#all'
get 'raids/groups', to: 'raids#groups'
get 'weapon_keys', to: 'weapon_keys#all'
post 'characters', to: 'grid_characters#create'

View file

@ -0,0 +1,16 @@
class AddRaidGroupsTable < ActiveRecord::Migration[7.0]
def up
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
def down
drop_table :raid_groups
end
end

View file

@ -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

View file

@ -0,0 +1,5 @@
class AddHlToRaidGroups < ActiveRecord::Migration[7.0]
def change
add_column :raid_groups, :hl, :boolean, default: true, null: false
end
end

View file

@ -0,0 +1,5 @@
class RemoveGroupIntegerFromRaids < ActiveRecord::Migration[7.0]
def change
remove_column :raids, :group, :integer
end
end

View file

@ -0,0 +1,5 @@
class AddGuidebooksToRaidGroups < ActiveRecord::Migration[7.0]
def change
add_column :raid_groups, :guidebooks, :boolean, default: false, null: false
end
end

View file

@ -0,0 +1,5 @@
class AddAutoSummonToParties < ActiveRecord::Migration[7.0]
def change
add_column :parties, :auto_summon, :boolean, default: false, null: false
end
end

View file

@ -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_06_18_051638) do
# These are extensions that must be enabled in order to support this database
enable_extension "btree_gin"
enable_extension "pg_trgm"
@ -332,6 +332,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_03_224353) do
t.uuid "guidebook3_id"
t.uuid "guidebook1_id"
t.uuid "guidebook2_id"
t.boolean "auto_summon", default: false, null: false
t.index ["accessory_id"], name: "index_parties_on_accessory_id"
t.index ["guidebook1_id"], name: "index_parties_on_guidebook1_id"
t.index ["guidebook2_id"], name: "index_parties_on_guidebook2_id"
@ -345,13 +346,39 @@ 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
t.boolean "guidebooks", default: false, 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|
t.string "user_id", null: false
t.string "guild_ids", null: false, array: true
t.integer "crystals", default: 0
t.integer "tickets", default: 0
t.integer "ten_tickets", default: 0
t.string "target_type"
t.bigint "target_id"
t.datetime "updated_at", default: -> { "CURRENT_TIMESTAMP" }, null: false
t.string "target_memo"
t.index ["target_type", "target_id"], name: "index_sparks_on_target"
t.index ["user_id"], name: "index_sparks_on_user_id", unique: true
end
create_table "sparks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
@ -479,4 +506,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