docbrown/app/controllers/api/v0/profile_images_controller.rb
Diogo Osório 2b72a35d3d
[deploy] Introduce /api/profile_images/:username endpoint (#10547)
* Documents the new /profile-images/:username API endpoint

* Introduces the /api/profile_images/:username endpoint

This endpoint receives either an user or organization username as input
via the URL path and returns the profile image information for that
user/orgnization.

* Updates the /api/profile_images/:username response

Adapts the response according to the review comments:

1. Removes the cache directives
1. Tweaks how the user query is being done
1. Adds a `image_of` property to the response

* Bump API version

Co-authored-by: rhymes <rhymes@hey.com>
Co-authored-by: Molly Struve <mollylbs@gmail.com>
2020-10-14 14:24:25 -05:00

27 lines
583 B
Ruby

module Api
module V0
class ProfileImagesController < ApiController
def show
not_found unless profile_image_owner
@profile_image_owner = profile_image_owner
end
private
def profile_image_owner
user || organization
end
def user
@user ||= User.registered.select(:id, :profile_image)
.find_by(username: params[:username])
end
def organization
@organization ||= Organization.select(:id, :profile_image)
.find_by(username: params[:username])
end
end
end
end