Class: Logistics::Core::AgenciesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Logistics::Core::AgenciesController
- Defined in:
- app/controllers/logistics/core/agencies_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /agencies POST /agencies.json.
- #get_document_type_with_no_agency ⇒ Object
- #get_permit_documents ⇒ Object
-
#index ⇒ Object
GET /agencies GET /agencies.json.
-
#update ⇒ Object
PATCH/PUT /agencies/1 PATCH/PUT /agencies/1.json.
Instance Method Details
#create ⇒ Object
POST /agencies POST /agencies.json
16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/logistics/core/agencies_controller.rb', line 16 def create @agency = Agency.new(agency_params) if @agency.save response = Mks::Common::MethodResponse.new(true, "Agency information saved successfully!", @agency, nil, nil) else errors = Mks::Common::Util. @agency, "Agency" response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end |
#get_document_type_with_no_agency ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/controllers/logistics/core/agencies_controller.rb', line 56 def get_document_type_with_no_agency dt_ids = AgencyPermitDocument.where(agency_id: params[:id]).map(&:document_type_id) document_types = DocumentType.where.not(id: dt_ids) data = JSON(ActiveModelSerializers::SerializableResource.new(document_types).to_json) response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end |
#get_permit_documents ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/logistics/core/agencies_controller.rb', line 39 def get_permit_documents agency_id = params[:id] agency_permit_documents = AgencyPermitDocument.where agency_id: agency_id result = [] agency_permit_documents.each do |document_type| result.push({ id: document_type.id, agency_id: document_type.agency_id, agency_name: document_type.agency.name, document_type_id: document_type.document_type_id, document_name: document_type.document_type.name, document_type_category: document_type.document_type.document_type_category.name, document_origin: document_type.document_type.document_type_origin.name }) end response = Mks::Common::MethodResponse.new(true, nil, result, nil, nil) render json: response end |
#index ⇒ Object
GET /agencies GET /agencies.json
8 9 10 11 12 |
# File 'app/controllers/logistics/core/agencies_controller.rb', line 8 def index data = ApplicationRecord.as_json(Agency.includes(:agency_category)) response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end |
#update ⇒ Object
PATCH/PUT /agencies/1 PATCH/PUT /agencies/1.json
29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/logistics/core/agencies_controller.rb', line 29 def update if @agency.update(agency_params) response = Mks::Common::MethodResponse.new(true, "Agency information updated successfully!", @agency, nil, nil) else errors = Mks::Common::Util. @agency, "Agency" response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end |