diff --git a/app/blueprints/api/v1/artifact_blueprint.rb b/app/blueprints/api/v1/artifact_blueprint.rb new file mode 100644 index 0000000..2e84de7 --- /dev/null +++ b/app/blueprints/api/v1/artifact_blueprint.rb @@ -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 diff --git a/app/blueprints/api/v1/artifact_skill_blueprint.rb b/app/blueprints/api/v1/artifact_skill_blueprint.rb new file mode 100644 index 0000000..9df8c4e --- /dev/null +++ b/app/blueprints/api/v1/artifact_skill_blueprint.rb @@ -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 diff --git a/app/blueprints/api/v1/collection_artifact_blueprint.rb b/app/blueprints/api/v1/collection_artifact_blueprint.rb new file mode 100644 index 0000000..b32d94b --- /dev/null +++ b/app/blueprints/api/v1/collection_artifact_blueprint.rb @@ -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 diff --git a/app/blueprints/api/v1/grid_artifact_blueprint.rb b/app/blueprints/api/v1/grid_artifact_blueprint.rb new file mode 100644 index 0000000..0f9e0b8 --- /dev/null +++ b/app/blueprints/api/v1/grid_artifact_blueprint.rb @@ -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 diff --git a/app/blueprints/api/v1/grid_character_blueprint.rb b/app/blueprints/api/v1/grid_character_blueprint.rb index accff5e..c6370c6 100644 --- a/app/blueprints/api/v1/grid_character_blueprint.rb +++ b/app/blueprints/api/v1/grid_character_blueprint.rb @@ -16,6 +16,8 @@ module Api view :nested do include_view :mastery_bonuses association :character, blueprint: CharacterBlueprint, view: :full + association :grid_artifact, blueprint: GridArtifactBlueprint, view: :nested, + if: ->(_field_name, gc, _options) { gc.grid_artifact.present? } end view :uncap do