cats_core 1.0.28 → 1.0.32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b39ab8dfbbd491a6a9e68acfd75dcf77f88a477e5fe1eb2bce823a17dd857bd8
4
- data.tar.gz: ffe26682256958cfb286feda0ae58f498922ed65c505af9401298fef5a7b7b44
3
+ metadata.gz: b481d401018e6fdfdf93be24ee465d117e45b4a888e4e4a0e079f3aa4654009a
4
+ data.tar.gz: dae45a28258a5125762192e4bd2579ed2b5c486ea74271dac1437ee4bea5c2b1
5
5
  SHA512:
6
- metadata.gz: 16218f6af68d849f4550848cffc761e265b4cf80972d6befc8edbe19aed2eff86730299042c7ed098f372b8c55f77a698638fcaf8ca5317001db07bc0d21da86
7
- data.tar.gz: e7a54575147d96397141682e144749767cc9be51abb89876c382202550531842876cba3c3a87800d01fc9671f3cc8fec056f29f992e3507a0f4a33423756f85b
6
+ metadata.gz: 2404e609083ccfe957927a8a7fbc9355eaa564f2aa2620af2eac779a10457b11661d1db34a8b6bdb27ad3b60ff2ba717dce8e35627688f2590bd2c292d17079f
7
+ data.tar.gz: d2748d191c6ac70a5977acf13b3647a0387dcd80dfeaa4dfb03c88244a845b353aeffd25cd6856ba5d1a3c2934ed5a8a85b71ab82e2cdde2f1ddc56afd14ae66
@@ -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,8 +6,13 @@ 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 }
12
+
13
+ delegate(:reference_no, to: :rhn_request, prefix: :rhn, allow_nil: true)
14
+ delegate(:batch_no, to: :commodity, prefix: true)
15
+ delegate(:name, to: :source, prefix: true)
11
16
  end
12
17
  end
13
18
  end
@@ -13,6 +13,9 @@ 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)
16
19
  end
17
20
  end
18
21
  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.28'.freeze
3
+ VERSION = '1.0.32'.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.28
4
+ version: 1.0.32
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