End of evening commit, changing supplier to JSONAPI
This commit is contained in:
@@ -7,17 +7,17 @@ module Suppliers
|
||||
@employee_shifts.select! do |shift|
|
||||
current_supplier.employee_ids.include?(shift.employee.try(:id))
|
||||
end
|
||||
render json: @employee_shifts, each_serializer: Suppliers::EmployeeShiftSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@employee_shifts, serializer: Suppliers::EmployeeShiftSerializer, is_collection: true, include: %w[employee supplier])
|
||||
end
|
||||
def create
|
||||
@employee_shift.supplier = current_supplier
|
||||
@employee_shift.save
|
||||
render json: @employee_shift, serializer: Suppliers::EmployeeShiftSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@employee_shift, serializer: Suppliers::EmployeeShiftSerializer, include: %w[employee supplier])
|
||||
end
|
||||
|
||||
def update
|
||||
@employee_shift.update employee_shift_params
|
||||
render json: @employee_shift, serializer: Suppliers::EmployeeShiftSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@employee_shift, serializer: Suppliers::EmployeeShiftSerializer)
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
||||
@@ -8,13 +8,13 @@ module Suppliers
|
||||
# GET /employees.json
|
||||
def index
|
||||
@employees = current_supplier.employees
|
||||
render json: @employees, each_serializer: Suppliers::EmployeeSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@employees, serializer: Suppliers::EmployeeSerializer, is_collection: true)
|
||||
end
|
||||
|
||||
# GET /employees/1
|
||||
# GET /employees/1.json
|
||||
def show
|
||||
render json: @employee, serializer: Suppliers::EmployeeSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@employee, serializer: Suppliers::EmployeeSerializer)
|
||||
end
|
||||
|
||||
# POST /employees
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,11 +3,11 @@ module Suppliers
|
||||
prepend_before_action :find_page, only: [:show]
|
||||
def index
|
||||
@pages = Page.all_for_suppliers(locale: params[:locale])
|
||||
render json: @pages, each_serializer: Suppliers::PageSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@pages, serializer: Suppliers::PageSerializer, is_collection: true)
|
||||
end
|
||||
|
||||
def show
|
||||
render json: @page, serializer: Suppliers::PageSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@page, serializer: Suppliers::PageSerializer)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -2,13 +2,13 @@ module Suppliers
|
||||
class SectionAreasController < Suppliers::ApplicationController
|
||||
def index
|
||||
@section_areas = SectionArea.for_supplier(current_supplier)
|
||||
render json: @section_areas, each_serializer: Suppliers::SectionAreaSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@section_areas, serializer: Suppliers::SectionAreaSerializer, is_collection: true)
|
||||
end
|
||||
|
||||
def create
|
||||
@section_area.supplier = current_supplier
|
||||
if @section_area.save
|
||||
render json: @section_area, serializer: Suppliers::SectionAreaSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@section_area, serializer: Suppliers::SectionAreaSerializer)
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
@@ -16,7 +16,7 @@ module Suppliers
|
||||
|
||||
def update
|
||||
if @section_area.update_attributes section_area_params
|
||||
render json: @section_area, serializer: Suppliers::SectionAreaSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@section_area, serializer: Suppliers::SectionAreaSerializer)
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
@@ -2,13 +2,13 @@ module Suppliers
|
||||
class SectionElementsController < Suppliers::ApplicationController
|
||||
def index
|
||||
@section_elements = SectionElement.for_supplier(current_supplier)
|
||||
render json: @section_elements, each_serializer: Suppliers::SectionElementSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@section_elements, serializer: Suppliers::SectionElementSerializer, is_collection: true)
|
||||
end
|
||||
|
||||
def create
|
||||
@section_element.supplier = current_supplier
|
||||
if @section_element.save
|
||||
render json: @section_element, serializer: Suppliers::SectionElementSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@section_element, serializer: Suppliers::SectionElementSerializer)
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
@@ -16,7 +16,7 @@ module Suppliers
|
||||
|
||||
def update
|
||||
if @section_element.update_attributes section_element_params
|
||||
render json: @section_element, serializer: Suppliers::SectionElementSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@section_element, serializer: Suppliers::SectionElementSerializer)
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -6,13 +6,13 @@ module Suppliers
|
||||
|
||||
def show
|
||||
[current_supplier].include_relations(sections: :tables, product_categories: {products: :product_variants})
|
||||
render json: current_supplier, serializer: Suppliers::SupplierSerializer #.new(current_supplier).as_json
|
||||
render json: JSONAPI::Serializer.serialize(current_supplier, serializer: Suppliers::SupplierSerializer) #.new(current_supplier).as_json
|
||||
end
|
||||
|
||||
def update
|
||||
@supplier = current_supplier
|
||||
current_supplier.update_attributes(supplier_params)
|
||||
render json: Suppliers::SupplierSerializer.new(current_supplier).as_json
|
||||
render json: JSONAPI::Serializer.serialize( current_supplier, serializer: Suppliers::SupplierSerializer)
|
||||
end
|
||||
|
||||
def switch_to
|
||||
|
||||
@@ -2,7 +2,7 @@ module Suppliers
|
||||
class SvgElementsController < Suppliers::ApplicationController
|
||||
def index
|
||||
@svg_elements = SvgElement.active
|
||||
render json: @svg_elements, each_serializer: Suppliers::SvgElementSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@svg_elements, serializer: Suppliers::SvgElementSerializer)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,10 +6,7 @@ module Suppliers
|
||||
@tables = Table.for_supplier(current_supplier, page: params[:page], per_page: params[:per_page] || 25, from_number: params[:from_number], to_number: params[:to_number])
|
||||
@tables.include_relation(:section)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render json: @tables }
|
||||
end
|
||||
render json: @tables
|
||||
end
|
||||
|
||||
# GET /tables/1
|
||||
@@ -17,10 +14,7 @@ module Suppliers
|
||||
def show
|
||||
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json { render json: @table }
|
||||
end
|
||||
render json: @table
|
||||
end
|
||||
|
||||
# GET /tables/new
|
||||
@@ -29,10 +23,7 @@ module Suppliers
|
||||
@table = Table.new
|
||||
@table.section_id = params[:section_id].presence
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.json { render json: @table }
|
||||
end
|
||||
render json: @table
|
||||
end
|
||||
|
||||
# GET /tables/1/edit
|
||||
@@ -46,14 +37,10 @@ module Suppliers
|
||||
@table = Table.new(table_params)
|
||||
@table.supplier = current_supplier
|
||||
|
||||
respond_to do |format|
|
||||
if @table.save
|
||||
format.html { redirect_to [:suppliers, @table.section || @table], notice: t('action.create.successfull', model: Table.model_name.human) }
|
||||
format.json { render json: @table, status: :created }
|
||||
else
|
||||
format.html { render action: "new" }
|
||||
format.json { render json: {errors: @table.errors}, status: :unprocessable_entity }
|
||||
end
|
||||
if @table.save
|
||||
render json: @table, status: :created
|
||||
else
|
||||
render json: {errors: @table.errors}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -62,14 +49,10 @@ module Suppliers
|
||||
def update
|
||||
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @table.update_attributes(table_params)
|
||||
format.html { redirect_to [:suppliers, @table.section || @table], notice: t('action.update.successfull', model: Table.model_name.human) }
|
||||
format.json { render json: @table }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: {errors: @table.errors}, status: :unprocessable_entity }
|
||||
end
|
||||
if @table.update_attributes(table_params)
|
||||
render json: @table
|
||||
else
|
||||
render json: {errors: @table.errors}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -79,10 +62,7 @@ module Suppliers
|
||||
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
@table.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to suppliers_tables_url, notice: t('action.destroy.successfull', model: Table.model_name.human) }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
head :ok
|
||||
end
|
||||
|
||||
def qr_codes
|
||||
|
||||
Reference in New Issue
Block a user