Skip to content

Commit 3b4d999

Browse files
Merge pull request #128 from Shopify/change_create_route_to_post
Change create product route to `POST /api/products`
2 parents 40ffd00 + 7fe9e22 commit 3b4d999

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ruby-3.1.2
1+
ruby-3.3.0

web/app/controllers/products_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# frozen_string_literal: true
22

33
class ProductsController < AuthenticatedController
4+
# GET /api/products/count
45
def count
56
product_count = ShopifyAPI::Product.count.body
67
ShopifyAPI::Logger.info("Retrieved product count: #{product_count["count"]}")
78
render(json: product_count)
89
end
910

11+
# POST /api/products
1012
def create
1113
ProductCreator.call(count: 5, session: current_shopify_session)
1214

web/config/routes.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@
1111

1212
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
1313

14-
get "/api/products/count", to: "products#count"
15-
get "/api/products/create", to: "products#create"
14+
scope path: :api, format: :json do
15+
# POST /api/products and GET /api/products/count
16+
resources :products, only: :create do
17+
collection do
18+
get :count
19+
end
20+
end
21+
end
1622

1723
# Any other routes will just render the react app
1824
match "*path" => "home#index", via: [:get, :post]

0 commit comments

Comments
 (0)