From aaa989d1c9a645d81b05241731f9f59817e597c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Johannes=20Werkhoven=20=E5=B2=A9=E5=B1=B1?= Date: Sat, 23 May 2026 19:56:05 +1000 Subject: [PATCH 1/8] Allow controller to pass @records to JSON API logic --- app/controllers/concerns/json_api_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/json_api_controller.rb b/app/controllers/concerns/json_api_controller.rb index 4537634..d1f5dc7 100644 --- a/app/controllers/concerns/json_api_controller.rb +++ b/app/controllers/concerns/json_api_controller.rb @@ -146,7 +146,11 @@ def allow_index(allowed = true) return error_forbidden_filters if forbidden_filters.any? # First we gather all records of the model class. - records = model_class_with_includes.all + records = if @records.nil? + params[:include].present? ? model_class_with_includes.all : model_class.all + else + @records # set in the controller, prevents .all + end # Next we reduce this collection with the permanent and requested filters. # @@ -183,7 +187,7 @@ def allow_index(allowed = true) options[:include] = strong_includes if strong_includes # We create a JSON response from the records we collected using the fast and - # JSON API compliant Netflux serializers. + # JSON API compliant Netflix serializers. json = serializer_class.new(records, options).serializable_hash.to_json # Finally we return the JSON with a 200. From 97aac1f0b8be244e2a7715a6bc3a83fc95d10e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Johannes=20Werkhoven=20=E5=B2=A9=E5=B1=B1?= Date: Sat, 23 May 2026 19:56:44 +1000 Subject: [PATCH 2/8] Allow past and upcoming events to be fetched --- app/controllers/v1/public/events_controller.rb | 10 ++++++++++ app/models/event.rb | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/controllers/v1/public/events_controller.rb b/app/controllers/v1/public/events_controller.rb index 2449bc7..b44e90c 100644 --- a/app/controllers/v1/public/events_controller.rb +++ b/app/controllers/v1/public/events_controller.rb @@ -2,6 +2,9 @@ module V1 module Public class EventsController < V1::PublicController def index + @records = Event.upcoming if params['upcoming'] == 'true' + @records = Event.past if params['past'] == 'true' + allow_index end @@ -36,6 +39,13 @@ def permitted_includes country ] end + + def permitted_filters + %i[ + upcoming + past + ] + end end end end diff --git a/app/models/event.rb b/app/models/event.rb index e6228b3..be1422b 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -34,13 +34,13 @@ def location "#{city}, #{country.name_english}" end + scope :past, -> { where('start_date < ?', Date.current - 2.days) } + scope :upcoming, -> { where('start_date >= ?', Date.current - 2.days) } + def start_to_end_date return '?' if sd.nil? && ed.nil? - return sd.strftime('%a %-d %b %Y') if sd.present? && ed.nil? - return sd.strftime('%a %-d %b %Y') if ed == sd - return "#{sd.strftime('%a %d')} to #{ed.strftime('%a %-d %b %Y')}" if sd.month == ed.month "#{sd.strftime('%a %-d %b %Y')} to #{ed.strftime('%a %-d %b %Y')}" From df2bb08a63030ba3f7f885b20f9efcc7c7c11435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Johannes=20Werkhoven=20=E5=B2=A9=E5=B1=B1?= Date: Sat, 23 May 2026 19:57:47 +1000 Subject: [PATCH 3/8] Skip strong include logic if not param is absent --- app/controllers/concerns/json_api_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/concerns/json_api_controller.rb b/app/controllers/concerns/json_api_controller.rb index d1f5dc7..31a4b7b 100644 --- a/app/controllers/concerns/json_api_controller.rb +++ b/app/controllers/concerns/json_api_controller.rb @@ -274,6 +274,7 @@ def allow_show # To avoid N+1 we include all the includes. def model_class_with_includes + return model_class if params[:include].blank? return model_class unless strong_includes list = [] From 124d3a866b87f559f3593a5d7b0f7948040268e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Johannes=20Werkhoven=20=E5=B2=A9=E5=B1=B1?= Date: Sat, 23 May 2026 19:58:47 +1000 Subject: [PATCH 4/8] Allow CompanyMarket to be filtered by country --- .../v1/public/company_markets_controller.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/controllers/v1/public/company_markets_controller.rb b/app/controllers/v1/public/company_markets_controller.rb index cf9f91e..861f40e 100644 --- a/app/controllers/v1/public/company_markets_controller.rb +++ b/app/controllers/v1/public/company_markets_controller.rb @@ -30,6 +30,19 @@ def model_class def serializer_class V1::Public::CompanyMarketSerializer end + + def permitted_includes + %i[ + company + country + ] + end + + def permitted_filters + %i[ + country + ] + end end end end From 172b1c0ea15246009eb40f3786a52926b9f2752d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Johannes=20Werkhoven=20=E5=B2=A9=E5=B1=B1?= Date: Sat, 23 May 2026 19:59:10 +1000 Subject: [PATCH 5/8] Add comment --- app/controllers/v1/public_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/v1/public_controller.rb b/app/controllers/v1/public_controller.rb index fae6bb1..9e833e4 100644 --- a/app/controllers/v1/public_controller.rb +++ b/app/controllers/v1/public_controller.rb @@ -1,4 +1,5 @@ module V1 class PublicController < ApplicationController + # TODO: add permanent filter public=true end end From 7a0784e32a9c4dd1176cb9cf0352f7dbb1ac62c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Johannes=20Werkhoven=20=E5=B2=A9=E5=B1=B1?= Date: Sat, 23 May 2026 19:59:45 +1000 Subject: [PATCH 6/8] Formatting --- config/environments/development.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 400fc3a..96ee5f3 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -68,7 +68,7 @@ end # Return a 404 to all requests who are not these hosts: - config.hosts = ["localhost", "127.0.0.1"] + config.hosts = ['localhost', '127.0.0.1'] # Configure CORS. # Note that the Interflux front-end live on different domains than their backend. From 1ef321e977704843f27fa2aab1e35ebc5d5f3046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Johannes=20Werkhoven=20=E5=B2=A9=E5=B1=B1?= Date: Sat, 23 May 2026 20:00:32 +1000 Subject: [PATCH 7/8] Skip DB ENV CHECK in development since we use SQL dumps instead of YML extracts --- scripts/backup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 0bf4c37..8eeae61 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -20,7 +20,7 @@ echo "✅ Downloaded production database" echo "----------" ls -la db/dumps echo "----------" -RAILS_ENV=development rails db:drop db:create +RAILS_ENV=development DISABLE_DATABASE_ENVIRONMENT_CHECK=1 rails db:drop db:create echo "----------" echo "✅ Reset local database" echo "----------" From 57f91e2ca69f8407b34a5d5e7b0ce09bf0c31779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Johannes=20Werkhoven=20=E5=B2=A9=E5=B1=B1?= Date: Sat, 23 May 2026 20:13:14 +1000 Subject: [PATCH 8/8] Silence Bullet's eager loading warnings because inaccurate --- app/controllers/concerns/json_api_controller.rb | 2 +- config/environments/development.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/concerns/json_api_controller.rb b/app/controllers/concerns/json_api_controller.rb index 31a4b7b..cee5848 100644 --- a/app/controllers/concerns/json_api_controller.rb +++ b/app/controllers/concerns/json_api_controller.rb @@ -288,7 +288,7 @@ def model_class_with_includes value = split[1] hash = {} hash[key] = value - # list.push(**hash) + list.push(**hash) else list.push(symbol) end diff --git a/config/environments/development.rb b/config/environments/development.rb index 96ee5f3..90d8a4b 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -6,6 +6,13 @@ Bullet.console = true Bullet.rails_logger = true Bullet.add_footer = true + + # Disable only the "AVOID eager loading" warnings + Bullet.unused_eager_loading_enable = false + + # Keep other useful warnings + Bullet.n_plus_one_query_enable = true + Bullet.counter_cache_enable = true end # Settings specified here will take precedence over those in config/application.rb.