mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-08 22:56:06 +00:00
Move json to API and strip index action
This commit is contained in:
@@ -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'
|
||||
|
||||
23
app/controllers/api/orders_controller.rb
Normal file
23
app/controllers/api/orders_controller.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user