Sha256: 996b72f06ba0052b35307eacbeef721e18e77cc20a6bb5f02c26f1c340c69330

Contents?: true

Size: 1.97 KB

Versions: 9

Compression:

Stored size: 1.97 KB

Contents

module Logistics
  module Core
    class ContentTypesController < ApplicationController
      before_action :set_content_type, only: [:update]

      # GET /content_types
      # GET /content_types.json
      def index
        @content_types = ContentType.all
        response = Mks::Common::MethodResponse.new(true, nil, @content_types, nil, nil)
        render json: response
      end

      def lookup
        @content_types = ContentType.order(:name).select("id, name")
        response =Mks::Common::MethodResponse.new(true, nil, @content_types, nil, nil)
        render json: response
      end

      # POST /content_types
      # POST /content_types.json
      def create
        @content_type = ContentType.new(content_type_params)
        if @content_type.valid?
          if @content_type.save
            response = Mks::Common::MethodResponse.new(true, "Content Type data Saved Successfully!", @content_type, nil, nil)
          end
        else
          errors = Mks::Common::Util.error_messages @content_type
          response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
        end
        render json: response
      end

      # PATCH/PUT /content_types/1
      # PATCH/PUT /content_types/1.json
      def update
        @old_content_type = set_content_type
        @content_type = ContentType.new(content_type_params)
        if @content_type.valid?
          if @old_content_type.update(content_type_params)
            response = Mks::Common::MethodResponse.new(true, "Content Type data Updated Successfully!", nil, nil)
          end
        else
          errors = Mks::Common::Util.error_messages @content_type
          response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
        end
        render json: response
      end

      private

      def set_content_type
        @content_type = ContentType.find(params[:id])
      end

      def content_type_params
        params.require(:content_type).permit(:code, :name)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
logistics_core-21.11.2 app/controllers/logistics/core/content_types_controller.rb
logistics_core-21.11.1 app/controllers/logistics/core/content_types_controller.rb
logistics_core-21.08.1 app/controllers/logistics/core/content_types_controller.rb
logistics_core-21.03.1 app/controllers/logistics/core/content_types_controller.rb
logistics_core-20.10.3 app/controllers/logistics/core/content_types_controller.rb
logistics_core-20.10.2 app/controllers/logistics/core/content_types_controller.rb
logistics_core-20.10.1 app/controllers/logistics/core/content_types_controller.rb
logistics_core-20.9.1 app/controllers/logistics/core/content_types_controller.rb
logistics_core-20.8.1 app/controllers/logistics/core/content_types_controller.rb