Merge pull request #55 from jedmund/updates
Adds support for managing app updates
This commit is contained in:
commit
5025f51d04
18 changed files with 215 additions and 8 deletions
20
app/blueprints/api/v1/job_accessory_blueprint.rb
Normal file
20
app/blueprints/api/v1/job_accessory_blueprint.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class JobAccessoryBlueprint < ApiBlueprint
|
||||
field :name do |skill|
|
||||
{
|
||||
en: skill.name_en,
|
||||
ja: skill.name_jp
|
||||
}
|
||||
end
|
||||
|
||||
association :job,
|
||||
name: :job,
|
||||
blueprint: JobBlueprint
|
||||
|
||||
fields :granblue_id, :rarity, :release_date
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -64,6 +64,8 @@ module Api
|
|||
include_view :characters
|
||||
include_view :job_skills
|
||||
|
||||
association :accessory,
|
||||
blueprint: JobAccessoryBlueprint
|
||||
fields :description, :charge_attack, :button_count, :turn_count, :chain_count
|
||||
end
|
||||
|
||||
|
|
|
|||
9
app/blueprints/api/v1/update_blueprint.rb
Normal file
9
app/blueprints/api/v1/update_blueprint.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class UpdateBlueprint < Blueprinter::Base
|
||||
fields :version, :update_type, :updated_at
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -36,6 +36,11 @@ module Api
|
|||
respond_to :json
|
||||
|
||||
##### Methods
|
||||
# Returns the latest update
|
||||
def version
|
||||
render json: UpdateBlueprint.render_as_json(AppUpdate.last)
|
||||
end
|
||||
|
||||
# Assign the current user if the Doorkeeper token isn't nil, then
|
||||
# update the current user's last seen datetime and last IP address
|
||||
# before returning
|
||||
|
|
@ -85,9 +90,9 @@ module Api
|
|||
|
||||
def render_not_found_response(object)
|
||||
render json: ErrorBlueprint.render(nil, error: {
|
||||
message: "#{object.capitalize} could not be found",
|
||||
code: 'not_found'
|
||||
}), status: :not_found
|
||||
message: "#{object.capitalize} could not be found",
|
||||
code: 'not_found'
|
||||
}), status: :not_found
|
||||
end
|
||||
|
||||
def render_unauthorized_response
|
||||
|
|
|
|||
12
app/controllers/api/v1/job_accessories_controller.rb
Normal file
12
app/controllers/api/v1/job_accessories_controller.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class JobAccessoriesController < Api::V1::ApiController
|
||||
def job
|
||||
accessories = JobAccessory.where('job_id = ?', params[:id])
|
||||
render json: JobAccessoryBlueprint.render(accessories)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -44,6 +44,8 @@ module Api
|
|||
|
||||
@party.attributes = party_params.except(:skill1_id, :skill2_id, :skill3_id)
|
||||
|
||||
# TODO: Validate accessory with job
|
||||
|
||||
return render json: PartyBlueprint.render(@party, view: :full, root: :party) if @party.save!
|
||||
|
||||
render_validation_error_response(@party)
|
||||
|
|
@ -64,7 +66,7 @@ module Api
|
|||
|
||||
if new_party.save
|
||||
render json: PartyBlueprint.render(new_party, view: :full, root: :party,
|
||||
meta: { remix: true })
|
||||
meta: { remix: true })
|
||||
else
|
||||
render_validation_error_response(new_party)
|
||||
end
|
||||
|
|
@ -124,7 +126,7 @@ module Api
|
|||
def build_conditions(params)
|
||||
unless params['recency'].blank?
|
||||
start_time = (DateTime.current - params['recency'].to_i.seconds)
|
||||
.to_datetime.beginning_of_day
|
||||
.to_datetime.beginning_of_day
|
||||
end
|
||||
|
||||
{}.tap do |hash|
|
||||
|
|
@ -176,6 +178,7 @@ module Api
|
|||
:description,
|
||||
:raid_id,
|
||||
:job_id,
|
||||
:accessory_id,
|
||||
:skill0_id,
|
||||
:skill1_id,
|
||||
:skill2_id,
|
||||
|
|
|
|||
5
app/models/app_update.rb
Normal file
5
app/models/app_update.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AppUpdate < ApplicationRecord
|
||||
|
||||
end
|
||||
37
app/models/job_accessory.rb
Normal file
37
app/models/job_accessory.rb
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class JobAccessory < ApplicationRecord
|
||||
include PgSearch::Model
|
||||
|
||||
belongs_to :job
|
||||
|
||||
pg_search_scope :en_search,
|
||||
against: :name_en,
|
||||
using: {
|
||||
tsearch: {
|
||||
prefix: true,
|
||||
dictionary: 'simple'
|
||||
}
|
||||
}
|
||||
|
||||
pg_search_scope :jp_search,
|
||||
against: :name_jp,
|
||||
using: {
|
||||
tsearch: {
|
||||
prefix: true,
|
||||
dictionary: 'simple'
|
||||
}
|
||||
}
|
||||
|
||||
def blueprint
|
||||
JobAccessoryBlueprint
|
||||
end
|
||||
|
||||
def display_resource(skill)
|
||||
skill.name_en
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
self.class == other.class && id == other.id
|
||||
end
|
||||
end
|
||||
|
|
@ -16,6 +16,11 @@ class Party < ApplicationRecord
|
|||
belongs_to :raid, optional: true
|
||||
belongs_to :job, optional: true
|
||||
|
||||
belongs_to :accessory,
|
||||
foreign_key: 'accessory_id',
|
||||
class_name: 'JobAccessory',
|
||||
optional: true
|
||||
|
||||
belongs_to :skill0,
|
||||
foreign_key: 'skill0_id',
|
||||
class_name: 'JobSkill',
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ Rails.application.routes.draw do
|
|||
resources :grid_summons, only: %i[update destroy]
|
||||
resources :favorites, only: [:create]
|
||||
|
||||
get 'version', to: 'api#version'
|
||||
|
||||
get 'users/info/:id', to: 'users#info'
|
||||
|
||||
get 'parties/favorites', to: 'parties#favorites'
|
||||
|
|
@ -34,6 +36,7 @@ Rails.application.routes.draw do
|
|||
|
||||
get 'jobs/skills', to: 'job_skills#all'
|
||||
get 'jobs/:id/skills', to: 'job_skills#job'
|
||||
get 'jobs/:id/accessories', to: 'job_accessories#job'
|
||||
|
||||
get 'raids', to: 'raids#all'
|
||||
get 'weapon_keys', to: 'weapon_keys#all'
|
||||
|
|
|
|||
14
db/migrate/20230124000252_create_job_accessories.rb
Normal file
14
db/migrate/20230124000252_create_job_accessories.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
class CreateJobAccessories < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :job_accessories, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
|
||||
t.references :job, type: :uuid
|
||||
|
||||
t.string :name_en, null: false, unique: true
|
||||
t.string :name_jp, null: false, unique: true
|
||||
t.string :granblue_id, null: false, unique: true
|
||||
|
||||
t.integer :rarity
|
||||
t.date :release_date
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
class AddAccessoryTypeToJobAccessories < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :job_accessories, :accessory_type, :integer
|
||||
end
|
||||
end
|
||||
7
db/migrate/20230124100823_add_accessory_id_to_party.rb
Normal file
7
db/migrate/20230124100823_add_accessory_id_to_party.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class AddAccessoryIdToParty < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_table(:parties) do |t|
|
||||
t.references :accessory, type: :uuid, foreign_key: { to_table: 'job_accessories' }
|
||||
end
|
||||
end
|
||||
end
|
||||
8
db/migrate/20230126030358_add_updates_table.rb
Normal file
8
db/migrate/20230126030358_add_updates_table.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
class AddUpdatesTable < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :app_updates, id: false do |t|
|
||||
t.string :update_type, null: false
|
||||
t.datetime :updated_at, null: false, unique: true, primary_key: true
|
||||
end
|
||||
end
|
||||
end
|
||||
5
db/migrate/20230126040207_add_version_to_app_updates.rb
Normal file
5
db/migrate/20230126040207_add_version_to_app_updates.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class AddVersionToAppUpdates < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :app_updates, :version, :string
|
||||
end
|
||||
end
|
||||
22
db/schema.rb
22
db/schema.rb
|
|
@ -10,13 +10,17 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_01_23_055508) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_01_26_040207) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "btree_gin"
|
||||
enable_extension "pg_trgm"
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
enable_extension "timescaledb"
|
||||
|
||||
create_table "app_updates", primary_key: "updated_at", id: :datetime, force: :cascade do |t|
|
||||
t.string "update_type", null: false
|
||||
t.string "version"
|
||||
end
|
||||
|
||||
create_table "characters", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.string "name_en"
|
||||
|
|
@ -115,6 +119,17 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_23_055508) do
|
|||
t.index ["weapon_key3_id"], name: "index_grid_weapons_on_weapon_key3_id"
|
||||
end
|
||||
|
||||
create_table "job_accessories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.uuid "job_id"
|
||||
t.string "name_en", null: false
|
||||
t.string "name_jp", null: false
|
||||
t.string "granblue_id", null: false
|
||||
t.integer "rarity"
|
||||
t.date "release_date"
|
||||
t.integer "accessory_type"
|
||||
t.index ["job_id"], name: "index_job_accessories_on_job_id"
|
||||
end
|
||||
|
||||
create_table "job_skills", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.uuid "job_id"
|
||||
t.string "name_en", null: false
|
||||
|
|
@ -205,6 +220,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_23_055508) do
|
|||
t.integer "chain_count"
|
||||
t.integer "turn_count"
|
||||
t.uuid "source_party_id"
|
||||
t.uuid "accessory_id"
|
||||
t.index ["accessory_id"], name: "index_parties_on_accessory_id"
|
||||
t.index ["job_id"], name: "index_parties_on_job_id"
|
||||
t.index ["skill0_id"], name: "index_parties_on_skill0_id"
|
||||
t.index ["skill1_id"], name: "index_parties_on_skill1_id"
|
||||
|
|
@ -314,6 +331,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_23_055508) do
|
|||
add_foreign_key "jobs", "jobs", column: "base_job_id"
|
||||
add_foreign_key "oauth_access_grants", "oauth_applications", column: "application_id"
|
||||
add_foreign_key "oauth_access_tokens", "oauth_applications", column: "application_id"
|
||||
add_foreign_key "parties", "job_accessories", column: "accessory_id"
|
||||
add_foreign_key "parties", "job_skills", column: "skill0_id"
|
||||
add_foreign_key "parties", "job_skills", column: "skill1_id"
|
||||
add_foreign_key "parties", "job_skills", column: "skill2_id"
|
||||
|
|
|
|||
42
lib/tasks/export_accessories.rake
Normal file
42
lib/tasks/export_accessories.rake
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
namespace :granblue do
|
||||
namespace :export do
|
||||
def build_url(id, type, size)
|
||||
# Set up URL
|
||||
base_url = 'https://prd-game-a-granbluefantasy.akamaized.net/assets_en/img/sp/assets'
|
||||
extension = '.jpg'
|
||||
|
||||
directory = 'm' if size.to_s == 'grid'
|
||||
directory = 's' if size.to_s == 'square'
|
||||
|
||||
"#{base_url}/#{type}/#{directory}/#{id}#{extension}"
|
||||
end
|
||||
|
||||
desc 'Exports a list of accessories for a given size'
|
||||
task :accessory, [:size] => :environment do |_t, args|
|
||||
# Set up options
|
||||
size = args[:size]
|
||||
|
||||
Dir.glob("#{Rails.root}/app/models/job_accessory.rb").each { |file| require file }
|
||||
|
||||
# Set up filepath
|
||||
dir = "#{Rails.root}/export/"
|
||||
filename = "#{dir}/accessory-#{size}.txt"
|
||||
FileUtils.mkdir(dir) unless Dir.exist?(dir)
|
||||
|
||||
# Write to file
|
||||
File.open(filename, 'w') do |f|
|
||||
JobAccessory.all.each do |w|
|
||||
if w.accessory_type === 1
|
||||
f.write("#{build_url(w.granblue_id.to_s, "shield", size)} \n")
|
||||
elsif w.accessory_type === 2
|
||||
f.write("#{build_url(w.granblue_id.to_s, "familiar", size)} \n")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# CLI output
|
||||
count = `wc -l #{filename}`.split.first.to_i
|
||||
puts "Wrote #{count} job accessory URLs for \"#{size}\" size"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -36,7 +36,14 @@ namespace :granblue do
|
|||
Rake::Task['granblue:export:job'].invoke
|
||||
Rake::Task['granblue:export:job'].reenable
|
||||
|
||||
puts 'Exported 10 files'
|
||||
# Run job accessory tasks
|
||||
Rake::Task['granblue:export:accessory'].invoke('grid')
|
||||
Rake::Task['granblue:export:accessory'].reenable
|
||||
|
||||
Rake::Task['granblue:export:accessory'].invoke('square')
|
||||
Rake::Task['granblue:export:accessory'].reenable
|
||||
|
||||
puts 'Exported 12 files'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue