Skip to content

Commit fa44d36

Browse files
committed
Create Spotlight products
1 parent 254c3df commit fa44d36

5 files changed

Lines changed: 37 additions & 1 deletion

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class SpotlightController < ApplicationController
2+
before_action :set_product, only: [:show, :update, :destroy]
3+
skip_before_action :authenticate_request, :only => [:index, :show]
4+
5+
# GET /spotlight
6+
def index
7+
@products = Product.where(spotlight: true)
8+
9+
render json: {data: @products}
10+
end
11+
12+
private
13+
# Use callbacks to share common setup or constraints between actions.
14+
def set_product
15+
@product = Product.find(params[:id])
16+
end
17+
18+
# Only allow a trusted parameter "white list" through.
19+
def product_params
20+
params.require(:product).permit(:sku, :item, :color, :size, :cod, :stock)
21+
end
22+
end

pdv/config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Rails.application.routes.draw do
22
resources :products
33
resources :users
4+
resources :spotlight
45
post 'authenticate', to: 'auth#authenticate'
56
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
67
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddSpotlightToProduct < ActiveRecord::Migration[5.2]
2+
def change
3+
add_column :products, :spotlight, :boolean
4+
end
5+
end

pdv/db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2019_03_13_124642) do
13+
ActiveRecord::Schema.define(version: 2019_03_21_200122) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -27,6 +27,7 @@
2727
t.string "image"
2828
t.float "price"
2929
t.integer "quantity"
30+
t.boolean "spotlight"
3031
end
3132

3233
create_table "users", force: :cascade do |t|
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'test_helper'
2+
3+
class SpotlightControllerTest < ActionDispatch::IntegrationTest
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end

0 commit comments

Comments
 (0)