cats_core 1.0.29 → 1.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 486360b9f249922d7bacf1223f81d9bbf1e32a8d0b0a25822f93fadfc93bab91
4
- data.tar.gz: b01a2f336d413f769183df4709d8bd29ffdda06da4d926e134c766502c7e1ebe
3
+ metadata.gz: f7e8bd73f8569d1c144fed8b4b5676ee0c163333156d501b21a2516bd2fd535f
4
+ data.tar.gz: ea06d76acd38e5c9cf96067dbfb84730abc4ade1ceb741910a75a0c56dd1d2fe
5
5
  SHA512:
6
- metadata.gz: d20caffe7fd8c5463fc718e77d2a5f794b028c982f0dacf555d4cd168848d66c314fac694ac16d31e8d97986f784f7ea8ec53b77f4283cbd99404c11295f5306
7
- data.tar.gz: cd3addf45f7891b459330e3f07b3d6f44318c14071397f0dbfabf4239a0a65765ef9e5b97cb31b1196f49793b3c75b7b797d04bd286e484929f41cc568159366
6
+ metadata.gz: 22114a9def60bcae317450fa5a4fb9fbac9f938dfb314cefcd888c1a4a9f1dbfd4a345bd254810245efe8a6e638267dfc4a8e2a76520310164f460042535c640
7
+ data.tar.gz: 057d3981b8b746a3d19b83c4dd5b20357dc38d8f909973f6e7e82c1bf3f951c6fb14dd7bd8bd544524f1d4333ceb0eeaca25486a40a49d4feb0e7a75c59d0c1c
@@ -0,0 +1,49 @@
1
+ module Cats
2
+ module Core
3
+ class UnitOfMeasuresController < ApplicationController
4
+ before_action :set_unit_of_measure, only: %i[show update]
5
+
6
+ def index
7
+ data = ActiveModelSerializers::SerializableResource.new(Cats::Core::UnitOfMeasure.all)
8
+ render json: { success: true, data: data }
9
+ end
10
+
11
+ def show
12
+ data = ActiveModelSerializers::SerializableResource.new(@unit_of_measure)
13
+ render json: { success: true, data: data }
14
+ end
15
+
16
+ def create
17
+ obj = Cats::Core::UnitOfMeasure.new(model_params)
18
+ if obj.save
19
+ data = ActiveModelSerializers::SerializableResource.new(obj)
20
+ render json: { success: true, data: data }, status: :created
21
+ else
22
+ render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
23
+ end
24
+ end
25
+
26
+ def update
27
+ if @unit_of_measure.update(model_params)
28
+ data = ActiveModelSerializers::SerializableResource.new(@unit_of_measure)
29
+ render json: { success: true, data: data }
30
+ else
31
+ render json: {
32
+ success: false,
33
+ error: @unit_of_measure.errors.full_messages[0]
34
+ }, status: :unprocessable_entity
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def set_unit_of_measure
41
+ @unit_of_measure = Cats::Core::UnitOfMeasure.find(params[:id])
42
+ end
43
+
44
+ def model_params
45
+ params.require(:payload).permit(:abbreviation, :name, :unit_type)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -6,12 +6,14 @@ module Cats
6
6
  belongs_to :source, class_name: 'Cats::Core::Location'
7
7
 
8
8
  validates :commodity_status, presence: true
9
+ validates :reference_no, presence: true, uniqueness: true
9
10
  validates :quantity, presence: true, numericality: { greater_than: 0 }
10
11
  validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
11
12
 
12
- delegate(:reference_no, to: :rhn_request, prefix: :rhn)
13
+ delegate(:reference_no, to: :rhn_request, prefix: :rhn, allow_nil: true)
13
14
  delegate(:batch_no, to: :commodity, prefix: true)
14
15
  delegate(:name, to: :source, prefix: true)
16
+ delegate(:location_type, to: :source, prefix: true)
15
17
  end
16
18
  end
17
19
  end
@@ -13,6 +13,10 @@ module Cats
13
13
 
14
14
  errors.add(:base, 'source and destination cannot be the same') if allocation.source == destination
15
15
  end
16
+
17
+ delegate(:name, to: :destination, prefix: true)
18
+ delegate(:reference_no, to: :allocation, prefix: true)
19
+ delegate(:location_type, to: :destination, prefix: true)
16
20
  end
17
21
  end
18
22
  end
@@ -5,6 +5,8 @@ module Cats
5
5
 
6
6
  validates :reference_no, :request_date, presence: true
7
7
  validates :reference_no, uniqueness: true
8
+
9
+ delegate(:batch_no, to: :commodity, prefix: true)
8
10
  end
9
11
  end
10
12
  end
@@ -0,0 +1,3 @@
1
+ class UnitOfMeasureSerializer < ActiveModel::Serializer
2
+ attributes :id, :abbreviation, :name, :unit_type
3
+ end
data/config/routes.rb CHANGED
@@ -34,4 +34,5 @@ Cats::Core::Engine.routes.draw do
34
34
  end
35
35
  end
36
36
  resources :currencies, except: %i[destroy]
37
+ resources :unit_of_measures, except: %i[destroy]
37
38
  end
@@ -1,6 +1,7 @@
1
1
  class CreateCatsCoreAllocations < ActiveRecord::Migration[6.1]
2
2
  def change
3
3
  create_table :cats_core_allocations do |t|
4
+ t.string :reference_no, unique: true
4
5
  t.references :rhn_request,
5
6
  null: true,
6
7
  index: { name: 'rr_on_allocation_indx' },
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.0.29'.freeze
3
+ VERSION = '1.0.33'.freeze
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  FactoryBot.define do
2
2
  factory :allocation, class: 'Cats::Core::Allocation' do
3
+ reference_no { FFaker::Name.name }
3
4
  rhn_request { nil }
4
5
  commodity
5
6
  source factory: :location
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cats_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.29
4
+ version: 1.0.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
@@ -224,6 +224,7 @@ files:
224
224
  - app/controllers/cats/core/menus_controller.rb
225
225
  - app/controllers/cats/core/notifications_controller.rb
226
226
  - app/controllers/cats/core/roles_controller.rb
227
+ - app/controllers/cats/core/unit_of_measures_controller.rb
227
228
  - app/controllers/cats/core/users_controller.rb
228
229
  - app/jobs/cats/core/application_job.rb
229
230
  - app/models/cats/core/allocation.rb
@@ -267,6 +268,7 @@ files:
267
268
  - app/serializers/cats/core/currency_serializer.rb
268
269
  - app/serializers/cats/core/location_serializer.rb
269
270
  - app/serializers/cats/core/role_menu_serializer.rb
271
+ - app/serializers/cats/core/unit_of_measure_serializer.rb
270
272
  - app/services/cats/core/menu_service.rb
271
273
  - app/services/cats/core/notification_service.rb
272
274
  - app/services/cats/core/token_auth_service.rb