JSONApi part1

This commit is contained in:
2015-09-02 15:52:48 +02:00
parent 5d1ecd81c8
commit f47a8a9ed0
51 changed files with 386 additions and 141 deletions
@@ -0,0 +1,7 @@
module Users
module Lists
class OrdersController < Users::ApplicationController
respond_to :json
end
end
end
+8 -11
View File
@@ -7,24 +7,21 @@ module Users
#lists.include_relation(:supplier)
lists.reject!{|l| l.id == params[:exclude_list]} if params[:exclude_list].present?
lists.reject!{|l| l.id == current_user.active_list_id } if current_user && current_user.active_list_id.present? # see spec Loading lists and switching to the order products view works, lists loading may unlink active list orders
lists.include_relation(:users, :orders, :supplier)
render json: lists, each_serializer: UserListSerializer, meta: {total_pages: lists.total_pages, page: lists.current_page} #, root: :lists
lists.include_relation(:users, :supplier)
render json: lists, each_serializer: Users::ListSerializer, meta: {total_pages: lists.total_pages, page: lists.current_page} #, root: :lists
end
#EMBER
def current
list = current_user.active_list
render json: {}, status: :not_found and return unless list.present?
[list].include_relation(supplier: {product_categories: :products}, orders: :product_orders) # table also when it is a real array :)
render json: json_response(not_present: true) and return unless list.present?
render json: list, serializer: UserExtendedListSerializer
@list = current_user.active_list
show
end
def show
list = List.find(params[:id])
render json: {}, status: :not_found and return unless list.present? && Array.wrap(list.user_ids).include?(current_user.id)
[list].include_relation(supplier: {product_categories: :products}, orders: :product_orders) # table also when it is a real array :)
render json: list, serializer: UserExtendedListSerializer
@list ||= List.find(params[:id])
render json: {}, status: :not_found and return unless @list.present? && Array.wrap(@list.user_ids).include?(current_user.id)
[@list].include_relation(:users)
render json: @list, serializer: Users::ListSerializer, include: %w[supplier users]
end
end
end
+10 -1
View File
@@ -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
+1 -1
View File
@@ -2,7 +2,7 @@ module Users
class TablesController < Users::ApplicationController
def show
@table = Table.find(params[:id])
render json: @table, serializer: UserExtendedTableSerializer
render json: @table, serializer: Users::TableSerializer
end
end
end