diff --git a/app/blueprints/api/v1/character_blueprint.rb b/app/blueprints/api/v1/character_blueprint.rb new file mode 100644 index 0000000..1fe220e --- /dev/null +++ b/app/blueprints/api/v1/character_blueprint.rb @@ -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 diff --git a/app/blueprints/api/v1/grid_character_blueprint.rb b/app/blueprints/api/v1/grid_character_blueprint.rb new file mode 100644 index 0000000..5984c71 --- /dev/null +++ b/app/blueprints/api/v1/grid_character_blueprint.rb @@ -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 diff --git a/app/blueprints/api/v1/grid_summon_blueprint.rb b/app/blueprints/api/v1/grid_summon_blueprint.rb new file mode 100644 index 0000000..ae9c58b --- /dev/null +++ b/app/blueprints/api/v1/grid_summon_blueprint.rb @@ -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 diff --git a/app/blueprints/api/v1/grid_weapon_blueprint.rb b/app/blueprints/api/v1/grid_weapon_blueprint.rb new file mode 100644 index 0000000..1d1dc9d --- /dev/null +++ b/app/blueprints/api/v1/grid_weapon_blueprint.rb @@ -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 diff --git a/app/blueprints/api/v1/job_blueprint.rb b/app/blueprints/api/v1/job_blueprint.rb new file mode 100644 index 0000000..b2299c4 --- /dev/null +++ b/app/blueprints/api/v1/job_blueprint.rb @@ -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 diff --git a/app/blueprints/api/v1/job_skill_blueprint.rb b/app/blueprints/api/v1/job_skill_blueprint.rb new file mode 100644 index 0000000..5b4c86b --- /dev/null +++ b/app/blueprints/api/v1/job_skill_blueprint.rb @@ -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 diff --git a/app/blueprints/api/v1/party_blueprint.rb b/app/blueprints/api/v1/party_blueprint.rb new file mode 100644 index 0000000..20927a1 --- /dev/null +++ b/app/blueprints/api/v1/party_blueprint.rb @@ -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 diff --git a/app/blueprints/api/v1/raid_blueprint.rb b/app/blueprints/api/v1/raid_blueprint.rb new file mode 100644 index 0000000..3a83225 --- /dev/null +++ b/app/blueprints/api/v1/raid_blueprint.rb @@ -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 diff --git a/app/blueprints/api/v1/summon_blueprint.rb b/app/blueprints/api/v1/summon_blueprint.rb new file mode 100644 index 0000000..4173b80 --- /dev/null +++ b/app/blueprints/api/v1/summon_blueprint.rb @@ -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 diff --git a/app/blueprints/api/v1/user_blueprint.rb b/app/blueprints/api/v1/user_blueprint.rb new file mode 100644 index 0000000..4f88e92 --- /dev/null +++ b/app/blueprints/api/v1/user_blueprint.rb @@ -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 diff --git a/app/blueprints/api/v1/weapon_blueprint.rb b/app/blueprints/api/v1/weapon_blueprint.rb new file mode 100644 index 0000000..917c34d --- /dev/null +++ b/app/blueprints/api/v1/weapon_blueprint.rb @@ -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 diff --git a/app/blueprints/api/v1/weapon_key_blueprint.rb b/app/blueprints/api/v1/weapon_key_blueprint.rb new file mode 100644 index 0000000..4a959df --- /dev/null +++ b/app/blueprints/api/v1/weapon_key_blueprint.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +module Api + module V1 + class WeaponKeyBlueprint < ApiBlueprint + end + end +end diff --git a/app/models/character.rb b/app/models/character.rb index 631614c..c772471 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -20,6 +20,10 @@ class Character < ApplicationRecord } } + def blueprint + CharacterBlueprint + end + def display_resource(character) character.name_en end diff --git a/app/models/favorite.rb b/app/models/favorite.rb index 13c5992..4c2d235 100644 --- a/app/models/favorite.rb +++ b/app/models/favorite.rb @@ -7,4 +7,8 @@ class Favorite < ApplicationRecord def party Party.find(party_id) end + + def favorite + FavoriteBlueprint + end end diff --git a/app/models/grid_character.rb b/app/models/grid_character.rb index badf5f9..2e3e16b 100644 --- a/app/models/grid_character.rb +++ b/app/models/grid_character.rb @@ -6,4 +6,8 @@ class GridCharacter < ApplicationRecord def character Character.find(character_id) end + + def blueprint + GridCharacterBlueprint + end end diff --git a/app/models/grid_summon.rb b/app/models/grid_summon.rb index 0f95dd8..9857a9b 100644 --- a/app/models/grid_summon.rb +++ b/app/models/grid_summon.rb @@ -6,4 +6,8 @@ class GridSummon < ApplicationRecord def summon Summon.find(summon_id) end + + def blueprint + GridSummonBlueprint + end end diff --git a/app/models/grid_weapon.rb b/app/models/grid_weapon.rb index 295b30c..bd97efb 100644 --- a/app/models/grid_weapon.rb +++ b/app/models/grid_weapon.rb @@ -20,4 +20,8 @@ class GridWeapon < ApplicationRecord weapon_keys end + + def blueprint + GridWeaponBlueprint + end end diff --git a/app/models/job.rb b/app/models/job.rb index 66420a9..beb0ce4 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -8,6 +8,10 @@ class Job < ApplicationRecord class_name: 'Job', optional: true + def blueprint + JobBlueprint + end + def display_resource(job) job.name_en end diff --git a/app/models/job_skill.rb b/app/models/job_skill.rb index b1109ea..9e0bcd3 100644 --- a/app/models/job_skill.rb +++ b/app/models/job_skill.rb @@ -25,6 +25,10 @@ class JobSkill < ApplicationRecord } } + def blueprint + JobSkillBlueprint + end + def display_resource(skill) skill.name_en end diff --git a/app/models/party.rb b/app/models/party.rb index fe2b45e..c90c0c4 100644 --- a/app/models/party.rb +++ b/app/models/party.rb @@ -52,6 +52,10 @@ class Party < ApplicationRecord user.favorite_parties.include? self end + def blueprint + PartyBlueprint + end + private def skills_are_unique diff --git a/app/models/raid.rb b/app/models/raid.rb index 7d4a12b..9163f71 100644 --- a/app/models/raid.rb +++ b/app/models/raid.rb @@ -1,4 +1,7 @@ # frozen_string_literal: true class Raid < ApplicationRecord + def blueprint + RaidBlueprint + end end diff --git a/app/models/summon.rb b/app/models/summon.rb index 775d61d..7efab1b 100644 --- a/app/models/summon.rb +++ b/app/models/summon.rb @@ -20,6 +20,10 @@ class Summon < ApplicationRecord } } + def blueprint + SummonBlueprint + end + def display_resource(summon) summon.name_en end diff --git a/app/models/user.rb b/app/models/user.rb index 44a0e76..215885e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -42,4 +42,8 @@ class User < ApplicationRecord def favorite_parties favorites.map(&:party) end + + def blueprint + UserBlueprint + end end diff --git a/app/models/weapon.rb b/app/models/weapon.rb index 646f82c..ed45010 100644 --- a/app/models/weapon.rb +++ b/app/models/weapon.rb @@ -20,6 +20,10 @@ class Weapon < ApplicationRecord } } + def blueprint + WeaponBlueprint + end + def display_resource(weapon) weapon.name_en end diff --git a/app/models/weapon_key.rb b/app/models/weapon_key.rb index 4615b11..cfce439 100644 --- a/app/models/weapon_key.rb +++ b/app/models/weapon_key.rb @@ -1,4 +1,7 @@ # frozen_string_literal: true class WeaponKey < ApplicationRecord + def blueprint + WeaponKeyBlueprint + end end