37 lines
1.2 KiB
Ruby
37 lines
1.2 KiB
Ruby
module Suppliers
|
|
class SectionElementsController < Suppliers::ApplicationController
|
|
def index
|
|
@section_elements = SectionElement.for_supplier(current_supplier)
|
|
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: JSONAPI::Serializer.serialize(@section_element, serializer: Suppliers::SectionElementSerializer)
|
|
else
|
|
render json: {errors: @section.errors}, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def update
|
|
if @section_element.update_attributes section_element_params
|
|
render json: JSONAPI::Serializer.serialize(@section_element, serializer: Suppliers::SectionElementSerializer)
|
|
else
|
|
render json: {errors: @section.errors}, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@section_element.destroy()
|
|
head :ok
|
|
end
|
|
|
|
private
|
|
|
|
def section_element_params
|
|
params.require(:section_element).permit %i[name svg dpm box_width box_height position_x position_y rotation svg_element_id section_id]
|
|
end
|
|
end
|
|
end
|