From beeeef310401805579b1a6368407dc47f466ec75 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 8 Jan 2023 01:16:25 -0800 Subject: [PATCH 1/3] TEMP: Comment out problematic code We don't ever send parameters when posting a party, so for now we don't need to worry about this. We can't leave this like this though: You should be able to send a complete party in the future (for API creation via strings) --- app/controllers/api/v1/parties_controller.rb | 30 +++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index 88d0953..169312c 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -8,22 +8,24 @@ module Api before_action :set, only: %w[update destroy] def create - @party = Party.new(shortcode: random_string) - @party.extra = party_params['extra'] + party = Party.new(shortcode: random_string) + party.user = current_user if current_user - # TODO: Extract this into a different method - job = Job.find(party_params['job_id']) if party_params['job_id'].present? - if job - job_skills = JobSkill.where(job: job.id, main: true) - job_skills.each_with_index do |skill, index| - @party["skill#{index}_id"] = skill.id - end - end + # unless party_params.empty? + # party.attributes = party_params + # + # # TODO: Extract this into a different method + # job = Job.find(party_params['job_id']) if party_params['job_id'].present? + # if job + # job_skills = JobSkill.where(job: job.id, main: true) + # job_skills.each_with_index do |skill, index| + # party["skill#{index}_id"] = skill.id + # end + # end + # end - @party.user = current_user if current_user - - if @party.save! - return render json: PartyBlueprint.render(@party, view: :full, root: :party), + if party.save! + return render json: PartyBlueprint.render(party, view: :full, root: :party), status: :created end From 382b2e2a92bd7898c258846c73b382bae0bd2e22 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 8 Jan 2023 01:16:43 -0800 Subject: [PATCH 2/3] Enable extra if the GridWeapon is in position 9, 10, 11 --- app/controllers/api/v1/grid_weapons_controller.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/grid_weapons_controller.rb b/app/controllers/api/v1/grid_weapons_controller.rb index aa0ad4d..94c9563 100644 --- a/app/controllers/api/v1/grid_weapons_controller.rb +++ b/app/controllers/api/v1/grid_weapons_controller.rb @@ -115,15 +115,15 @@ module Api # Render the conflict view as a string def render_conflict_view(conflict_weapon, incoming_weapon, incoming_position) ConflictBlueprint.render(nil, view: :weapons, - conflict_weapon: conflict_weapon, - incoming_weapon: incoming_weapon, - incoming_position: incoming_position) + conflict_weapon: conflict_weapon, + incoming_weapon: incoming_weapon, + incoming_position: incoming_position) end def render_grid_weapon_view(grid_weapon, conflict_position) GridWeaponBlueprint.render(grid_weapon, view: :full, - root: :grid_weapon, - meta: { replaced: conflict_position }) + root: :grid_weapon, + meta: { replaced: conflict_position }) end def save_weapon(weapon) @@ -140,6 +140,9 @@ module Api if weapon.position == -1 party.element = weapon.weapon.element party.save! + elsif [9, 10, 11].include?(weapon.position) + party.extra = true + party.save! end # Render the weapon if it can be saved From 78df1df683509451d688d8c18653f33ec470f9e2 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 8 Jan 2023 01:30:12 -0800 Subject: [PATCH 3/3] Allow empty strong params --- app/controllers/api/v1/parties_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index 169312c..258de6a 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -11,6 +11,10 @@ module Api party = Party.new(shortcode: random_string) party.user = current_user if current_user + if party_params + party.attributes = party_params + end + # unless party_params.empty? # party.attributes = party_params # @@ -152,7 +156,7 @@ module Api :button_count, :turn_count, :chain_count - ) + ) if params[:party].present? end end end