Return proper REST response for deleting a party

This commit is contained in:
Justin Edmund 2025-09-22 00:50:30 -07:00
parent 02d189e18a
commit 4eee998cea

View file

@ -44,11 +44,9 @@ module Api
def create
party = Party.new(party_params)
party.user = current_user if current_user
if party_params && party_params[:raid_id].present?
if (raid = Raid.find_by(id: party_params[:raid_id]))
if party_params && party_params[:raid_id].present? && (raid = Raid.find_by(id: party_params[:raid_id]))
party.extra = raid.group.extra
end
end
if party.save
party.schedule_preview_generation if party.ready_for_preview?
render json: PartyBlueprint.render(party, view: :created, root: :party), status: :created
@ -71,11 +69,9 @@ module Api
# Updates an existing party.
def update
@party.attributes = party_params.except(:skill1_id, :skill2_id, :skill3_id)
if party_params && party_params[:raid_id]
if (raid = Raid.find_by(id: party_params[:raid_id]))
if party_params && party_params[:raid_id] && (raid = Raid.find_by(id: party_params[:raid_id]))
@party.extra = raid.group.extra
end
end
if @party.save
render json: PartyBlueprint.render(@party, view: :full, root: :party)
else
@ -85,7 +81,7 @@ module Api
# Deletes a party.
def destroy
render json: PartyBlueprint.render(@party, view: :destroyed, root: :checkin) if @party.destroy
head :no_content if @party.destroy
end
# Extended Party Actions
@ -93,7 +89,8 @@ module Api
# Creates a remixed copy of an existing party.
def remix
new_party = @party.amoeba_dup
new_party.attributes = { user: current_user, name: remixed_name(@party.name), source_party: @party, remix: true }
new_party.attributes = { user: current_user, name: remixed_name(@party.name), source_party: @party,
remix: true }
new_party.local_id = party_params[:local_id] if party_params
if new_party.save
new_party.schedule_preview_generation
@ -125,9 +122,7 @@ module Api
end
# Compact character positions if needed
if options[:maintain_character_sequence]
compact_party_character_positions
end
compact_party_character_positions if options[:maintain_character_sequence]
end
render json: {
@ -173,7 +168,8 @@ module Api
# Returns the current preview status of a party.
def preview_status
party = Party.find_by!(shortcode: params[:id])
render json: { state: party.preview_state, generated_at: party.preview_generated_at, ready_for_preview: party.ready_for_preview? }
render json: { state: party.preview_state, generated_at: party.preview_generated_at,
ready_for_preview: party.ready_for_preview? }
end
# Forces regeneration of the party preview.
@ -202,8 +198,7 @@ module Api
weapon_key1: {},
weapon_key2: {},
weapon_key3: {}
}
},
} },
{ summons: :summon },
:guidebook1, :guidebook2, :guidebook3,
:source_party, :remixes, :skill0, :skill1, :skill2, :skill3, :accessory
@ -237,8 +232,8 @@ module Api
# Permits parameters for grid update operation.
def grid_update_params
params.permit(
operations: [:type, :entity, :id, :source_id, :target_id, :position, :container],
options: [:maintain_character_sequence, :validate_before_execute]
operations: %i[type entity id source_id target_id position container],
options: %i[maintain_character_sequence validate_before_execute]
)
end