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,10 +44,8 @@ module Api
def create def create
party = Party.new(party_params) party = Party.new(party_params)
party.user = current_user if current_user party.user = current_user if current_user
if party_params && party_params[:raid_id].present? if party_params && party_params[:raid_id].present? && (raid = Raid.find_by(id: party_params[:raid_id]))
if (raid = Raid.find_by(id: party_params[:raid_id])) party.extra = raid.group.extra
party.extra = raid.group.extra
end
end end
if party.save if party.save
party.schedule_preview_generation if party.ready_for_preview? party.schedule_preview_generation if party.ready_for_preview?
@ -71,10 +69,8 @@ module Api
# Updates an existing party. # Updates an existing party.
def update def update
@party.attributes = party_params.except(:skill1_id, :skill2_id, :skill3_id) @party.attributes = party_params.except(:skill1_id, :skill2_id, :skill3_id)
if party_params && party_params[:raid_id] if party_params && party_params[:raid_id] && (raid = Raid.find_by(id: party_params[:raid_id]))
if (raid = Raid.find_by(id: party_params[:raid_id])) @party.extra = raid.group.extra
@party.extra = raid.group.extra
end
end end
if @party.save if @party.save
render json: PartyBlueprint.render(@party, view: :full, root: :party) render json: PartyBlueprint.render(@party, view: :full, root: :party)
@ -85,7 +81,7 @@ module Api
# Deletes a party. # Deletes a party.
def destroy def destroy
render json: PartyBlueprint.render(@party, view: :destroyed, root: :checkin) if @party.destroy head :no_content if @party.destroy
end end
# Extended Party Actions # Extended Party Actions
@ -93,7 +89,8 @@ module Api
# Creates a remixed copy of an existing party. # Creates a remixed copy of an existing party.
def remix def remix
new_party = @party.amoeba_dup 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 new_party.local_id = party_params[:local_id] if party_params
if new_party.save if new_party.save
new_party.schedule_preview_generation new_party.schedule_preview_generation
@ -125,9 +122,7 @@ module Api
end end
# Compact character positions if needed # Compact character positions if needed
if options[:maintain_character_sequence] compact_party_character_positions if options[:maintain_character_sequence]
compact_party_character_positions
end
end end
render json: { render json: {
@ -153,9 +148,9 @@ module Api
raise Api::V1::UnauthorizedError unless current_user raise Api::V1::UnauthorizedError unless current_user
base_query = build_common_base_query base_query = build_common_base_query
.joins(:favorites) .joins(:favorites)
.where(favorites: { user_id: current_user.id }) .where(favorites: { user_id: current_user.id })
.distinct .distinct
query = build_filtered_query(base_query) query = build_filtered_query(base_query)
@parties = query.paginate(page: params[:page], per_page: page_size) @parties = query.paginate(page: params[:page], per_page: page_size)
render_paginated_parties(@parties, page_size) render_paginated_parties(@parties, page_size)
@ -173,7 +168,8 @@ module Api
# Returns the current preview status of a party. # Returns the current preview status of a party.
def preview_status def preview_status
party = Party.find_by!(shortcode: params[:id]) 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 end
# Forces regeneration of the party preview. # Forces regeneration of the party preview.
@ -202,8 +198,7 @@ module Api
weapon_key1: {}, weapon_key1: {},
weapon_key2: {}, weapon_key2: {},
weapon_key3: {} weapon_key3: {}
} } },
},
{ summons: :summon }, { summons: :summon },
:guidebook1, :guidebook2, :guidebook3, :guidebook1, :guidebook2, :guidebook3,
:source_party, :remixes, :skill0, :skill1, :skill2, :skill3, :accessory :source_party, :remixes, :skill0, :skill1, :skill2, :skill3, :accessory
@ -237,8 +232,8 @@ module Api
# Permits parameters for grid update operation. # Permits parameters for grid update operation.
def grid_update_params def grid_update_params
params.permit( params.permit(
operations: [:type, :entity, :id, :source_id, :target_id, :position, :container], operations: %i[type entity id source_id target_id position container],
options: [:maintain_character_sequence, :validate_before_execute] options: %i[maintain_character_sequence validate_before_execute]
) )
end end