Class: Logistics::Core::WeightRangesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Logistics::Core::WeightRangesController
- Defined in:
- app/controllers/logistics/core/weight_ranges_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /weight_ranges POST /weight_ranges.json.
-
#index ⇒ Object
GET /weight_ranges GET /weight_ranges.json.
-
#update ⇒ Object
PATCH/PUT /weight_ranges/1 PATCH/PUT /weight_ranges/1.json.
Instance Method Details
#create ⇒ Object
POST /weight_ranges POST /weight_ranges.json
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/logistics/core/weight_ranges_controller.rb', line 19 def create weight_range = WeightRange.new(weight_range_params) overlap = WeightRange.check_range_overlap weight_range if !overlap if weight_range.save response = Mks::Common::MethodResponse.new(true, "Weight Range saved successfully!", weight_range, nil, nil) else errors = Mks::Common::Util. weight_range, "Weight Range" response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end else errors = ["Weight range information overlap with previous entry!"] response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end |
#index ⇒ Object
GET /weight_ranges GET /weight_ranges.json
11 12 13 14 15 |
# File 'app/controllers/logistics/core/weight_ranges_controller.rb', line 11 def index weight_ranges = WeightRange.fetch_all response = Mks::Common::MethodResponse.new(true, nil, weight_ranges, nil, nil) render json: response end |
#update ⇒ Object
PATCH/PUT /weight_ranges/1 PATCH/PUT /weight_ranges/1.json
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/logistics/core/weight_ranges_controller.rb', line 38 def update weight_range = WeightRange.find(params[:id]) new_weight_range = WeightRange.new(weight_range_params) overlap_result = WeightRange.check_range_overlap_update new_weight_range, params[:id] if !overlap_result['overlap'] if weight_range.update(weight_range_params) response = Mks::Common::MethodResponse.new(true, "Weight Range updated successfully!", weight_range, nil, nil) else errors = Mks::Common::Util. weight_range, "Weight Range" response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end else errors = ["Weight range information overlap with previous entry!"] response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end |