2024-06-12 14:29:38 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class ExportsController < ApplicationController
|
2025-04-03 12:41:05 -04:00
|
|
|
include ActiveStorage::SetCurrent
|
|
|
|
|
|
2024-06-12 14:29:38 -04:00
|
|
|
before_action :authenticate_user!
|
|
|
|
|
before_action :set_export, only: %i[destroy]
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
@exports = current_user.exports.order(created_at: :desc).page(params[:page])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
2024-12-11 08:42:26 -05:00
|
|
|
export_name =
|
|
|
|
|
"export_from_#{params[:start_at].to_date}_to_#{params[:end_at].to_date}.#{params[:file_format]}"
|
2025-03-24 15:46:16 -04:00
|
|
|
export = current_user.exports.create(
|
|
|
|
|
name: export_name,
|
|
|
|
|
status: :created,
|
2025-04-02 15:19:02 -04:00
|
|
|
file_format: params[:file_format],
|
2025-03-24 15:46:16 -04:00
|
|
|
start_at: params[:start_at],
|
|
|
|
|
end_at: params[:end_at]
|
|
|
|
|
)
|
2024-06-12 14:29:38 -04:00
|
|
|
|
|
|
|
|
redirect_to exports_url, notice: 'Export was successfully initiated. Please wait until it\'s finished.'
|
|
|
|
|
rescue StandardError => e
|
|
|
|
|
export&.destroy
|
|
|
|
|
|
2025-05-03 14:36:09 -04:00
|
|
|
ExceptionReporter.call(e)
|
|
|
|
|
|
2025-09-12 15:08:45 -04:00
|
|
|
redirect_to exports_url, alert: "Export failed to initiate: #{e.message}", status: :unprocessable_content
|
2024-06-12 14:29:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
2025-03-24 15:46:16 -04:00
|
|
|
@export.destroy
|
2024-06-12 14:29:38 -04:00
|
|
|
|
|
|
|
|
redirect_to exports_url, notice: 'Export was successfully destroyed.', status: :see_other
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def set_export
|
|
|
|
|
@export = current_user.exports.find(params[:id])
|
|
|
|
|
end
|
|
|
|
|
end
|