hensei-api/app/controllers/api/v1/weapon_series_controller.rb
Justin Edmund 1f80e4189f
Add weapon stat modifiers for AX skills and befoulments (#202)
* add weapon_stat_modifiers table for ax skills and befoulments

* add fk columns for ax modifiers and befoulments, replace has_ax_skills with augment_type

* update models for weapon_stat_modifier fks and befoulments

* update blueprints for weapon_stat_modifier serialization

* update import service for weapon_stat_modifier fks and befoulments

* add weapon_stat_modifiers controller and update params for fks

* update tests and factories for weapon_stat_modifier fks

* fix remaining has_ax_skills and ax_modifier references

* add ax_modifier and befoulment_modifier to eager loading

* fix ax modifier column naming and migration approach

* add game_skill_ids for befoulment modifiers
2025-12-31 22:20:00 -08:00

76 lines
2.3 KiB
Ruby

# frozen_string_literal: true
module Api
module V1
class WeaponSeriesController < Api::V1::ApiController
before_action :set_weapon_series, only: %i[show update destroy]
before_action :ensure_editor_role, only: %i[create update destroy]
# GET /weapon_series
def index
weapon_series = WeaponSeries.ordered
render json: WeaponSeriesBlueprint.render(weapon_series)
end
# GET /weapon_series/:id
def show
render json: WeaponSeriesBlueprint.render(@weapon_series, view: :full)
end
# POST /weapon_series
def create
weapon_series = WeaponSeries.new(weapon_series_params)
if weapon_series.save
render json: WeaponSeriesBlueprint.render(weapon_series, view: :full), status: :created
else
render_validation_error_response(weapon_series)
end
end
# PATCH/PUT /weapon_series/:id
def update
if @weapon_series.update(weapon_series_params)
render json: WeaponSeriesBlueprint.render(@weapon_series, view: :full)
else
render_validation_error_response(@weapon_series)
end
end
# DELETE /weapon_series/:id
def destroy
if @weapon_series.weapons.exists?
render json: ErrorBlueprint.render(nil, error: {
message: 'Cannot delete series with associated weapons',
code: 'has_dependencies'
}), status: :unprocessable_entity
else
@weapon_series.destroy!
head :no_content
end
end
private
def set_weapon_series
# Support lookup by slug or UUID
@weapon_series = WeaponSeries.find_by(slug: params[:id]) || WeaponSeries.find(params[:id])
end
def ensure_editor_role
return if current_user&.role && current_user.role >= 7
Rails.logger.warn "[WEAPON_SERIES] Unauthorized access attempt by user #{current_user&.id}"
render json: { error: 'Unauthorized - Editor role required' }, status: :unauthorized
end
def weapon_series_params
params.require(:weapon_series).permit(
:name_en, :name_jp, :slug, :order,
:extra, :element_changeable, :has_weapon_keys,
:has_awakening, :augment_type
)
end
end
end
end