* Implements advanced filters (#90) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix a bug where unauthenticated users couldn't view profiles (#92) * Implements advanced filters (#90) (#91) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix being unable to see profiles when unauth * Add tables used for Siero's revival (#94) * Implements advanced filters (#90) (#91) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Deploy unauthenticated profile fix (#93) * Implements advanced filters (#90) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix a bug where unauthenticated users couldn't view profiles (#92) * Implements advanced filters (#90) (#91) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix being unable to see profiles when unauth * Add guidebooks migration * Implement business logic for reading Guidebooks * Change to individual guidebook columns * Properly output guidebook description * Move to 1-index guidebooks * Update party-related files for 1-index guidebooks * Add tables for Siero
231 lines
9.8 KiB
Ruby
231 lines
9.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Api
|
|
module V1
|
|
class SearchController < Api::V1::ApiController
|
|
def characters
|
|
filters = search_params[:filters]
|
|
locale = search_params[:locale] || 'en'
|
|
conditions = {}
|
|
|
|
if filters
|
|
conditions[:rarity] = filters['rarity'] unless filters['rarity'].blank? || filters['rarity'].empty?
|
|
conditions[:element] = filters['element'] unless filters['element'].blank? || filters['element'].empty?
|
|
unless filters['proficiency1'].blank? || filters['proficiency1'].empty?
|
|
conditions[:proficiency1] =
|
|
filters['proficiency1']
|
|
end
|
|
unless filters['proficiency2'].blank? || filters['proficiency2'].empty?
|
|
conditions[:proficiency2] =
|
|
filters['proficiency2']
|
|
end
|
|
# conditions[:series] = filters['series'] unless filters['series'].blank? || filters['series'].empty?
|
|
end
|
|
|
|
characters = if search_params[:query].present? && search_params[:query].length >= 2
|
|
if locale == 'ja'
|
|
Character.jp_search(search_params[:query]).where(conditions)
|
|
else
|
|
Character.en_search(search_params[:query]).where(conditions)
|
|
end
|
|
else
|
|
Character.where(conditions)
|
|
end
|
|
|
|
count = characters.length
|
|
paginated = characters.paginate(page: search_params[:page], per_page: SEARCH_PER_PAGE)
|
|
|
|
render json: CharacterBlueprint.render(paginated,
|
|
root: :results,
|
|
meta: {
|
|
count: count,
|
|
total_pages: total_pages(count),
|
|
per_page: SEARCH_PER_PAGE
|
|
})
|
|
end
|
|
|
|
def weapons
|
|
filters = search_params[:filters]
|
|
locale = search_params[:locale] || 'en'
|
|
conditions = {}
|
|
|
|
if filters
|
|
conditions[:rarity] = filters['rarity'] unless filters['rarity'].blank? || filters['rarity'].empty?
|
|
conditions[:element] = filters['element'] unless filters['element'].blank? || filters['element'].empty?
|
|
unless filters['proficiency1'].blank? || filters['proficiency1'].empty?
|
|
conditions[:proficiency] =
|
|
filters['proficiency1']
|
|
end
|
|
conditions[:series] = filters['series'] unless filters['series'].blank? || filters['series'].empty?
|
|
conditions[:extra] = filters['extra'] unless filters['extra'].blank?
|
|
end
|
|
|
|
weapons = if search_params[:query].present? && search_params[:query].length >= 2
|
|
if locale == 'ja'
|
|
Weapon.jp_search(search_params[:query]).where(conditions)
|
|
else
|
|
Weapon.en_search(search_params[:query]).where(conditions)
|
|
end
|
|
else
|
|
Weapon.where(conditions)
|
|
end
|
|
|
|
count = weapons.length
|
|
paginated = weapons.paginate(page: search_params[:page], per_page: SEARCH_PER_PAGE)
|
|
|
|
render json: WeaponBlueprint.render(paginated,
|
|
root: :results,
|
|
meta: {
|
|
count: count,
|
|
total_pages: total_pages(count),
|
|
per_page: SEARCH_PER_PAGE
|
|
})
|
|
end
|
|
|
|
def summons
|
|
filters = search_params[:filters]
|
|
locale = search_params[:locale] || 'en'
|
|
conditions = {}
|
|
|
|
if filters
|
|
conditions[:rarity] = filters['rarity'] unless filters['rarity'].blank? || filters['rarity'].empty?
|
|
conditions[:element] = filters['element'] unless filters['element'].blank? || filters['element'].empty?
|
|
conditions[:subaura] = filters['subaura'] unless filters['subaura'].blank?
|
|
end
|
|
|
|
summons = if search_params[:query].present? && search_params[:query].length >= 2
|
|
if locale == 'ja'
|
|
Summon.jp_search(search_params[:query]).where(conditions)
|
|
else
|
|
Summon.en_search(search_params[:query]).where(conditions)
|
|
end
|
|
else
|
|
Summon.where(conditions)
|
|
end
|
|
|
|
count = summons.length
|
|
paginated = summons.paginate(page: search_params[:page], per_page: SEARCH_PER_PAGE)
|
|
|
|
render json: SummonBlueprint.render(paginated,
|
|
root: :results,
|
|
meta: {
|
|
count: count,
|
|
total_pages: total_pages(count),
|
|
per_page: SEARCH_PER_PAGE
|
|
})
|
|
end
|
|
|
|
def job_skills
|
|
raise Api::V1::NoJobProvidedError unless search_params[:job].present?
|
|
|
|
# Set up basic parameters we'll use
|
|
job = Job.find(search_params[:job])
|
|
locale = search_params[:locale] || 'en'
|
|
|
|
# Set the conditions based on the group requested
|
|
conditions = {}
|
|
if search_params[:filters].present? && search_params[:filters]['group'].present?
|
|
group = search_params[:filters]['group'].to_i
|
|
|
|
if group >= 0 && group < 4
|
|
conditions[:color] = group
|
|
conditions[:emp] = false
|
|
conditions[:base] = false
|
|
elsif group == 4
|
|
conditions[:emp] = true
|
|
elsif group == 5
|
|
conditions[:base] = true
|
|
end
|
|
end
|
|
|
|
# Perform the query
|
|
skills = if search_params[:query].present? && search_params[:query].length >= 2
|
|
JobSkill.joins(:job)
|
|
.method("#{locale}_search").call(search_params[:query])
|
|
.where(conditions)
|
|
.where(job: job.id, main: false)
|
|
.or(
|
|
JobSkill.joins(:job)
|
|
.method("#{locale}_search").call(search_params[:query])
|
|
.where(conditions)
|
|
.where(sub: true)
|
|
.where.not(job: job.id)
|
|
)
|
|
.or(
|
|
JobSkill.joins(:job)
|
|
.method("#{locale}_search").call(search_params[:query])
|
|
.where(conditions)
|
|
.where(job: { base_job: job.base_job.id }, emp: true)
|
|
.where.not(job: job.id)
|
|
)
|
|
else
|
|
JobSkill.all
|
|
.joins(:job)
|
|
.where(conditions)
|
|
.where(job: job.id, main: false)
|
|
.or(
|
|
JobSkill.all
|
|
.where(conditions)
|
|
.where(sub: true)
|
|
.where.not(job: job.id)
|
|
)
|
|
.or(
|
|
JobSkill.all
|
|
.where(conditions)
|
|
.where(job: job.base_job.id, base: true)
|
|
.where.not(job: job.id)
|
|
)
|
|
.or(
|
|
JobSkill.all
|
|
.where(conditions)
|
|
.joins(:job)
|
|
.where(job: { base_job: job.base_job.id }, emp: true)
|
|
.where.not(job: job.id)
|
|
)
|
|
end
|
|
|
|
count = skills.length
|
|
paginated = skills.paginate(page: search_params[:page], per_page: SEARCH_PER_PAGE)
|
|
|
|
render json: JobSkillBlueprint.render(paginated,
|
|
root: :results,
|
|
meta: {
|
|
count: count,
|
|
total_pages: total_pages(count),
|
|
per_page: SEARCH_PER_PAGE
|
|
})
|
|
end
|
|
|
|
def guidebooks
|
|
# Perform the query
|
|
books = if search_params[:query].present? && search_params[:query].length >= 2
|
|
Guidebook.method("#{locale}_search").call(search_params[:query])
|
|
else
|
|
Guidebook.all
|
|
end
|
|
|
|
count = books.length
|
|
paginated = books.paginate(page: search_params[:page], per_page: SEARCH_PER_PAGE)
|
|
|
|
render json: GuidebookBlueprint.render(paginated,
|
|
root: :results,
|
|
meta: {
|
|
count: count,
|
|
total_pages: total_pages(count),
|
|
per_page: SEARCH_PER_PAGE
|
|
})
|
|
end
|
|
|
|
private
|
|
|
|
def total_pages(count)
|
|
count.to_f / SEARCH_PER_PAGE > 1 ? (count.to_f / SEARCH_PER_PAGE).ceil : 1
|
|
end
|
|
|
|
# Specify whitelisted properties that can be modified.
|
|
def search_params
|
|
params.require(:search).permit!
|
|
end
|
|
end
|
|
end
|
|
end
|