Add all blueprints and associate with models
This commit is contained in:
parent
c102d68dd7
commit
e541182e36
25 changed files with 407 additions and 0 deletions
68
app/blueprints/api/v1/character_blueprint.rb
Normal file
68
app/blueprints/api/v1/character_blueprint.rb
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class CharacterBlueprint < ApiBlueprint
|
||||
fields :id, :granblue_id, :character_id, :rarity,
|
||||
:element, :gender, :special
|
||||
|
||||
field :name do |w|
|
||||
{
|
||||
en: w.name_en,
|
||||
ja: w.name_jp
|
||||
}
|
||||
end
|
||||
|
||||
field :uncap do |w|
|
||||
{
|
||||
flb: w.flb,
|
||||
ulb: w.ulb
|
||||
}
|
||||
end
|
||||
|
||||
field :hp do |w|
|
||||
{
|
||||
min_hp: w.min_hp,
|
||||
max_hp: w.max_hp,
|
||||
max_hp_flb: w.max_hp_flb
|
||||
}
|
||||
end
|
||||
|
||||
field :atk do |w|
|
||||
{
|
||||
min_atk: w.min_atk,
|
||||
max_atk: w.max_atk,
|
||||
max_atk_flb: w.max_atk_flb
|
||||
}
|
||||
end
|
||||
|
||||
field :race do |w|
|
||||
[
|
||||
w.race1,
|
||||
w.race2
|
||||
]
|
||||
end
|
||||
|
||||
field :proficiency do |w|
|
||||
[
|
||||
w.proficiency1,
|
||||
w.proficiency2
|
||||
]
|
||||
end
|
||||
|
||||
field :data do |w|
|
||||
{
|
||||
base_da: w.base_da,
|
||||
base_ta: w.base_ta
|
||||
}
|
||||
end
|
||||
|
||||
field :ougi_ratio do |w|
|
||||
{
|
||||
ougi_ratio: w.ougi_ratio,
|
||||
ougi_ratio_flb: w.ougi_ratio_flb
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
16
app/blueprints/api/v1/grid_character_blueprint.rb
Normal file
16
app/blueprints/api/v1/grid_character_blueprint.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class GridCharacterBlueprint < ApiBlueprint
|
||||
view :nested do
|
||||
fields :id, :position, :uncap_level, :perpetuity
|
||||
association :character, name: :object, blueprint: CharacterBlueprint
|
||||
end
|
||||
|
||||
view :full do
|
||||
fields :party_id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
16
app/blueprints/api/v1/grid_summon_blueprint.rb
Normal file
16
app/blueprints/api/v1/grid_summon_blueprint.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class GridSummonBlueprint < ApiBlueprint
|
||||
view :nested do
|
||||
fields :id, :main, :friend, :position, :uncap_level
|
||||
association :summon, name: :object, blueprint: SummonBlueprint
|
||||
end
|
||||
|
||||
view :full do
|
||||
fields :party_id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
35
app/blueprints/api/v1/grid_weapon_blueprint.rb
Normal file
35
app/blueprints/api/v1/grid_weapon_blueprint.rb
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class GridWeaponBlueprint < ApiBlueprint
|
||||
view :nested do
|
||||
fields :id, :mainhand, :position, :uncap_level, :element
|
||||
association :weapon, name: :object, blueprint: WeaponBlueprint
|
||||
|
||||
association :weapon_keys,
|
||||
blueprint: WeaponKeyBlueprint,
|
||||
if: lambda { |_field_name, w, _options|
|
||||
[2, 3, 17, 22].include?(w.weapon.series)
|
||||
}
|
||||
|
||||
field :ax, if: ->(_field_name, w, _options) { w.weapon.ax.positive? } do |w|
|
||||
[
|
||||
{
|
||||
modifier: w.ax_modifier1,
|
||||
strength: w.ax_strength1
|
||||
},
|
||||
{
|
||||
modifier: w.ax_modifier2,
|
||||
strength: w.ax_strength2
|
||||
}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
view :full do
|
||||
fields :party_id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
23
app/blueprints/api/v1/job_blueprint.rb
Normal file
23
app/blueprints/api/v1/job_blueprint.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class JobBlueprint < ApiBlueprint
|
||||
fields :id, :row, :ml, :order
|
||||
|
||||
field :name do |job|
|
||||
{
|
||||
en: job.name_en,
|
||||
ja: job.name_jp
|
||||
}
|
||||
end
|
||||
|
||||
field :proficiency do |job|
|
||||
[
|
||||
job.proficiency1,
|
||||
job.proficiency2
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
20
app/blueprints/api/v1/job_skill_blueprint.rb
Normal file
20
app/blueprints/api/v1/job_skill_blueprint.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class JobSkillBlueprint < ApiBlueprint
|
||||
fields :id, :slug, :color, :main, :base, :sub, :emp, :order
|
||||
|
||||
association :job,
|
||||
name: :job,
|
||||
blueprint: JobBlueprint
|
||||
|
||||
field :name do |skill|
|
||||
{
|
||||
en: skill.name_en,
|
||||
ja: skill.name_jp
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
43
app/blueprints/api/v1/party_blueprint.rb
Normal file
43
app/blueprints/api/v1/party_blueprint.rb
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class PartyBlueprint < ApiBlueprint
|
||||
view :preview do
|
||||
fields :id, :name, :element, :shortcode, :favorited, :extra, :created_at, :updated_at
|
||||
|
||||
association :raid,
|
||||
blueprint: RaidBlueprint
|
||||
|
||||
association :job,
|
||||
blueprint: JobBlueprint
|
||||
|
||||
association :weapons,
|
||||
blueprint: GridWeaponBlueprint,
|
||||
view: :nested
|
||||
end
|
||||
|
||||
view :full do
|
||||
include_view :preview
|
||||
fields :description, :extra
|
||||
|
||||
field :job_skills do |job|
|
||||
{
|
||||
'0' => !job.skill0.nil? ? JobSkillBlueprint.render_as_hash(job.skill0) : nil,
|
||||
'1' => !job.skill1.nil? ? JobSkillBlueprint.render_as_hash(job.skill1) : nil,
|
||||
'2' => !job.skill2.nil? ? JobSkillBlueprint.render_as_hash(job.skill2) : nil,
|
||||
'3' => !job.skill3.nil? ? JobSkillBlueprint.render_as_hash(job.skill3) : nil
|
||||
}
|
||||
end
|
||||
|
||||
association :characters,
|
||||
blueprint: GridCharacterBlueprint,
|
||||
view: :nested
|
||||
|
||||
association :summons,
|
||||
blueprint: GridSummonBlueprint,
|
||||
view: :nested
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
15
app/blueprints/api/v1/raid_blueprint.rb
Normal file
15
app/blueprints/api/v1/raid_blueprint.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class RaidBlueprint < ApiBlueprint
|
||||
fields :id, :slug, :level, :group, :element
|
||||
field :name do |raid|
|
||||
{
|
||||
en: raid.name_en,
|
||||
ja: raid.name_jp
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
41
app/blueprints/api/v1/summon_blueprint.rb
Normal file
41
app/blueprints/api/v1/summon_blueprint.rb
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class SummonBlueprint < ApiBlueprint
|
||||
fields :id, :granblue_id, :element, :rarity, :max_level
|
||||
|
||||
field :name do |w|
|
||||
{
|
||||
en: w.name_en,
|
||||
ja: w.name_jp
|
||||
}
|
||||
end
|
||||
|
||||
field :uncap do |w|
|
||||
{
|
||||
flb: w.flb,
|
||||
ulb: w.ulb
|
||||
}
|
||||
end
|
||||
|
||||
field :hp do |w|
|
||||
{
|
||||
min_hp: w.min_hp,
|
||||
max_hp: w.max_hp,
|
||||
max_hp_flb: w.max_hp_flb,
|
||||
max_hp_ulb: w.max_hp_ulb
|
||||
}
|
||||
end
|
||||
|
||||
field :atk do |w|
|
||||
{
|
||||
min_atk: w.min_atk,
|
||||
max_atk: w.max_atk,
|
||||
max_atk_flb: w.max_atk_flb,
|
||||
max_atk_ulb: w.max_atk_ulb
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
29
app/blueprints/api/v1/user_blueprint.rb
Normal file
29
app/blueprints/api/v1/user_blueprint.rb
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class UserBlueprint < ApiBlueprint
|
||||
view :minimal do
|
||||
fields :username, :language, :private, :gender
|
||||
field :avatar do |user|
|
||||
{
|
||||
picture: user.picture,
|
||||
element: user.element
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
view :profile do
|
||||
association :parties,
|
||||
name: :parties,
|
||||
blueprint: PartyBlueprint, view: :preview,
|
||||
if: ->(_field_name, user, _options) { user.parties.length.positive? },
|
||||
&:parties
|
||||
end
|
||||
|
||||
view :settings do
|
||||
fields :email
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
43
app/blueprints/api/v1/weapon_blueprint.rb
Normal file
43
app/blueprints/api/v1/weapon_blueprint.rb
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class WeaponBlueprint < ApiBlueprint
|
||||
fields :id, :granblue_id, :element, :proficiency,
|
||||
:max_level, :max_skill_level, :limit, :rarity,
|
||||
:series, :ax
|
||||
|
||||
field :name do |w|
|
||||
{
|
||||
en: w.name_en,
|
||||
ja: w.name_jp
|
||||
}
|
||||
end
|
||||
|
||||
field :uncap do |w|
|
||||
{
|
||||
flb: w.flb,
|
||||
ulb: w.ulb
|
||||
}
|
||||
end
|
||||
|
||||
field :hp do |w|
|
||||
{
|
||||
min_hp: w.min_hp,
|
||||
max_hp: w.max_hp,
|
||||
max_hp_flb: w.max_hp_flb,
|
||||
max_hp_ulb: w.max_hp_ulb
|
||||
}
|
||||
end
|
||||
|
||||
field :atk do |w|
|
||||
{
|
||||
min_atk: w.min_atk,
|
||||
max_atk: w.max_atk,
|
||||
max_atk_flb: w.max_atk_flb,
|
||||
max_atk_ulb: w.max_atk_ulb
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
8
app/blueprints/api/v1/weapon_key_blueprint.rb
Normal file
8
app/blueprints/api/v1/weapon_key_blueprint.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class WeaponKeyBlueprint < ApiBlueprint
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -20,6 +20,10 @@ class Character < ApplicationRecord
|
|||
}
|
||||
}
|
||||
|
||||
def blueprint
|
||||
CharacterBlueprint
|
||||
end
|
||||
|
||||
def display_resource(character)
|
||||
character.name_en
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,4 +7,8 @@ class Favorite < ApplicationRecord
|
|||
def party
|
||||
Party.find(party_id)
|
||||
end
|
||||
|
||||
def favorite
|
||||
FavoriteBlueprint
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,4 +6,8 @@ class GridCharacter < ApplicationRecord
|
|||
def character
|
||||
Character.find(character_id)
|
||||
end
|
||||
|
||||
def blueprint
|
||||
GridCharacterBlueprint
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,4 +6,8 @@ class GridSummon < ApplicationRecord
|
|||
def summon
|
||||
Summon.find(summon_id)
|
||||
end
|
||||
|
||||
def blueprint
|
||||
GridSummonBlueprint
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,4 +20,8 @@ class GridWeapon < ApplicationRecord
|
|||
|
||||
weapon_keys
|
||||
end
|
||||
|
||||
def blueprint
|
||||
GridWeaponBlueprint
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ class Job < ApplicationRecord
|
|||
class_name: 'Job',
|
||||
optional: true
|
||||
|
||||
def blueprint
|
||||
JobBlueprint
|
||||
end
|
||||
|
||||
def display_resource(job)
|
||||
job.name_en
|
||||
end
|
||||
|
|
|
|||
|
|
@ -25,6 +25,10 @@ class JobSkill < ApplicationRecord
|
|||
}
|
||||
}
|
||||
|
||||
def blueprint
|
||||
JobSkillBlueprint
|
||||
end
|
||||
|
||||
def display_resource(skill)
|
||||
skill.name_en
|
||||
end
|
||||
|
|
|
|||
|
|
@ -52,6 +52,10 @@ class Party < ApplicationRecord
|
|||
user.favorite_parties.include? self
|
||||
end
|
||||
|
||||
def blueprint
|
||||
PartyBlueprint
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def skills_are_unique
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Raid < ApplicationRecord
|
||||
def blueprint
|
||||
RaidBlueprint
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,6 +20,10 @@ class Summon < ApplicationRecord
|
|||
}
|
||||
}
|
||||
|
||||
def blueprint
|
||||
SummonBlueprint
|
||||
end
|
||||
|
||||
def display_resource(summon)
|
||||
summon.name_en
|
||||
end
|
||||
|
|
|
|||
|
|
@ -42,4 +42,8 @@ class User < ApplicationRecord
|
|||
def favorite_parties
|
||||
favorites.map(&:party)
|
||||
end
|
||||
|
||||
def blueprint
|
||||
UserBlueprint
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,6 +20,10 @@ class Weapon < ApplicationRecord
|
|||
}
|
||||
}
|
||||
|
||||
def blueprint
|
||||
WeaponBlueprint
|
||||
end
|
||||
|
||||
def display_resource(weapon)
|
||||
weapon.name_en
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class WeaponKey < ApplicationRecord
|
||||
def blueprint
|
||||
WeaponKeyBlueprint
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue