End of evening commit, changing supplier to JSONAPI
This commit is contained in:
@@ -21,7 +21,16 @@ module Suppliers
|
||||
end
|
||||
@lists.include_relation(:table, :users, orders: {product_orders: :product})
|
||||
|
||||
render json: @lists, each_serializer: Suppliers::ListSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@lists, serializer: Suppliers::ListSerializer, is_collection: true, include: %w[
|
||||
orders
|
||||
orders.product_orders
|
||||
orders.product_orders.order
|
||||
orders.product_orders.product
|
||||
users
|
||||
join_requests
|
||||
join_requests.user
|
||||
table
|
||||
])
|
||||
end
|
||||
|
||||
|
||||
@@ -47,26 +56,14 @@ module Suppliers
|
||||
@lists = List.for_supplier_created_at current_supplier, @start_time..@end_time
|
||||
@lists.include_relation(:table) # for number
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render json: @lists }
|
||||
end
|
||||
render json: JSONAPI::Serializer.serialize(@lists, serializer: Suppliers::ListSerializer, is_collection: true, include: %w[table])
|
||||
end
|
||||
|
||||
# GET /lists/1
|
||||
# GET /lists/1.json
|
||||
def show
|
||||
@list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
respond_to do |format|
|
||||
format.html {}
|
||||
format.json do
|
||||
if params[:old_style] then
|
||||
render json: @list.with_orders_as_json
|
||||
else
|
||||
render json: @list, serializer: Suppliers::ListSerializer
|
||||
end
|
||||
end
|
||||
end
|
||||
render json: JSONAPI::Serializer.serialize(@list, serializer: Suppliers::ListSerializer)
|
||||
end
|
||||
|
||||
# GET /lists/1/extra_info
|
||||
@@ -83,10 +80,7 @@ module Suppliers
|
||||
@list.section_id = params[:section_id].presence
|
||||
@tables = current_supplier.active_tables
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.json { render json: @list }
|
||||
end
|
||||
render json: @list
|
||||
end
|
||||
|
||||
# POST /lists
|
||||
@@ -95,17 +89,10 @@ module Suppliers
|
||||
@list = List.new(list_params)
|
||||
@list.supplier = current_supplier
|
||||
|
||||
respond_to do |format|
|
||||
if @list.save
|
||||
format.html { redirect_to [:suppliers, @list.section || @list], notice: t('action.create.successfull', model: List.model_name.human) }
|
||||
format.json { render json: @list, status: :created, location: @list }
|
||||
else
|
||||
format.html do
|
||||
@tables = current_supplier.active_tables
|
||||
render action: "new"
|
||||
end
|
||||
format.json { render json: {errors: @list.errors}, status: :unprocessable_entity }
|
||||
end
|
||||
if @list.save
|
||||
render json: @list
|
||||
else
|
||||
render json: {errors: @list.errors}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -120,14 +107,10 @@ module Suppliers
|
||||
def update
|
||||
@list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @list.update_attributes(list_params)
|
||||
format.html { redirect_to [:suppliers, @list], notice: t('action.update.successfull', model: List.model_name.human) }
|
||||
format.json { render json: @list }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: {errors: @list.errors}, status: :unprocessable_entity }
|
||||
end
|
||||
if @list.update_attributes(list_params)
|
||||
render json: @list
|
||||
else
|
||||
render json: {errors: @list.errors}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -136,11 +119,7 @@ module Suppliers
|
||||
def destroy
|
||||
@list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
@list.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to suppliers_lists_url, notice: t('action.destroy.successfull', model: List.model_name.human) }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
head :ok
|
||||
end
|
||||
# POST /supplier/lists/1/close
|
||||
def close
|
||||
|
||||
Reference in New Issue
Block a user