add POST /artifacts/grade endpoint
allows grading artifact skills without persisting a record
This commit is contained in:
parent
c3dbab896c
commit
fd1c363352
2 changed files with 43 additions and 1 deletions
|
|
@ -19,6 +19,21 @@ module Api
|
||||||
render json: ArtifactBlueprint.render(@artifact)
|
render json: ArtifactBlueprint.render(@artifact)
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def set_artifact
|
def set_artifact
|
||||||
|
|
@ -26,6 +41,29 @@ module Api
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_not_found_response('artifact')
|
render_not_found_response('artifact')
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,11 @@ Rails.application.routes.draw do
|
||||||
resources :weapon_series, only: %i[index show create update destroy]
|
resources :weapon_series, only: %i[index show create update destroy]
|
||||||
|
|
||||||
# Artifacts (read-only reference data)
|
# 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
|
resources :artifact_skills, only: %i[index] do
|
||||||
collection do
|
collection do
|
||||||
get 'for_slot/:slot', action: :for_slot, as: :for_slot
|
get 'for_slot/:slot', action: :for_slot, as: :for_slot
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue