-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Top Ten endpoint and new releases
- Loading branch information
1 parent
1f0dd0e
commit 00fc96f
Showing
3 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::V1::ProductsController < ApplicationController | ||
before_action :onboarded_products | ||
|
||
def new_releases | ||
onboarded_products = Product.published.where(store: Store.where(user: User.where.not(stripe_user_id: nil))) | ||
@new_releases = onboarded_products.order(created_at: :desc).take(12) | ||
end | ||
|
||
def top_ten | ||
@top_ten = onboarded_products.order("RANDOM()").take(10) | ||
end | ||
|
||
def onboarded_products | ||
Product.published.where(store: Store.where(user: User.where.not(stripe_user_id: nil))) | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
json.array! @top_ten do |product| | ||
json.name product.name | ||
json.store_name product.store.name | ||
json.price product.price | ||
json.slug product.slug | ||
json.created_at product.created_at | ||
json.issue_cover url_for(product.issue_cover) | ||
end |
This file contains 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