add import endpoints to collection controllers
This commit is contained in:
parent
860177c0a4
commit
aa198f072b
3 changed files with 108 additions and 3 deletions
|
|
@ -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]
|
||||
before_action :restrict_access, only: %i[create update destroy batch import]
|
||||
before_action :set_collection_character_for_write, only: %i[update destroy]
|
||||
|
||||
def index
|
||||
|
|
@ -113,6 +113,37 @@ module Api
|
|||
), status: status
|
||||
end
|
||||
|
||||
# POST /collection/characters/import
|
||||
# Imports characters from game JSON data
|
||||
#
|
||||
# @param data [Hash] Game data containing character list
|
||||
# @param update_existing [Boolean] Whether to update existing characters (default: false)
|
||||
def import
|
||||
game_data = import_params[:data]
|
||||
|
||||
unless game_data.present?
|
||||
return render json: { error: 'No data provided' }, status: :bad_request
|
||||
end
|
||||
|
||||
service = CharacterImportService.new(
|
||||
current_user,
|
||||
game_data,
|
||||
update_existing: import_params[:update_existing] == true
|
||||
)
|
||||
|
||||
result = service.import
|
||||
|
||||
status = result.success? ? :created : :multi_status
|
||||
|
||||
render json: {
|
||||
success: result.success?,
|
||||
created: result.created.size,
|
||||
updated: result.updated.size,
|
||||
skipped: result.skipped.size,
|
||||
errors: result.errors
|
||||
}, status: status
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_target_user
|
||||
|
|
@ -163,6 +194,10 @@ module Api
|
|||
earring: %i[modifier strength]
|
||||
])
|
||||
end
|
||||
|
||||
def import_params
|
||||
params.permit(:update_existing, data: {})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
before_action :restrict_access, only: %i[create update destroy batch import]
|
||||
before_action :set_collection_summon_for_write, only: %i[update destroy]
|
||||
|
||||
def index
|
||||
|
|
@ -96,6 +96,37 @@ module Api
|
|||
), status: status
|
||||
end
|
||||
|
||||
# POST /collection/summons/import
|
||||
# Imports summons from game JSON data
|
||||
#
|
||||
# @param data [Hash] Game data containing summon list
|
||||
# @param update_existing [Boolean] Whether to update existing summons (default: false)
|
||||
def import
|
||||
game_data = import_params[:data]
|
||||
|
||||
unless game_data.present?
|
||||
return render json: { error: 'No data provided' }, status: :bad_request
|
||||
end
|
||||
|
||||
service = SummonImportService.new(
|
||||
current_user,
|
||||
game_data,
|
||||
update_existing: import_params[:update_existing] == true
|
||||
)
|
||||
|
||||
result = service.import
|
||||
|
||||
status = result.success? ? :created : :multi_status
|
||||
|
||||
render json: {
|
||||
success: result.success?,
|
||||
created: result.created.size,
|
||||
updated: result.updated.size,
|
||||
skipped: result.skipped.size,
|
||||
errors: result.errors
|
||||
}, status: status
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_target_user
|
||||
|
|
@ -134,6 +165,10 @@ module Api
|
|||
:summon_id, :uncap_level, :transcendence_step
|
||||
])
|
||||
end
|
||||
|
||||
def import_params
|
||||
params.permit(:update_existing, data: {})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
before_action :restrict_access, only: %i[create update destroy batch import]
|
||||
before_action :set_collection_weapon_for_write, only: %i[update destroy]
|
||||
|
||||
def index
|
||||
|
|
@ -98,6 +98,37 @@ module Api
|
|||
), status: status
|
||||
end
|
||||
|
||||
# POST /collection/weapons/import
|
||||
# Imports weapons from game JSON data
|
||||
#
|
||||
# @param data [Hash] Game data containing weapon list
|
||||
# @param update_existing [Boolean] Whether to update existing weapons (default: false)
|
||||
def import
|
||||
game_data = import_params[:data]
|
||||
|
||||
unless game_data.present?
|
||||
return render json: { error: 'No data provided' }, status: :bad_request
|
||||
end
|
||||
|
||||
service = WeaponImportService.new(
|
||||
current_user,
|
||||
game_data,
|
||||
update_existing: import_params[:update_existing] == true
|
||||
)
|
||||
|
||||
result = service.import
|
||||
|
||||
status = result.success? ? :created : :multi_status
|
||||
|
||||
render json: {
|
||||
success: result.success?,
|
||||
created: result.created.size,
|
||||
updated: result.updated.size,
|
||||
skipped: result.skipped.size,
|
||||
errors: result.errors
|
||||
}, status: status
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_target_user
|
||||
|
|
@ -144,6 +175,10 @@ module Api
|
|||
:element
|
||||
])
|
||||
end
|
||||
|
||||
def import_params
|
||||
params.permit(:update_existing, data: {})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue