Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions app/controllers/concerns/json_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -270,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 = []
Expand All @@ -283,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
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/v1/public/company_markets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions app/controllers/v1/public/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -36,6 +39,13 @@ def permitted_includes
country
]
end

def permitted_filters
%i[
upcoming
past
]
end
end
end
end
1 change: 1 addition & 0 deletions app/controllers/v1/public_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module V1
class PublicController < ApplicationController
# TODO: add permanent filter public=true
end
end
6 changes: 3 additions & 3 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')}"
Expand Down
9 changes: 8 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -68,7 +75,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.
Expand Down
2 changes: 1 addition & 1 deletion scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "----------"
Expand Down
Loading