diff --git a/app/controllers/api/v1/collection_weapons_controller.rb b/app/controllers/api/v1/collection_weapons_controller.rb index ad1cfc5..9ae14a5 100644 --- a/app/controllers/api/v1/collection_weapons_controller.rb +++ b/app/controllers/api/v1/collection_weapons_controller.rb @@ -19,6 +19,10 @@ module Api @collection_weapons = @collection_weapons.by_weapon(params[:weapon_id]) if params[:weapon_id] @collection_weapons = @collection_weapons.by_element(params[:element]) if params[:element] @collection_weapons = @collection_weapons.by_rarity(params[:rarity]) if params[:rarity] + @collection_weapons = @collection_weapons.by_proficiency(params[:proficiency]) if params[:proficiency] + @collection_weapons = @collection_weapons.by_series(params[:series]) if params[:series] + + @collection_weapons = @collection_weapons.sorted_by(params[:sort]) @collection_weapons = @collection_weapons.paginate(page: params[:page], per_page: params[:limit] || 50) diff --git a/app/models/collection_weapon.rb b/app/models/collection_weapon.rb index 3105c2f..a9c97e9 100644 --- a/app/models/collection_weapon.rb +++ b/app/models/collection_weapon.rb @@ -28,9 +28,29 @@ class CollectionWeapon < ApplicationRecord scope :with_ax, -> { where.not(ax_modifier1: nil) } scope :by_element, ->(element) { joins(:weapon).where(weapons: { element: element }) } scope :by_rarity, ->(rarity) { joins(:weapon).where(weapons: { rarity: rarity }) } + scope :by_proficiency, ->(proficiency) { joins(:weapon).where(weapons: { proficiency: proficiency }) } scope :transcended, -> { where('transcendence_step > 0') } scope :with_awakening, -> { where.not(awakening_id: nil) } + scope :sorted_by, ->(sort_key) { + case sort_key + when 'name_asc' + joins(:weapon).order('weapons.name_en ASC NULLS LAST') + when 'name_desc' + joins(:weapon).order('weapons.name_en DESC NULLS LAST') + when 'element_asc' + joins(:weapon).order('weapons.element ASC') + when 'element_desc' + joins(:weapon).order('weapons.element DESC') + when 'proficiency_asc' + joins(:weapon).order('weapons.proficiency ASC') + when 'proficiency_desc' + joins(:weapon).order('weapons.proficiency DESC') + else + order(created_at: :desc) + end + } + def blueprint Api::V1::CollectionWeaponBlueprint end