Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ gem 'rack-cors', require: 'rack/cors'
gem 'active_model_serializers'
gem 'devise_token_auth'
gem 'geocoder'
gem 'aws-sdk-s3'
gem 'aws-sdk-s3', require: false
gem 'stripe-rails'

group :development, :test do
Expand Down
5 changes: 3 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ GEM
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
devise_token_auth (1.1.3)
devise_token_auth (1.1.4)
bcrypt (~> 3.0)
devise (> 3.5.2, < 5)
rails (>= 4.2.0, < 6.1)
sprockets (= 3.7.2)
diff-lcs (1.4.4)
docile (1.3.2)
erubi (1.9.0)
Expand Down Expand Up @@ -219,7 +220,7 @@ GEM
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0)
sprockets (4.0.2)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/api/v1/listings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ def index
end

def show
binding.pry
listing = Listing.find(params[:id])

render json: listing, serializer: ListingShowSerializer
rescue StandardError
rescue StandardError => e
binding.pry
render json: { message: 'Unfortunately the listing could not be found' }, status: 422
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/listing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Listing < ApplicationRecord
validates_presence_of :category, :lead, :scene, :address, :description, :price
enum scene: [:indoor, :outdoor]

has_many_attached :image
has_many_attached :images

geocoded_by :address

Expand Down
10 changes: 6 additions & 4 deletions app/serializers/listing_show_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
class ListingShowSerializer < ActiveModel::Serializer
include Rails.application.routes.url_helpers
attributes :id, :category, :lead, :scene, :description, :address, :price, :image

def image
return nil unless object.image.attached?
attributes :id, :category, :lead, :scene, :description, :address, :price, :images

def images
return nil unless object.images.attached?
if Rails.env.test?
rails_blob_url(object.image)
else
object.image.service_url(expires_in:1.hour, disposition: 'inline')
binding.pry
object.images.service_url(expires_in:1.hour, disposition: 'inline')
end
end
end
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
N6lYsC7CzNt6smGvxLSozdySGaOMEjJwVzHS3Q/rNAbezjEG5XhoZkOxtez05nkPn8BTIlvhI78pkbBYMS4/cIMMspMEgL/kVor6j1zZ+QIXPypgmajYgfh49+claeeiFd+3KM0Pl5ieYItk/BBBaYDL0BgmlKOURcWOVt3Tyx6DG3Gd4kPIPVd66j6UQBJSMNitkh2a4fBcJT6FyceW8UOi4DbSrMgSFiqAsy2kKSxbies9PuQ4xWMt3J5333ZHEAF4rH675YPjydv1H/VnJ/9Z8RxMq5PpLCrurlpKWCFP9uXgHDY2ZXDG6Ol6XxVPWcS4hHC9uk7ozl2dLWv9NqliShEiDLufgYwLXww16VRqLFw+2foQdGbZXFgW8alGHzAYC/hUezJ7gFieWXDgm2Fd7ogq9fHg4FewVtdRv+b2iiwIDemBNHR2Mxh4saC6G5ACHtLKOJQzt5DAg7jOsFi/tbnCKhytmeyn/0Xf9PxLvHllIMoGz62vALhy4Y6HiDcGKkbxo9YLkEL1Z+zJLgZxxqURy/pql6Pc+CWmbmTLPFZqu7NpPqBZNEEPsUq65FVuLfzsG9EVbh55uWo2/EddxRKfQwgZdRLx0VtpEW01WbzGcv9uGGvibeaQtbo8cO+XpI0z--nucIdQ3lUVoge1IQ--6/hOTiG79SDnqEawaILx6Q==
JojYHZfQ8xGbq+Rmor3yocTh4FST1uT3j7X+UQmhP/q6LOWIfEhlWaSYC58taSipzudwY5wAqM82+wrgQElVPruM9MhHJQQ0bGPddb31948ppD2n14OOdSVymCD3TuS1vfEYSmbUJJFGmEz4rXMIpPHGKV3/+xfdz1vZypVl3nB/Y/7Kw6Qbw3Mcnjq8uhxQAjg/xChKDZPSNoL8SiICJYZscM+TSQNS/LPR1BRuwRiWMHbhcN32+Bo2WxZLxfmcrue/vf1AH+FYKaTM8mUL0wLvOHEbEj4cSVUagigj8qJJrPFuFeH9RWMAkaqNLXRPcNdS+1M6BCLU4FEBwMegyNhXErWTNgG9QGcuO2w8RB3mvbcKgmz6FvxAitr4ndKfgECf77USxw9oDgMitLzCgHTlD3IS+1/J3Lf8Ij3CpcHIwL7j2y6oratPUlxX6wzfSNfI5HpizSkW7pgC7MnRsppoT8nUS4wdZGEIyR9yfUNNILTbOne+CvD66cmvgui/2brYHFXDLdJ0KgqEMNd3mSyzBnBgiHMbe6/IDgOldwONvyT41w7bo6jTzW8sn1OqoGEnt66GuG6uTlIp022x1qLoKHD6GSfhaggCChsPZB74BrRVtMIJ6CF4n3ik9os=--fceoVIu+RyRkWKWu--TnIlvtTi6ySWFRNdFJjsBw==
6 changes: 3 additions & 3 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
landlord_id: user.id
)
file = URI.open('https://www.quickanddirtytips.com/sites/default/files/images/12186/Parking-Lot-of-deas.jpg')
free_listing_1.image.attach(io: file, filename: 'first.jpg')
free_listing_1.images.attach(io: file, filename: 'first.jpg')

free_listing_2 = Listing.create(
category: 'Parking spot',
Expand All @@ -26,7 +26,7 @@
landlord_id: user.id
)
file = URI.open('https://www.pymnts.com/wp-content/uploads/2018/03/parkingspot.jpg')
free_listing_2.image.attach(io: file, filename: 'second.jpg')
free_listing_2.images.attach(io: file, filename: 'second.jpg')

free_listing_3 = Listing.create(
category: 'Parking spot',
Expand All @@ -38,4 +38,4 @@
landlord_id: user.id
)
file = URI.open('https://parkeasier.com/wp-content/uploads/2014/12/Homepage_Find_a_Spot_section2.jpg')
free_listing_3.image.attach(io: file, filename: 'third.jpg')
free_listing_3.images.attach(io: file, filename: 'third.jpg')