Created
July 20, 2017 18:42
-
-
Save chadwilken/c1b47494fc0e551db32f3c336fe8a38d to your computer and use it in GitHub Desktop.
The Project JSON Partial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
json = { | |
id: project.id, | |
name: project.name, | |
street_address_1: project.street_address_1, | |
street_address_2: project.street_address_2, | |
city: project.city, | |
state: project.state, | |
postal_code: project.postal_code, | |
country: project.country, | |
company_id: project.company_id, | |
user_id: project.creator_id, | |
active: project.active, | |
images_count: project.images_count, | |
last_image_taken: project.last_image_taken, | |
created_at: project.created_at, | |
updated_at: project.updated_at, | |
lat: project.coordinates.lat, | |
lon: project.coordinates.lon, | |
feature_photo_url: project.feature_photo_url, | |
feature_photo_medium_url: project.feature_photo_medium_url, | |
feature_photo_small_url: project.feature_photo_small_url, | |
coordinates: { lat: project.coordinates.lat, lon: project.coordinates.lon }, | |
public: project.public, | |
slug: project.slug, | |
geofence: Polygon.new(project.geofence).to_geofence | |
} | |
recent_images = [] | |
if can_view_users | |
recent_images = project.recent_images.limit(6) | |
else | |
recent_images = project.recent_images.where(creator_id: current_user.id, creator_type: 'User').limit(6) | |
end | |
json[:recent_images] = recent_images.map do |image| | |
Rails.cache.fetch(['v1', image]) do | |
render partial: 'v1/locations/recent/image', locals: { image: image } | |
end | |
end | |
days_images = [] | |
if can_view_users | |
days_images = project.days_images | |
else | |
days_images = project.days_images.where(creator_id: current_user.id, creator_type: 'User') | |
end | |
json[:days_images] = days_images.map do |image| | |
Rails.cache.fetch(['v1', image]) do | |
render partial: 'v1/locations/recent/image', locals: { image: image } | |
end | |
end | |
json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment