Merge pull request #63 from jedmund/fix-users-response

Fix response when requesting nonexistent user
This commit is contained in:
Justin Edmund 2023-01-28 20:51:08 -08:00 committed by GitHub
commit 1474580d37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -40,30 +40,33 @@ module Api
end
def show
render_not_found_response('user') unless @user
if @user.nil?
render_not_found_response('user')
else
conditions = build_conditions(request.params)
conditions[:user_id] = @user.id
conditions = build_conditions(request.params)
conditions[:user_id] = @user.id
parties = Party
.where(conditions)
.order(created_at: :desc)
.paginate(page: request.params[:page], per_page: COLLECTION_PER_PAGE)
.each do |party|
party.favorited = current_user ? party.is_favorited(current_user) : false
parties = Party
.where(conditions)
.order(created_at: :desc)
.paginate(page: request.params[:page], per_page: COLLECTION_PER_PAGE)
.each do |party|
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
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
def check_email
@ -81,7 +84,7 @@ module Api
def build_conditions(params)
unless params['recency'].blank?
start_time = (DateTime.current - params['recency'].to_i.seconds)
.to_datetime.beginning_of_day
.to_datetime.beginning_of_day
end
{}.tap do |hash|