module Logistics module Core class AgencyPermitDocumentsController < ApplicationController before_action :set_agency_permit_document, only: [:update, :get_document_type] # GET /agency_permit_documents # GET /agency_permit_documents.json def index agency_permit_documents = AgencyPermitDocument.where(agency_id: params[:agency_id]) data = ActiveModelSerializers::SerializableResource.new(agency_permit_documents).as_json response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end def document_type data = ApplicationRecord.as_json(@agency_permit_document.document_type) response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end # POST /agency_permit_documents # POST /agency_permit_documents.json def create @agency_permit_document = AgencyPermitDocument.new(agency_permit_document_params[:agency_permit_document]) if @agency_permit_document.save response = Mks::Common::MethodResponse.new(true, "Agency Permit Document successfully saved!", @agency_permit_document, nil, nil) else errors = Mks::Common::Util.error_messages @agency_permit_document, "Agency Permit Document" response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end # PATCH/PUT /agency_permit_documents/1 # PATCH/PUT /agency_permit_documents/1.json def update if @agency_permit_document.update(agency_permit_document_params[:agency_permit_document]) response = Mks::Common::MethodResponse.new(true, "Agency Permit Document successfully updated!", @agency_permit_document, nil, nil) else errors = Mks::Common::Util.error_messages @agency_permit_document, "Agency Permit Document" response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end private # Use callbacks to share common setup or constraints between actions. def set_agency_permit_document @agency_permit_document = AgencyPermitDocument.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def agency_permit_document_params params.permit(:agency_permit_document => [:document_type_id, :agency_id]) end end end end