Add pagination for collections
This commit is contained in:
parent
d98772e93c
commit
1f3ba2307f
3 changed files with 14 additions and 11 deletions
|
|
@ -19,7 +19,7 @@ class Api::V1::PartiesController < Api::V1::ApiController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
now = DateTime.current
|
now = DateTime.current
|
||||||
start_time = (now - params['recency'].to_i.seconds).to_datetime.beginning_of_day unless request.params['recency'].blank?
|
start_time = (now - request.params['recency'].to_i.seconds).to_datetime.beginning_of_day unless request.params['recency'].blank?
|
||||||
|
|
||||||
conditions = {}
|
conditions = {}
|
||||||
conditions[:element] = request.params['element'] unless request.params['element'].blank?
|
conditions[:element] = request.params['element'] unless request.params['element'].blank?
|
||||||
|
|
@ -27,9 +27,10 @@ class Api::V1::PartiesController < Api::V1::ApiController
|
||||||
conditions[:created_at] = start_time..now unless request.params['recency'].blank?
|
conditions[:created_at] = start_time..now unless request.params['recency'].blank?
|
||||||
conditions[:weapons_count] = 5..13
|
conditions[:weapons_count] = 5..13
|
||||||
|
|
||||||
@parties = Party.where(conditions).each { |party|
|
@parties = Party.where(conditions).paginate(page: request.params[:page], per_page: 15)
|
||||||
party.favorited = (current_user) ? party.is_favorited(current_user) : false
|
.each { |party|
|
||||||
}
|
party.favorited = (current_user) ? party.is_favorited(current_user) : false
|
||||||
|
}
|
||||||
|
|
||||||
render :all, status: :ok
|
render :all, status: :ok
|
||||||
end
|
end
|
||||||
|
|
@ -46,9 +47,10 @@ class Api::V1::PartiesController < Api::V1::ApiController
|
||||||
conditions[:created_at] = start_time..now unless request.params['recency'].blank?
|
conditions[:created_at] = start_time..now unless request.params['recency'].blank?
|
||||||
conditions[:favorites] = { user_id: current_user.id }
|
conditions[:favorites] = { user_id: current_user.id }
|
||||||
|
|
||||||
@parties = Party.joins(:favorites).where(conditions).each { |party|
|
@parties = Party.joins(:favorites).where(conditions).paginate(page: request.params[:page], per_page: 15)
|
||||||
party.favorited = party.is_favorited(current_user)
|
.each { |party|
|
||||||
}
|
party.favorited = party.is_favorited(current_user)
|
||||||
|
}
|
||||||
|
|
||||||
render :all, status: :ok
|
render :all, status: :ok
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,10 @@ class Api::V1::UsersController < Api::V1::ApiController
|
||||||
conditions[:created_at] = start_time..now unless request.params['recency'].blank?
|
conditions[:created_at] = start_time..now unless request.params['recency'].blank?
|
||||||
conditions[:user_id] = @user.id
|
conditions[:user_id] = @user.id
|
||||||
|
|
||||||
@parties = Party.where(conditions).each { |party|
|
@parties = Party.where(conditions).paginate(page: request.params[:page], per_page: 15)
|
||||||
party.favorited = (current_user) ? party.is_favorited(current_user) : false
|
.each { |party|
|
||||||
}
|
party.favorited = (current_user) ? party.is_favorited(current_user) : false
|
||||||
|
}
|
||||||
else
|
else
|
||||||
render_not_found_response
|
render_not_found_response
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2022_03_15_005952) do
|
ActiveRecord::Schema.define(version: 2022_03_15_011802) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "btree_gin"
|
enable_extension "btree_gin"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue