API endpoints to load alt styles as JSON, and filter by species

Gonna use this in the app for the alt style picker! Still deciding on
the UI details.
This commit is contained in:
Emi Matchu 2024-01-28 07:30:06 -08:00
parent 6763e9454e
commit 72d4bc65ae
3 changed files with 13 additions and 1 deletions

View file

@ -1,6 +1,16 @@
class AltStylesController < ApplicationController
def index
@alt_styles = AltStyle.includes(:species, :color, :swf_assets).
order(:species_id, :color_id).all
order(:species_id, :color_id)
if params[:species_id]
@species = Species.find(params[:species_id])
@alt_styles = @alt_styles.merge(@species.alt_styles)
end
respond_to do |format|
format.html { render }
format.json { render json: @alt_styles }
end
end
end

View file

@ -1,6 +1,7 @@
class Species < ApplicationRecord
translates # TODO: Remove once we're all done with translations!
has_many :pet_types
has_many :alt_styles
scope :alphabetical, -> { order(:name) }

View file

@ -31,6 +31,7 @@ OpenneoImpressItems::Application.routes.draw do
resources :colors, only: [] do
get :pet_type, to: 'pet_types#show'
end
resources :alt_styles, path: 'alt-styles', only: [:index]
end
resources :colors, only: [] do
resources :pet_types, only: [:index]