Added ShopPanel to home sidebar
• Added: - ShopPanel to home sidebar - DIssenter shop redux, api route/controller
This commit is contained in:
33
app/controllers/api/v1/shop_controller.rb
Normal file
33
app/controllers/api/v1/shop_controller.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Api::V1::ShopController < Api::BaseController
|
||||
before_action :require_user!
|
||||
|
||||
respond_to :json
|
||||
|
||||
skip_before_action :set_cache_headers
|
||||
|
||||
def index
|
||||
type = params[:type]
|
||||
if type == 'featured_products'
|
||||
body = Redis.current.get("gabstore:featuredproducts")
|
||||
|
||||
if body.nil?
|
||||
uri = URI("https://shop.dissenter.com/product/group/json")
|
||||
uri.query = URI.encode_www_form({})
|
||||
|
||||
res = Net::HTTP.get_response(uri)
|
||||
if res.is_a?(Net::HTTPSuccess)
|
||||
body = res.body
|
||||
Redis.current.set("gabstore:featuredproducts", res.body)
|
||||
Redis.current.expire("gabstore:featuredproducts", 15.minutes.seconds)
|
||||
end
|
||||
end
|
||||
|
||||
render json: body
|
||||
else
|
||||
raise GabSocial::NotPermittedError
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user