add artifact blueprints
This commit is contained in:
parent
d6d655297b
commit
069118cbe9
5 changed files with 120 additions and 0 deletions
18
app/blueprints/api/v1/artifact_blueprint.rb
Normal file
18
app/blueprints/api/v1/artifact_blueprint.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Api
|
||||||
|
module V1
|
||||||
|
class ArtifactBlueprint < ApiBlueprint
|
||||||
|
field :name do |a|
|
||||||
|
{
|
||||||
|
en: a.name_en,
|
||||||
|
ja: a.name_jp
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
fields :granblue_id, :proficiency, :rarity
|
||||||
|
|
||||||
|
field :release_date, if: ->(_field, a, _options) { a.release_date.present? }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
31
app/blueprints/api/v1/artifact_skill_blueprint.rb
Normal file
31
app/blueprints/api/v1/artifact_skill_blueprint.rb
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Api
|
||||||
|
module V1
|
||||||
|
class ArtifactSkillBlueprint < ApiBlueprint
|
||||||
|
field :name do |s|
|
||||||
|
{
|
||||||
|
en: s.name_en,
|
||||||
|
ja: s.name_jp
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
fields :skill_group, :modifier, :polarity
|
||||||
|
|
||||||
|
field :base_values do |s|
|
||||||
|
s.base_values
|
||||||
|
end
|
||||||
|
|
||||||
|
field :growth, if: ->(_field, s, _options) { s.growth.present? } do |s|
|
||||||
|
s.growth.to_f
|
||||||
|
end
|
||||||
|
|
||||||
|
field :suffix do |s|
|
||||||
|
{
|
||||||
|
en: s.suffix_en,
|
||||||
|
ja: s.suffix_jp
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
32
app/blueprints/api/v1/collection_artifact_blueprint.rb
Normal file
32
app/blueprints/api/v1/collection_artifact_blueprint.rb
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Api
|
||||||
|
module V1
|
||||||
|
class CollectionArtifactBlueprint < ApiBlueprint
|
||||||
|
identifier :id
|
||||||
|
|
||||||
|
fields :element, :level, :nickname, :created_at, :updated_at
|
||||||
|
|
||||||
|
# Proficiency is only present on quirk artifacts
|
||||||
|
field :proficiency, if: ->(_field, obj, _options) { obj.proficiency.present? }
|
||||||
|
|
||||||
|
field :skills do |obj|
|
||||||
|
[obj.skill1, obj.skill2, obj.skill3, obj.skill4].map do |skill|
|
||||||
|
next nil if skill.blank? || skill == {}
|
||||||
|
|
||||||
|
{
|
||||||
|
modifier: skill['modifier'],
|
||||||
|
strength: skill['strength'],
|
||||||
|
level: skill['level']
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
association :artifact, blueprint: ArtifactBlueprint
|
||||||
|
|
||||||
|
view :full do
|
||||||
|
association :artifact, blueprint: ArtifactBlueprint
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
37
app/blueprints/api/v1/grid_artifact_blueprint.rb
Normal file
37
app/blueprints/api/v1/grid_artifact_blueprint.rb
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Api
|
||||||
|
module V1
|
||||||
|
class GridArtifactBlueprint < ApiBlueprint
|
||||||
|
fields :element, :level
|
||||||
|
|
||||||
|
# Proficiency is only present on quirk artifacts
|
||||||
|
field :proficiency, if: ->(_field, obj, _options) { obj.proficiency.present? }
|
||||||
|
|
||||||
|
field :skills do |obj|
|
||||||
|
[obj.skill1, obj.skill2, obj.skill3, obj.skill4].map do |skill|
|
||||||
|
next nil if skill.blank? || skill == {}
|
||||||
|
|
||||||
|
{
|
||||||
|
modifier: skill['modifier'],
|
||||||
|
strength: skill['strength'],
|
||||||
|
level: skill['level']
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
view :nested do
|
||||||
|
association :artifact, blueprint: ArtifactBlueprint
|
||||||
|
end
|
||||||
|
|
||||||
|
view :full do
|
||||||
|
include_view :nested
|
||||||
|
association :grid_character, blueprint: GridCharacterBlueprint
|
||||||
|
end
|
||||||
|
|
||||||
|
view :destroyed do
|
||||||
|
fields :created_at, :updated_at
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -16,6 +16,8 @@ module Api
|
||||||
view :nested do
|
view :nested do
|
||||||
include_view :mastery_bonuses
|
include_view :mastery_bonuses
|
||||||
association :character, blueprint: CharacterBlueprint, view: :full
|
association :character, blueprint: CharacterBlueprint, view: :full
|
||||||
|
association :grid_artifact, blueprint: GridArtifactBlueprint, view: :nested,
|
||||||
|
if: ->(_field_name, gc, _options) { gc.grid_artifact.present? }
|
||||||
end
|
end
|
||||||
|
|
||||||
view :uncap do
|
view :uncap do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue