From 7fc2207810f933e310477ca80f943c524b1af5e0 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 25 Jun 2025 21:26:08 +0200 Subject: [PATCH] User export: exporting areas, stats, notifications, trips --- CHANGELOG.md | 8 ++++---- app/services/users/export_data.rb | 28 ++++++++++++++-------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb401e8c..6d28189c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,14 +10,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [x] In the User Settings, you can now export your user data as a zip file. It will contain the following: - [ ] All your points - - [ ] All your areas + - [ ] All your places - [ ] All your visits + - [x] All your areas - [x] All your imports with files - [x] All your exports with files - [x] All your trips - - [ ] All your places - - [ ] All your notifications - - [ ] All your stats + - [x] All your notifications + - [x] All your stats - [ ] In the User Settings, you can now import your user data from a zip file. It will import all the data from the zip file, listed above. It will also start stats recalculation. diff --git a/app/services/users/export_data.rb b/app/services/users/export_data.rb index e0e982c8..c999580e 100644 --- a/app/services/users/export_data.rb +++ b/app/services/users/export_data.rb @@ -13,12 +13,8 @@ class Users::ExportData # TODO: Implement # 1. Export user settings # 2. Export user points - # 3. Export user areas # 4. Export user visits - # 7. Export user trips # 8. Export user places - # 9. Export user notifications - # 10. Export user stats # 11. Zip all the files @@ -28,12 +24,14 @@ class Users::ExportData data = {} data[:settings] = user.safe_settings.settings - data[:points] = nil - data[:areas] = nil - data[:visits] = nil + data[:areas] = serialized_areas data[:imports] = serialized_imports data[:exports] = serialized_exports data[:trips] = serialized_trips + data[:stats] = serialized_stats + data[:notifications] = serialized_notifications + data[:points] = nil + data[:visits] = nil data[:places] = nil json_file_path = export_directory.join('data.json') @@ -204,16 +202,18 @@ class Users::ExportData end def serialized_trips - user.trips.map { process_trip(_1) } + user.trips.as_json(except: %w[user_id]) end - def process_trip(trip) - Rails.logger.info "Processing trip #{trip.name}" + def serialized_areas + user.areas.as_json(except: %w[user_id]) + end - trip_hash = trip.as_json(except: %w[user_id]) + def serialized_stats + user.stats.as_json(except: %w[user_id]) + end - Rails.logger.info "Trip #{trip.name} processed" - - trip_hash + def serialized_notifications + user.notifications.as_json(except: %w[user_id]) end end