diff --git a/app/controllers/api/v1/collection_characters_controller.rb b/app/controllers/api/v1/collection_characters_controller.rb index 43ff811..29dc59c 100644 --- a/app/controllers/api/v1/collection_characters_controller.rb +++ b/app/controllers/api/v1/collection_characters_controller.rb @@ -7,7 +7,7 @@ module Api before_action :set_collection_character_for_read, only: %i[show] # Write actions: require auth, use current_user - before_action :restrict_access, only: %i[create update destroy batch import] + before_action :restrict_access, only: %i[create update destroy batch batch_destroy import] before_action :set_collection_character_for_write, only: %i[update destroy] def index @@ -113,6 +113,17 @@ module Api ), status: status end + # DELETE /collection/characters/batch_destroy + # Deletes multiple collection characters in a single request + def batch_destroy + ids = batch_destroy_params[:ids] || [] + deleted_count = current_user.collection_characters.where(id: ids).destroy_all.count + + render json: { + meta: { deleted: deleted_count } + }, status: :ok + end + # POST /collection/characters/import # Imports characters from game JSON data # @@ -201,6 +212,10 @@ module Api data: params[:data]&.to_unsafe_h } end + + def batch_destroy_params + params.permit(ids: []) + end end end end diff --git a/app/controllers/api/v1/collection_summons_controller.rb b/app/controllers/api/v1/collection_summons_controller.rb index 673ac97..e53648a 100644 --- a/app/controllers/api/v1/collection_summons_controller.rb +++ b/app/controllers/api/v1/collection_summons_controller.rb @@ -7,7 +7,7 @@ module Api before_action :set_collection_summon_for_read, only: %i[show] # Write actions: require auth, use current_user - before_action :restrict_access, only: %i[create update destroy batch import] + before_action :restrict_access, only: %i[create update destroy batch batch_destroy import] before_action :set_collection_summon_for_write, only: %i[update destroy] def index @@ -96,6 +96,17 @@ module Api ), status: status end + # DELETE /collection/summons/batch_destroy + # Deletes multiple collection summons in a single request + def batch_destroy + ids = batch_destroy_params[:ids] || [] + deleted_count = current_user.collection_summons.where(id: ids).destroy_all.count + + render json: { + meta: { deleted: deleted_count } + }, status: :ok + end + # POST /collection/summons/import # Imports summons from game JSON data # @@ -172,6 +183,10 @@ module Api data: params[:data]&.to_unsafe_h } end + + def batch_destroy_params + params.permit(ids: []) + end end end end diff --git a/app/controllers/api/v1/collection_weapons_controller.rb b/app/controllers/api/v1/collection_weapons_controller.rb index 9ae14a5..3353b32 100644 --- a/app/controllers/api/v1/collection_weapons_controller.rb +++ b/app/controllers/api/v1/collection_weapons_controller.rb @@ -7,7 +7,7 @@ module Api before_action :set_collection_weapon_for_read, only: %i[show] # Write actions: require auth, use current_user - before_action :restrict_access, only: %i[create update destroy batch import] + before_action :restrict_access, only: %i[create update destroy batch batch_destroy import] before_action :set_collection_weapon_for_write, only: %i[update destroy] def index @@ -102,6 +102,17 @@ module Api ), status: status end + # DELETE /collection/weapons/batch_destroy + # Deletes multiple collection weapons in a single request + def batch_destroy + ids = batch_destroy_params[:ids] || [] + deleted_count = current_user.collection_weapons.where(id: ids).destroy_all.count + + render json: { + meta: { deleted: deleted_count } + }, status: :ok + end + # POST /collection/weapons/import # Imports weapons from game JSON data # @@ -186,6 +197,10 @@ module Api data: params[:data]&.to_unsafe_h } end + + def batch_destroy_params + params.permit(ids: []) + end end end end diff --git a/config/routes.rb b/config/routes.rb index 17f20f9..db71b63 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -262,18 +262,21 @@ Rails.application.routes.draw do resources :characters, only: [:create, :update, :destroy], controller: '/api/v1/collection_characters' do collection do post :batch + delete :batch_destroy post :import end end resources :weapons, only: [:create, :update, :destroy], controller: '/api/v1/collection_weapons' do collection do post :batch + delete :batch_destroy post :import end end resources :summons, only: [:create, :update, :destroy], controller: '/api/v1/collection_summons' do collection do post :batch + delete :batch_destroy post :import end end @@ -282,6 +285,7 @@ Rails.application.routes.draw do resources :artifacts, only: [:create, :update, :destroy], controller: '/api/v1/collection_artifacts' do collection do post :batch + delete :batch_destroy post :import end end