Move json to API and strip index action

This commit is contained in:
Matt-Yorkley
2018-10-23 10:34:42 +01:00
parent 0bd67bd06a
commit 334eebeab1
4 changed files with 27 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
angular.module("admin.resources").factory 'OrderResource', ($resource) ->
$resource('/admin/orders/:id/:action.json', {}, {
'index':
url: '/api/orders.json'
method: 'GET'
'update':
method: 'PUT'

View File

@@ -0,0 +1,23 @@
module Api
class OrdersController < BaseController
def index
authorize! :admin, Spree::Order
search_results = SearchOrders.new(params, spree_current_user)
render json: {
orders: serialized_orders(search_results.orders),
pagination: search_results.pagination_data
}
end
private
def serialized_orders(orders)
ActiveModel::ArraySerializer.new(
orders,
each_serializer: Api::Admin::OrderSerializer
)
end
end
end

View File

@@ -23,17 +23,7 @@ Spree::Admin::OrdersController.class_eval do
respond_to :html, :json
def index
@results = SearchOrders.new(params, spree_current_user) if json_request?
respond_to do |format|
format.html
format.json do
render json: {
orders: serialized_orders,
pagination: @results.pagination_data
}
end
end
# Moved to api. Overriding the action so we only render the page template.
end
# Overwrite to use confirm_email_for_customer instead of confirm_email.
@@ -96,8 +86,4 @@ Spree::Admin::OrdersController.class_eval do
render 'set_distribution', locals: { order: @order }
end
end
def serialized_orders
ActiveModel::ArraySerializer.new(@results.orders, each_serializer: Api::Admin::OrderSerializer)
end
end

View File

@@ -103,6 +103,8 @@ Openfoodnetwork::Application.routes.draw do
get :accessible, on: :collection
end
resources :orders, only: [:index]
resource :status do
get :job_queue
end