Update JobsController and JobSkillsController for blueprinter
This commit is contained in:
parent
349c42f839
commit
9a27ac853d
3 changed files with 25 additions and 19 deletions
|
|
@ -21,6 +21,17 @@ module Api
|
||||||
view: :nested
|
view: :nested
|
||||||
end
|
end
|
||||||
|
|
||||||
|
view :job_skills do
|
||||||
|
field :job_skills do |job|
|
||||||
|
{
|
||||||
|
'0' => !job.skill0.nil? ? JobSkillBlueprint.render_as_hash(job.skill0) : nil,
|
||||||
|
'1' => !job.skill1.nil? ? JobSkillBlueprint.render_as_hash(job.skill1) : nil,
|
||||||
|
'2' => !job.skill2.nil? ? JobSkillBlueprint.render_as_hash(job.skill2) : nil,
|
||||||
|
'3' => !job.skill3.nil? ? JobSkillBlueprint.render_as_hash(job.skill3) : nil
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
view :minimal do
|
view :minimal do
|
||||||
fields :name, :element, :shortcode, :favorited, :extra, :created_at, :updated_at
|
fields :name, :element, :shortcode, :favorited, :extra, :created_at, :updated_at
|
||||||
|
|
||||||
|
|
@ -31,6 +42,12 @@ module Api
|
||||||
blueprint: JobBlueprint
|
blueprint: JobBlueprint
|
||||||
end
|
end
|
||||||
|
|
||||||
|
view :jobs do
|
||||||
|
association :job,
|
||||||
|
blueprint: JobBlueprint
|
||||||
|
include_view :job_skills
|
||||||
|
end
|
||||||
|
|
||||||
view :preview do
|
view :preview do
|
||||||
include_view :minimal
|
include_view :minimal
|
||||||
include_view :weapons
|
include_view :weapons
|
||||||
|
|
@ -40,17 +57,9 @@ module Api
|
||||||
include_view :preview
|
include_view :preview
|
||||||
include_view :summons
|
include_view :summons
|
||||||
include_view :characters
|
include_view :characters
|
||||||
|
include_view :job_skills
|
||||||
|
|
||||||
fields :description, :extra
|
fields :description, :extra
|
||||||
|
|
||||||
field :job_skills do |job|
|
|
||||||
{
|
|
||||||
'0' => !job.skill0.nil? ? JobSkillBlueprint.render_as_hash(job.skill0) : nil,
|
|
||||||
'1' => !job.skill1.nil? ? JobSkillBlueprint.render_as_hash(job.skill1) : nil,
|
|
||||||
'2' => !job.skill2.nil? ? JobSkillBlueprint.render_as_hash(job.skill2) : nil,
|
|
||||||
'3' => !job.skill3.nil? ? JobSkillBlueprint.render_as_hash(job.skill3) : nil
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
view :collection do
|
view :collection do
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,13 @@ module Api
|
||||||
module V1
|
module V1
|
||||||
class JobSkillsController < Api::V1::ApiController
|
class JobSkillsController < Api::V1::ApiController
|
||||||
def all
|
def all
|
||||||
@skills = JobSkill.all
|
render json: JobSkillBlueprint.render(JobSkill.all)
|
||||||
render :all, status: :ok
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def job
|
def job
|
||||||
job = Job.find(params[:id])
|
@skills = JobSkill.where(job: Job.find(params[:id]))
|
||||||
|
.or(JobSkill.where(sub: true))
|
||||||
@skills = JobSkill.where(job: job).or(JobSkill.where(sub: true))
|
render json: JobSkillBlueprint.render(@skills)
|
||||||
render :all, status: :ok
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@ module Api
|
||||||
before_action :set, only: %w[update_job update_job_skills]
|
before_action :set, only: %w[update_job update_job_skills]
|
||||||
|
|
||||||
def all
|
def all
|
||||||
@jobs = Job.all
|
render json: JobBlueprint.render(Job.all)
|
||||||
render :all, status: :ok
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_job
|
def update_job
|
||||||
|
|
@ -28,7 +27,7 @@ module Api
|
||||||
@party[key] = nil if @party[key] && mismatched_skill(@party.job, JobSkill.find(@party[key]))
|
@party[key] = nil if @party[key] && mismatched_skill(@party.job, JobSkill.find(@party[key]))
|
||||||
end
|
end
|
||||||
|
|
||||||
render :update, status: :ok if @party.save!
|
render json: PartyBlueprint.render(@party, view: :jobs) if @party.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_job_skills
|
def update_job_skills
|
||||||
|
|
@ -63,7 +62,7 @@ module Api
|
||||||
@party.attributes = new_skill_ids
|
@party.attributes = new_skill_ids
|
||||||
end
|
end
|
||||||
|
|
||||||
render :update, status: :ok if @party.save!
|
render json: PartyBlueprint.render(@party, view: :jobs) if @party.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue