diff options
Diffstat (limited to 'lib/api/project_export.rb')
-rw-r--r-- | lib/api/project_export.rb | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/lib/api/project_export.rb b/lib/api/project_export.rb index 19e5ed3f9e0..8a72ec051dc 100644 --- a/lib/api/project_export.rb +++ b/lib/api/project_export.rb @@ -127,8 +127,13 @@ module API ] tags ['project_export'] end + params do + optional :batched, type: Boolean, desc: 'Whether to export in batches' + end post ':id/export_relations' do - response = ::BulkImports::ExportService.new(portable: user_project, user: current_user).execute + response = ::BulkImports::ExportService + .new(portable: user_project, user: current_user, batched: params[:batched]) + .execute if response.success? accepted! @@ -152,19 +157,33 @@ module API produces %w[application/octet-stream application/json] end params do - requires :relation, - type: String, - project_portable: true, - desc: 'Project relation name' + requires :relation, type: String, project_portable: true, desc: 'Project relation name' + optional :batched, type: Boolean, desc: 'Whether to download in batches' + optional :batch_number, type: Integer, desc: 'Batch number to download' + + all_or_none_of :batched, :batch_number end get ':id/export_relations/download' do export = user_project.bulk_import_exports.find_by_relation(params[:relation]) - file = export&.upload&.export_file - if file - present_carrierwave_file!(file) + break render_api_error!('Export not found', 404) unless export + + if params[:batched] + batch = export.batches.find_by_batch_number(params[:batch_number]) + batch_file = batch&.upload&.export_file + + break render_api_error!('Export is not batched', 400) unless export.batched? + break render_api_error!('Batch not found', 404) unless batch + break render_api_error!('Batch file not found', 404) unless batch_file + + present_carrierwave_file!(batch_file) else - render_api_error!('404 Not found', 404) + file = export&.upload&.export_file + + break render_api_error!('Export is batched', 400) if export.batched? + break render_api_error!('Export file not found', 404) unless file + + present_carrierwave_file!(file) end end @@ -180,8 +199,19 @@ module API ] tags ['project_export'] end + params do + optional :relation, type: String, desc: 'Project relation name' + end get ':id/export_relations/status' do - present user_project.bulk_import_exports, with: Entities::BulkImports::ExportStatus + if params[:relation] + export = user_project.bulk_import_exports.find_by_relation(params[:relation]) + + break render_api_error!('Export not found', 404) unless export + + present export, with: Entities::BulkImports::ExportStatus + else + present user_project.bulk_import_exports, with: Entities::BulkImports::ExportStatus + end end end end |