JSONApi progress

This commit is contained in:
2015-09-03 20:42:48 +02:00
parent f47a8a9ed0
commit e4dde28dd0
27 changed files with 215 additions and 64 deletions
+9 -3
View File
@@ -8,7 +8,7 @@ module Users
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, :supplier)
render json: lists, each_serializer: Users::ListSerializer, meta: {total_pages: lists.total_pages, page: lists.current_page} #, root: :lists
render json: JSONAPI::Serializer.serialize(lists, serializer: Users::ListSerializer, include: %w[supplier users], is_collection: true, meta: {total_pages: lists.total_pages, page: lists.current_page}) #, root: :lists
end
#EMBER
@@ -17,11 +17,17 @@ module Users
show
end
def table
list = List.find(params[:id])
render json: {}, status: :not_found and return unless list.present?
@table = list.table
render json: JSONAPI::Serializer.serialize(@table, serializer: Users::TableSerializer)
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(:users)
render json: @list, serializer: Users::ListSerializer, include: %w[supplier users]
render json: JSONAPI::Serializer.serialize(@list, serializer: Users::ListSerializer, include: %w[supplier users])
end
end
end
+1 -1
View File
@@ -8,7 +8,7 @@ module Users
@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]
render json: JSONAPI::Serializer.serialize(orders, serializer: Users::OrderSerializer, include: %w[product_orders product_orders.order], is_collection: true)
end
# Used by the user Ember app
+8 -1
View File
@@ -2,7 +2,14 @@ module Users
class TablesController < Users::ApplicationController
def show
@table = Table.find(params[:id])
render json: @table, serializer: Users::TableSerializer
render json: JSONAPI::Serializer.serialize(@table, serializer: Users::TableSerializer)
end
def supplier
table = Table.find(params[:id])
supplier = table.supplier
supplier.product_categories.include_relations(:products)
render json: JSONAPI::Serializer.serialize(supplier, serializer: Users::SupplierSerializer, include: %w[product_categories product_categories.products product_categories.supplier])
end
end
end