diff --git a/app/blueprints/api/v1/grid_summon_blueprint.rb b/app/blueprints/api/v1/grid_summon_blueprint.rb index af2cec6..1a27594 100644 --- a/app/blueprints/api/v1/grid_summon_blueprint.rb +++ b/app/blueprints/api/v1/grid_summon_blueprint.rb @@ -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 diff --git a/app/controllers/api/v1/grid_summons_controller.rb b/app/controllers/api/v1/grid_summons_controller.rb index cf9ea7d..6fbc3f1 100644 --- a/app/controllers/api/v1/grid_summons_controller.rb +++ b/app/controllers/api/v1/grid_summons_controller.rb @@ -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) diff --git a/app/controllers/api/v1/grid_weapons_controller.rb b/app/controllers/api/v1/grid_weapons_controller.rb index 7282161..652fdbc 100644 --- a/app/controllers/api/v1/grid_weapons_controller.rb +++ b/app/controllers/api/v1/grid_weapons_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 38775d6..e9a6b9f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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'