dawarich/app/services/geojson/importer.rb

29 lines
635 B
Ruby
Raw Permalink Normal View History

2024-09-02 16:33:54 -04:00
# frozen_string_literal: true
2025-04-23 17:36:16 -04:00
class Geojson::Importer
include Imports::Broadcaster
include PointValidation
attr_reader :import, :user_id
2024-09-02 16:33:54 -04:00
def initialize(import, user_id)
@import = import
@user_id = user_id
end
def call
2025-04-23 17:27:55 -04:00
file_content = Imports::SecureFileDownloader.new(import.file).download_with_verification
json = Oj.load(file_content)
2024-09-02 16:33:54 -04:00
2025-04-23 17:27:55 -04:00
data = Geojson::Params.new(json).call
2024-09-02 16:33:54 -04:00
2025-04-23 17:27:55 -04:00
data.each.with_index(1) do |point, index|
next if point_exists?(point, user_id)
2025-04-23 17:27:55 -04:00
Point.create!(point.merge(user_id:, import_id: import.id))
2024-09-02 16:33:54 -04:00
2025-04-23 17:27:55 -04:00
broadcast_import_progress(import, index)
end
2024-09-02 16:33:54 -04:00
end
end