diff --git a/app/controllers/api/v1/api_controller.rb b/app/controllers/api/v1/api_controller.rb index 2aceddc..73c51a1 100644 --- a/app/controllers/api/v1/api_controller.rb +++ b/app/controllers/api/v1/api_controller.rb @@ -6,6 +6,10 @@ module Api ##### Doorkeeper include Doorkeeper::Rails::Helpers + ##### Constants + COLLECTION_PER_PAGE = 15 + SEARCH_PER_PAGE = 10 + ##### Errors rescue_from ActiveRecord::RecordInvalid, with: :render_unprocessable_entity_response rescue_from ActiveRecord::RecordNotDestroyed, with: :render_unprocessable_entity_response diff --git a/app/controllers/api/v1/grid_weapons_controller.rb b/app/controllers/api/v1/grid_weapons_controller.rb index 3d21caf..a6324bd 100644 --- a/app/controllers/api/v1/grid_weapons_controller.rb +++ b/app/controllers/api/v1/grid_weapons_controller.rb @@ -67,7 +67,8 @@ module Api :id, :party_id, :weapon_id, :position, :mainhand, :uncap_level, :element, :weapon_key1_id, :weapon_key2_id, :weapon_key3_id, - :ax_modifier1, :ax_modifier2, :ax_strength1, :ax_strength2 + :ax_modifier1, :ax_modifier2, :ax_strength1, :ax_strength2, + :awakening_type, :awakening_level ) end end diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index d97b96f..eba4cd2 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -2,8 +2,6 @@ module Api module V1 - PER_PAGE = 15 - class PartiesController < Api::V1::ApiController before_action :set_from_slug, except: %w[create destroy update index favorites] @@ -59,11 +57,11 @@ module Api @parties = Party.where(conditions) .order(created_at: :desc) - .paginate(page: request.params[:page], per_page: PER_PAGE) + .paginate(page: request.params[:page], per_page: COLLECTION_PER_PAGE) .each { |party| party.favorited = current_user ? party.is_favorited(current_user) : false } count = Party.where(conditions).count - total_pages = count.to_f / PER_PAGE > 1 ? (count.to_f / PER_PAGE).ceil : 1 + total_pages = count.to_f / COLLECTION_PER_PAGE > 1 ? (count.to_f / COLLECTION_PER_PAGE).ceil : 1 render json: PartyBlueprint.render(@parties, view: :collection, @@ -71,7 +69,7 @@ module Api meta: { count: count, total_pages: total_pages, - per_page: PER_PAGE + per_page: COLLECTION_PER_PAGE }) end @@ -84,11 +82,11 @@ module Api @parties = Party.joins(:favorites) .where(conditions) .order('favorites.created_at DESC') - .paginate(page: request.params[:page], per_page: PER_PAGE) + .paginate(page: request.params[:page], per_page: COLLECTION_PER_PAGE) .each { |party| party.favorited = party.is_favorited(current_user) } count = Party.joins(:favorites).where(conditions).count - total_pages = count.to_f / PER_PAGE > 1 ? (count.to_f / PER_PAGE).ceil : 1 + total_pages = count.to_f / COLLECTION_PER_PAGE > 1 ? (count.to_f / COLLECTION_PER_PAGE).ceil : 1 render json: PartyBlueprint.render(@parties, view: :collection, @@ -96,7 +94,7 @@ module Api meta: { count: count, total_pages: total_pages, - per_page: PER_PAGE + per_page: COLLECTION_PER_PAGE }) end diff --git a/app/controllers/api/v1/search_controller.rb b/app/controllers/api/v1/search_controller.rb index a383525..e317c96 100644 --- a/app/controllers/api/v1/search_controller.rb +++ b/app/controllers/api/v1/search_controller.rb @@ -2,8 +2,6 @@ module Api module V1 - PER_PAGE = 10 - class SearchController < Api::V1::ApiController def characters filters = search_params[:filters] @@ -35,14 +33,14 @@ module Api end count = characters.length - paginated = characters.paginate(page: search_params[:page], per_page: PER_PAGE) + paginated = characters.paginate(page: search_params[:page], per_page: SEARCH_PER_PAGE) render json: CharacterBlueprint.render(paginated, root: :results, meta: { count: count, total_pages: total_pages(count), - per_page: PER_PAGE + per_page: SEARCH_PER_PAGE }) end @@ -72,14 +70,14 @@ module Api end count = weapons.length - paginated = weapons.paginate(page: search_params[:page], per_page: PER_PAGE) + paginated = weapons.paginate(page: search_params[:page], per_page: SEARCH_PER_PAGE) render json: WeaponBlueprint.render(paginated, root: :results, meta: { count: count, total_pages: total_pages(count), - per_page: PER_PAGE + per_page: SEARCH_PER_PAGE }) end @@ -104,14 +102,14 @@ module Api end count = summons.length - paginated = summons.paginate(page: search_params[:page], per_page: PER_PAGE) + paginated = summons.paginate(page: search_params[:page], per_page: SEARCH_PER_PAGE) render json: SummonBlueprint.render(paginated, root: :results, meta: { count: count, total_pages: total_pages(count), - per_page: PER_PAGE + per_page: SEARCH_PER_PAGE }) end @@ -168,21 +166,21 @@ module Api end count = skills.length - paginated = skills.paginate(page: search_params[:page], per_page: PER_PAGE) + paginated = skills.paginate(page: search_params[:page], per_page: SEARCH_PER_PAGE) render json: JobSkillBlueprint.render(paginated, root: :results, meta: { count: count, total_pages: total_pages(count), - per_page: PER_PAGE + per_page: SEARCH_PER_PAGE }) end private def total_pages(count) - count.to_f / PER_PAGE > 1 ? (count.to_f / PER_PAGE).ceil : 1 + count.to_f / SEARCH_PER_PAGE > 1 ? (count.to_f / SEARCH_PER_PAGE).ceil : 1 end # Specify whitelisted properties that can be modified. diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 267e23f..cdd9d4e 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -2,8 +2,6 @@ module Api module V1 - PER_PAGE = 15 - class UsersController < Api::V1::ApiController class ForbiddenError < StandardError; end @@ -50,7 +48,7 @@ module Api parties = Party .where(conditions) .order(created_at: :desc) - .paginate(page: request.params[:page], per_page: PER_PAGE) + .paginate(page: request.params[:page], per_page: COLLECTION_PER_PAGE) .each do |party| party.favorited = current_user ? party.is_favorited(current_user) : false end @@ -63,8 +61,8 @@ module Api parties: parties, meta: { count: count, - total_pages: count.to_f / PER_PAGE > 1 ? (count.to_f / PER_PAGE).ceil : 1, - per_page: PER_PAGE + total_pages: count.to_f / COLLECTION_PER_PAGE > 1 ? (count.to_f / COLLECTION_PER_PAGE).ceil : 1, + per_page: COLLECTION_PER_PAGE }) end