add batch_destroy endpoints for collection items

This commit is contained in:
Justin Edmund 2025-12-19 00:39:47 -08:00
parent efa8dec43a
commit 9ce86b22b4
4 changed files with 52 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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