End of evening commit, changing supplier to JSONAPI

This commit is contained in:
2015-09-08 23:22:13 +02:00
parent 3cb7fd2a6f
commit 9c1945252d
36 changed files with 195 additions and 230 deletions
@@ -17,7 +17,7 @@ module Suppliers
# end
# end
# end
render json: @sections, each_serializer: Suppliers::ExtendedSectionSerializer
render json: JSONAPI::Serializer.serialize(@sections, serializer: Suppliers::ExtendedSectionSerializer, is_collection: true)
end
# GET /sections/1
@@ -55,14 +55,10 @@ module Suppliers
@section = Section.new(section_params)
@section.supplier = current_supplier
respond_to do |format|
if @section.save
format.html { redirect_to [:suppliers, @section], notice: t('action.create.successfull', model: Section.model_name.human) }
format.json { render json: @section, serializer: Suppliers::SectionSerializer, status: :created }
else
format.html { render action: "new" }
format.json { render json: {errors: @section.errors}, status: :unprocessable_entity }
end
if @section.save
render json: @section, serializer: Suppliers::SectionSerializer, status: :created
else
render json: {errors: @section.errors}, status: :unprocessable_entity
end
end
@@ -71,14 +67,10 @@ module Suppliers
def update
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
respond_to do |format|
if @section.update_attributes(section_params)
format.html { redirect_to [:suppliers, @section], notice: t('action.update.successfull', model: Section.model_name.human) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: {errors: @section.errors}, status: :unprocessable_entity }
end
if @section.update_attributes(section_params)
head :ok
else
render json: {errors: @section.errors}, status: :unprocessable_entity
end
end
@@ -88,10 +80,7 @@ module Suppliers
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
@section.destroy
respond_to do |format|
format.html { redirect_to suppliers_sections_url, notice: t('action.destroy.successfull', model: Section.model_name.human) }
format.json { head :no_content }
end
head :ok
end
# GET /sections/1/manage_tables
@@ -99,10 +88,7 @@ module Suppliers
def manage_tables
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @section }
end
render json: @section
end
# GET /sections/1/tables_view
@@ -111,12 +97,7 @@ module Suppliers
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
@tables = @section.tables_with_active_list_id
respond_to do |format|
format.html # show.html.erb
format.json do
render json: @section.for_tables_as_json
end
end
render json: @section
end
# POST /sections/1/add_tables {number_start: 1423, number_end: 234234}
@@ -134,8 +115,7 @@ module Suppliers
added_tables << table
end
@section.arrange_tables_in_grid added_tables
table_json = ActiveModel::ArraySerializer.new(@section.tables, each_serializer: SupplierTableSerializer, root: false).as_json
render json: {tables: table_json}
render json: JSONAPI::Serializer.serialize(@section.tables, serializer: Supplier::TableSerializer, is_collection: true, include: %w[section])
end
# POST /sections/1/arrange_tables {number_start: 1423, number_end: 234234}