Merge branch 'main' into awakening
This commit is contained in:
commit
ddae480f48
5 changed files with 24 additions and 26 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
@ -55,15 +53,14 @@ module Api
|
|||
|
||||
def index
|
||||
conditions = build_conditions(request.params)
|
||||
ap conditions
|
||||
|
||||
@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 +68,7 @@ module Api
|
|||
meta: {
|
||||
count: count,
|
||||
total_pages: total_pages,
|
||||
per_page: PER_PAGE
|
||||
per_page: COLLECTION_PER_PAGE
|
||||
})
|
||||
end
|
||||
|
||||
|
|
@ -84,11 +81,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 +93,7 @@ module Api
|
|||
meta: {
|
||||
count: count,
|
||||
total_pages: total_pages,
|
||||
per_page: PER_PAGE
|
||||
per_page: COLLECTION_PER_PAGE
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue