Refactor parties#create
This commit is contained in:
parent
b526ce2138
commit
09dc344e35
1 changed files with 14 additions and 10 deletions
|
|
@ -38,21 +38,25 @@ module Api
|
||||||
# Creates a new party with optional user association
|
# Creates a new party with optional user association
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def create
|
def create
|
||||||
party = Party.new
|
# Build the party with the provided parameters and assign the user
|
||||||
|
party = Party.new(party_params)
|
||||||
party.user = current_user if current_user
|
party.user = current_user if current_user
|
||||||
party.attributes = party_params if party_params
|
|
||||||
|
|
||||||
if party_params && party_params[:raid_id]
|
# If a raid_id is given, look it up and assign the extra flag from its group.
|
||||||
raid = Raid.find_by(id: party_params[:raid_id])
|
if party_params && party_params[:raid_id].present?
|
||||||
party.extra = raid.group.extra
|
if (raid = Raid.find_by(id: party_params[:raid_id]))
|
||||||
|
party.extra = raid.group.extra
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if party.save!
|
# Save and render the party, triggering preview generation if the party is ready
|
||||||
return render json: PartyBlueprint.render(party, view: :created, root: :party),
|
if party.save
|
||||||
status: :created
|
party.schedule_preview_generation if party.ready_for_preview?
|
||||||
|
render json: PartyBlueprint.render(party, view: :created, root: :party),
|
||||||
|
status: :created
|
||||||
|
else
|
||||||
|
render_validation_error_response(party)
|
||||||
end
|
end
|
||||||
|
|
||||||
render_validation_error_response(@party)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Shows a specific party if the user has permission to view it
|
# Shows a specific party if the user has permission to view it
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue