add show/update endpoints for artifact skills

- show and update actions with editor role protection
- include game_name field in blueprint
- clear cache after updates
This commit is contained in:
Justin Edmund 2025-12-18 23:14:41 -08:00
parent db2aa43d81
commit b7aeb2bdfe
3 changed files with 49 additions and 1 deletions

View file

@ -10,6 +10,13 @@ module Api
}
end
field :game_name do |s|
{
en: s.game_name_en,
ja: s.game_name_jp
}
end
fields :skill_group, :modifier, :polarity
field :base_values do |s|

View file

@ -3,6 +3,9 @@
module Api
module V1
class ArtifactSkillsController < Api::V1::ApiController
before_action :set_artifact_skill, only: %w[show update]
before_action :ensure_editor_role, only: %w[update]
# GET /artifact_skills
def index
@skills = ArtifactSkill.all
@ -24,6 +27,44 @@ module Api
@skills = ArtifactSkill.for_slot(slot)
render json: ArtifactSkillBlueprint.render(@skills, root: :artifact_skills)
end
# GET /artifact_skills/:id
def show
render json: ArtifactSkillBlueprint.render(@skill)
end
# PATCH/PUT /artifact_skills/:id
def update
if @skill.update(artifact_skill_params)
ArtifactSkill.clear_cache!
render json: ArtifactSkillBlueprint.render(@skill)
else
render_validation_error_response(@skill)
end
end
private
def set_artifact_skill
@skill = ArtifactSkill.find(params[:id])
end
def ensure_editor_role
return if current_user&.role && current_user.role >= 7
render json: { error: 'Unauthorized - Editor role required' }, status: :unauthorized
end
def artifact_skill_params
params.permit(
:skill_group, :modifier,
:name_en, :name_jp,
:game_name_en, :game_name_jp,
:suffix_en, :suffix_jp,
:growth, :polarity,
base_values: []
)
end
end
end
end

View file

@ -121,7 +121,7 @@ Rails.application.routes.draw do
get :download_status
end
end
resources :artifact_skills, only: %i[index] do
resources :artifact_skills, only: %i[index show update] do
collection do
get 'for_slot/:slot', action: :for_slot, as: :for_slot
end