diff --git a/app/blueprints/api/v1/artifact_skill_blueprint.rb b/app/blueprints/api/v1/artifact_skill_blueprint.rb index 9df8c4e..1c951d8 100644 --- a/app/blueprints/api/v1/artifact_skill_blueprint.rb +++ b/app/blueprints/api/v1/artifact_skill_blueprint.rb @@ -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| diff --git a/app/controllers/api/v1/artifact_skills_controller.rb b/app/controllers/api/v1/artifact_skills_controller.rb index 93551ae..d810587 100644 --- a/app/controllers/api/v1/artifact_skills_controller.rb +++ b/app/controllers/api/v1/artifact_skills_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 3f8c03c..17f20f9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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