Export trips data

This commit is contained in:
Eugene Burmakin 2025-06-25 21:21:03 +02:00
parent 7988fadd5f
commit 6ebf58d7ad
2 changed files with 19 additions and 13 deletions

View file

@ -13,8 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [ ] All your areas - [ ] All your areas
- [ ] All your visits - [ ] All your visits
- [x] All your imports with files - [x] All your imports with files
- [ ] All your exports with files - [x] All your exports with files
- [ ] All your trips - [x] All your trips
- [ ] All your places - [ ] All your places
- [ ] All your notifications - [ ] All your notifications
- [ ] All your stats - [ ] All your stats

View file

@ -33,7 +33,7 @@ class Users::ExportData
data[:visits] = nil data[:visits] = nil
data[:imports] = serialized_imports data[:imports] = serialized_imports
data[:exports] = serialized_exports data[:exports] = serialized_exports
data[:trips] = nil data[:trips] = serialized_trips
data[:places] = nil data[:places] = nil
json_file_path = export_directory.join('data.json') json_file_path = export_directory.join('data.json')
@ -69,11 +69,7 @@ class Users::ExportData
process_export(export) process_export(export)
end end
{ exports_data
exports: exports_data,
export_directory: export_directory.to_s,
files_directory: files_directory.to_s
}
end end
def process_export(export) def process_export(export)
@ -132,11 +128,7 @@ class Users::ExportData
process_import(import) process_import(import)
end end
{ imports_data
imports: imports_data,
export_directory: export_directory.to_s,
files_directory: files_directory.to_s
}
end end
def process_import(import) def process_import(import)
@ -210,4 +202,18 @@ class Users::ExportData
Rails.logger.error "Failed to cleanup temporary files: #{e.message}" Rails.logger.error "Failed to cleanup temporary files: #{e.message}"
# Don't re-raise the error as cleanup failure shouldn't break the export # Don't re-raise the error as cleanup failure shouldn't break the export
end end
def serialized_trips
user.trips.map { process_trip(_1) }
end
def process_trip(trip)
Rails.logger.info "Processing trip #{trip.name}"
trip_hash = trip.as_json(except: %w[user_id])
Rails.logger.info "Trip #{trip.name} processed"
trip_hash
end
end end