demarches-normaliennes/app/services/procedure_archive_service.rb

39 lines
1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require 'tempfile'
class ProcedureArchiveService
def initialize(procedure)
@procedure = procedure
end
def make_and_upload_archive(archive)
dossiers = Dossier.visible_by_administration
.where(groupe_instructeur: archive.groupe_instructeurs)
dossiers = if archive.time_span_type == 'everything'
dossiers.state_termine
else
dossiers.processed_in_month(archive.month)
end
attachments = ActiveStorage::DownloadableFile.create_list_from_dossiers(dossiers:, user_profile: archive.user_profile)
2022-04-04 17:45:10 +02:00
DownloadableFileService.download_and_zip(@procedure, attachments, zip_root_folder(archive)) do |zip_filepath|
ArchiveUploader.new(procedure: @procedure, filename: archive.filename(@procedure), filepath: zip_filepath)
.upload(archive)
end
end
private
def zip_root_folder(archive)
zip_filename = archive.filename(@procedure)
[
File.basename(zip_filename, File.extname(zip_filename)),
archive.id
].join("-")
2021-08-04 15:08:14 +02:00
end
end