diff --git a/app/controllers/api/v1/artifacts_controller.rb b/app/controllers/api/v1/artifacts_controller.rb index fc621de..f1434f1 100644 --- a/app/controllers/api/v1/artifacts_controller.rb +++ b/app/controllers/api/v1/artifacts_controller.rb @@ -19,6 +19,21 @@ module Api render json: ArtifactBlueprint.render(@artifact) end + # POST /artifacts/grade + # Grades artifact skills without persisting. Accepts skill data and returns grade/recommendation. + # + # @param artifact_id [String] Optional - ID of base artifact (for quirk detection) + # @param skill1 [Hash] Skill data with modifier, strength, level + # @param skill2 [Hash] Skill data with modifier, strength, level + # @param skill3 [Hash] Skill data with modifier, strength, level + # @param skill4 [Hash] Skill data with modifier, strength, level + def grade + artifact_data = build_gradeable_artifact + grader = ArtifactGrader.new(artifact_data) + + render json: { grade: grader.grade } + end + private def set_artifact @@ -26,6 +41,29 @@ module Api rescue ActiveRecord::RecordNotFound render_not_found_response('artifact') end + + def build_gradeable_artifact + base_artifact = params[:artifact_id].present? ? Artifact.find_by(id: params[:artifact_id]) : nil + + # Build a simple struct that responds to what ArtifactGrader needs + OpenStruct.new( + skill1: grade_params[:skill1] || {}, + skill2: grade_params[:skill2] || {}, + skill3: grade_params[:skill3] || {}, + skill4: grade_params[:skill4] || {}, + artifact: base_artifact || OpenStruct.new(quirk?: false) + ) + end + + def grade_params + params.permit( + :artifact_id, + skill1: %i[modifier strength level], + skill2: %i[modifier strength level], + skill3: %i[modifier strength level], + skill4: %i[modifier strength level] + ) + end end end end diff --git a/config/routes.rb b/config/routes.rb index c1034f0..dc0f5e7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -102,7 +102,11 @@ Rails.application.routes.draw do resources :weapon_series, only: %i[index show create update destroy] # Artifacts (read-only reference data) - resources :artifacts, only: %i[index show] + resources :artifacts, only: %i[index show] do + collection do + post :grade + end + end resources :artifact_skills, only: %i[index] do collection do get 'for_slot/:slot', action: :for_slot, as: :for_slot