Implement deleting summons

This commit is contained in:
Justin Edmund 2023-01-21 15:41:16 -08:00
parent 633db43e94
commit c5f2c9d080
4 changed files with 15 additions and 3 deletions

View file

@ -17,6 +17,10 @@ module Api
include_view :nested
association :party, blueprint: PartyBlueprint, view: :minimal
end
view :destroyed do
fields :main, :friend, :position, :created_at, :updated_at
end
end
end
end

View file

@ -3,6 +3,8 @@
module Api
module V1
class GridSummonsController < Api::V1::ApiController
before_action :set, only: %w[destroy]
def create
party = Party.find(summon_params[:party_id])
canonical_summon = Summon.find(summon_params[:summon_id])
@ -31,11 +33,17 @@ module Api
render json: GridSummonBlueprint.render(summon, view: :nested, root: :grid_summon)
end
# TODO: Implement removing summons
def destroy; end
def destroy
render_unauthorized_response if @summon.party.user != current_user
return render json: GridSummonBlueprint.render(@summon, view: :destroyed) if @summon.destroy
end
private
def set
@summon = GridSummon.where('id = ?', params[:id]).first
end
# Specify whitelisted properties that can be modified.
def summon_params
params.require(:summon).permit(:id, :party_id, :summon_id, :position, :main, :friend, :uncap_level)

View file

@ -55,7 +55,6 @@ module Api
render json: GridWeaponBlueprint.render(@weapon, view: :nested) if @weapon.update(weapon_params)
end
# TODO: Implement removing characters
def destroy
render_unauthorized_response if @weapon.party.user != current_user
return render json: GridCharacterBlueprint.render(@weapon, view: :destroyed) if @weapon.destroy

View file

@ -10,6 +10,7 @@ Rails.application.routes.draw do
resources :users, only: %i[create update show]
resources :grid_weapons, only: %i[update destroy]
resources :grid_characters, only: %i[update destroy]
resources :grid_summons, only: %i[destroy]
resources :favorites, only: [:create]
get 'users/info/:id', to: 'users#info'