Fix response when requesting nonexistent user
This commit is contained in:
parent
8fb6fab0d7
commit
6c12b1937a
1 changed files with 25 additions and 22 deletions
|
|
@ -40,30 +40,33 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
render_not_found_response('user') unless @user
|
if @user.nil?
|
||||||
|
render_not_found_response('user')
|
||||||
|
else
|
||||||
|
|
||||||
conditions = build_conditions(request.params)
|
conditions = build_conditions(request.params)
|
||||||
conditions[:user_id] = @user.id
|
conditions[:user_id] = @user.id
|
||||||
|
|
||||||
parties = Party
|
parties = Party
|
||||||
.where(conditions)
|
.where(conditions)
|
||||||
.order(created_at: :desc)
|
.order(created_at: :desc)
|
||||||
.paginate(page: request.params[:page], per_page: COLLECTION_PER_PAGE)
|
.paginate(page: request.params[:page], per_page: COLLECTION_PER_PAGE)
|
||||||
.each do |party|
|
.each do |party|
|
||||||
party.favorited = current_user ? party.is_favorited(current_user) : false
|
party.favorited = current_user ? party.is_favorited(current_user) : false
|
||||||
|
end
|
||||||
|
|
||||||
|
count = Party.where(conditions).count
|
||||||
|
|
||||||
|
render json: UserBlueprint.render(@user,
|
||||||
|
view: :profile,
|
||||||
|
root: 'profile',
|
||||||
|
parties: parties,
|
||||||
|
meta: {
|
||||||
|
count: count,
|
||||||
|
total_pages: count.to_f / COLLECTION_PER_PAGE > 1 ? (count.to_f / COLLECTION_PER_PAGE).ceil : 1,
|
||||||
|
per_page: COLLECTION_PER_PAGE
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
count = Party.where(conditions).count
|
|
||||||
|
|
||||||
render json: UserBlueprint.render(@user,
|
|
||||||
view: :profile,
|
|
||||||
root: 'profile',
|
|
||||||
parties: parties,
|
|
||||||
meta: {
|
|
||||||
count: count,
|
|
||||||
total_pages: count.to_f / COLLECTION_PER_PAGE > 1 ? (count.to_f / COLLECTION_PER_PAGE).ceil : 1,
|
|
||||||
per_page: COLLECTION_PER_PAGE
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_email
|
def check_email
|
||||||
|
|
@ -81,7 +84,7 @@ module Api
|
||||||
def build_conditions(params)
|
def build_conditions(params)
|
||||||
unless params['recency'].blank?
|
unless params['recency'].blank?
|
||||||
start_time = (DateTime.current - params['recency'].to_i.seconds)
|
start_time = (DateTime.current - params['recency'].to_i.seconds)
|
||||||
.to_datetime.beginning_of_day
|
.to_datetime.beginning_of_day
|
||||||
end
|
end
|
||||||
|
|
||||||
{}.tap do |hash|
|
{}.tap do |hash|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue