Skip to content

Commit

Permalink
Merge pull request #128 from Shopify/change_create_route_to_post
Browse files Browse the repository at this point in the history
Change create product route to `POST /api/products`
  • Loading branch information
rachel-carvalho committed Apr 18, 2024
2 parents 6f6bf81 + 618cd7a commit d0868bc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-3.1.2
ruby-3.3.0
2 changes: 2 additions & 0 deletions web/app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# frozen_string_literal: true

class ProductsController < AuthenticatedController
# GET /api/products/count
def count
product_count = ShopifyAPI::Product.count.body
ShopifyAPI::Logger.info("Retrieved product count: #{product_count["count"]}")
render(json: product_count)
end

# POST /api/products
def create
ProductCreator.call(count: 5, session: current_shopify_session)

Expand Down
10 changes: 8 additions & 2 deletions web/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@

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

get "/api/products/count", to: "products#count"
get "/api/products/create", to: "products#create"
scope path: :api, format: :json do
# POST /api/products and GET /api/products/count
resources :products, only: :create do
collection do
get :count
end
end
end

# Any other routes will just render the react app
match "*path" => "home#index", via: [:get, :post]
Expand Down
2 changes: 1 addition & 1 deletion web/frontend

0 comments on commit d0868bc

Please sign in to comment.