JSONApi part1
This commit is contained in:
@@ -2,6 +2,15 @@ module Users
|
||||
class OrdersController < Users::ApplicationController
|
||||
respond_to :json
|
||||
|
||||
# /nested resource
|
||||
def index
|
||||
render json: {}, status: :not_found and return unless params[:list_id].present?
|
||||
@list = List.find(params[:list_id])
|
||||
render json: {}, status: :not_found and return unless @list.present? && Array.wrap(@list.user_ids).include?(current_user.id)
|
||||
orders = @list.orders.include_relation(:product_orders)
|
||||
render json: orders, each_serializer: Users::OrderSerializer, include: %w[product_orders]
|
||||
end
|
||||
|
||||
# Used by the user Ember app
|
||||
# POST /user/orders
|
||||
def create
|
||||
@@ -25,7 +34,7 @@ module Users
|
||||
list = List.from_table( table, current_user )
|
||||
end
|
||||
order = list.place_order product_orders: params[:product_orders], user: current_user
|
||||
render json: order, serializer: OrderSerializer
|
||||
render json: order, serializer: Users::OrderSerializer
|
||||
#render nothing: true
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user