2024-06-12 14:29:38 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class Export < ApplicationRecord
|
|
|
|
|
belongs_to :user
|
|
|
|
|
|
2024-09-05 15:01:59 -04:00
|
|
|
enum :status, { created: 0, processing: 1, completed: 2, failed: 3 }
|
2025-03-24 15:46:16 -04:00
|
|
|
enum :format, { json: 0, gpx: 1 }
|
2024-06-12 14:29:38 -04:00
|
|
|
|
|
|
|
|
validates :name, presence: true
|
|
|
|
|
|
2025-03-24 15:46:16 -04:00
|
|
|
has_one_attached :file
|
2024-06-12 14:29:38 -04:00
|
|
|
|
2025-03-24 15:46:16 -04:00
|
|
|
after_commit -> { ExportJob.perform_later(id) }, on: :create
|
|
|
|
|
after_commit -> { file.purge }, on: :destroy
|
2024-06-12 14:29:38 -04:00
|
|
|
|
2025-03-24 15:46:16 -04:00
|
|
|
def process!
|
|
|
|
|
Exports::Create.new(export: self).call
|
2024-06-12 14:29:38 -04:00
|
|
|
end
|
|
|
|
|
end
|