Skip to content
This repository was archived by the owner on Nov 23, 2024. It is now read-only.
Draft
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
2 changes: 2 additions & 0 deletions link-api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ gem 'iso639-validator'
# Use property sets for Link Instance settings
gem 'property_sets'

gem 'will_paginate', '~> 3.1.0'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
Expand Down
2 changes: 2 additions & 0 deletions link-api/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ GEM
websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
will_paginate (3.1.7)

PLATFORMS
ruby
Expand All @@ -241,6 +242,7 @@ DEPENDENCIES
spring-commands-rspec
spring-watcher-listen (~> 2.0.0)
tzinfo-data
will_paginate (~> 3.1.0)

RUBY VERSION
ruby 2.5.1p57
Expand Down
2 changes: 1 addition & 1 deletion link-api/app/controllers/api/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ContactsController < ApplicationController
def index
@contacts = current_link_instance.contacts

render json: @contacts
render json: Api::Paginate::paginate(params[:page], @contacts)
end

# GET /api/contacts/1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HolidaySchedulesController < ApplicationController
def index
@holiday_schedules = current_link_instance.holiday_schedules

render json: @holiday_schedules
render json: Api::Paginate::paginate(params[:page], @holiday_schedules)
end

# GET /holiday_schedules/1
Expand Down
2 changes: 1 addition & 1 deletion link-api/app/controllers/api/languages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class LanguagesController < ApplicationController
def index
@languages = current_link_instance.languages

render json: @languages
render json: Api::Paginate::paginate(params[:page], @languages)
end

# GET /api/languages/1
Expand Down
2 changes: 1 addition & 1 deletion link-api/app/controllers/api/locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Api::LocationsController < ApplicationController
def index
@locations = current_link_instance.locations.all

render json: @locations
render json: Api::Paginate::paginate(params[:page], @locations)
end

# GET /locations/1
Expand Down
4 changes: 2 additions & 2 deletions link-api/app/controllers/api/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class Api::OrganizationsController < ApplicationController

# GET /organizations
def index
@organizations = current_link_instance.organizations.all
@organizations = current_link_instance.organizations

render json: @organizations
render json: Api::Paginate::paginate(params[:page], @organizations)
end

# GET /organizations/1
Expand Down
13 changes: 13 additions & 0 deletions link-api/app/controllers/api/paginate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Api::Paginate
class << self
def paginate(page, xs, order_query = 'created_at DESC')
entity = xs.name.downcase
pages = xs.order(order_query).page(page)

{
"#{entity}_count" => pages.total_entries,
entity.pluralize => pages
}
end
end
end
2 changes: 1 addition & 1 deletion link-api/app/controllers/api/phones_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PhonesController < ApplicationController
def index
@phones = current_link_instance.phones

render json: @phones
render json: Api::Paginate::paginate(params[:page], @phones)
end

# GET /phones/1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PhysicalAddressesController < ApplicationController
def index
@physical_addresses = current_link_instance.physical_addresses

render json: @physical_addresses
render json: Api::Paginate::paginate(params[:page], @physical_addresses)
end

# GET /physical_addresses/1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PostalAddressesController < ApplicationController
def index
@postal_addresses = current_link_instance.postal_addresses

render json: @postal_addresses
render json: Api::Paginate::paginate(params[:page], @postal_addresses)
end

# GET /postal_addresses/1
Expand Down
2 changes: 1 addition & 1 deletion link-api/app/controllers/api/programs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Api::ProgramsController < ApplicationController
def index
@programs = current_link_instance.programs.all

render json: @programs
render json: Api::Paginate::paginate(params[:page], @programs)
end

# GET /programs/1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RegularSchedulesController < ApplicationController
def index
@regular_schedules = current_link_instance.regular_schedules

render json: @regular_schedules
render json: Api::Paginate::paginate(params[:page], @regular_schedules)
end

# GET /regular_schedules/1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ServiceAtLocationsController < ApplicationController
def index
@service_at_locations = current_link_instance.service_at_locations.all

render json: @service_at_locations
render json: Api::Paginate::paginate(params[:page], @service_at_locations)
end

# GET /api/service_at_locations/1
Expand Down
2 changes: 1 addition & 1 deletion link-api/app/controllers/api/services_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ServicesController < ApplicationController
def index
@services = current_link_instance.services

render json: @services
render json: Api::Paginate::paginate(params[:page], @services)
end

# GET /api/services/1
Expand Down