cats_core 1.0.18 → 1.0.22

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: 4e5a323d8291d9ed0b4e8ac75ce16c6c1b9cf91cd328fb12070b66c3682eb624
4
- data.tar.gz: 50ee9a685b52a59e48b97d8a0478055ee9b7f23ba2069e0e47bf0a51f4668c83
3
+ metadata.gz: 7847bbf4c0a83ac387d2b9e7bc1f8f4b4ffe184d12f9611ee60c6f14d1fe3078
4
+ data.tar.gz: 319c387eeddbd6342b1b4fe14ea921e7c3e686243feded978cad60d96c9756ad
5
5
  SHA512:
6
- metadata.gz: '092a7d07c58df8daf989d27038f0483048f8eb076edf00bfeeed526199c1bd15dade0f7293d0520b2ef92a0a6efbb85c705749ab9b7862db175ba52c22c968b4'
7
- data.tar.gz: fc2a83c12dd376cd710b1784dba71e2e5003a3df8e83c1b7f956886cbb078ced15cf05dc38b59c42ee09a3f1f2fc58f81260b9def42bd653c252564f96580183
6
+ metadata.gz: 5ec1c786270a96caa0097f2cd8c95d4a14e88b255d2def862f246770c36fd6956fc6b9e401ea931c4a306c0444c1ca9487fd64439769810249730c407b1e2ecb
7
+ data.tar.gz: eafd2a9293936dab8f7130c9428598fdc88fffb4b7a294e3f381fb08f985d9b379e5d268aa340ab5cfce4952da6c6b10b8b4b829cce8309268f48fb26de3b7ba
@@ -0,0 +1,55 @@
1
+ module Cats
2
+ module Core
3
+ class CommodityCategoriesController < ApplicationController
4
+ before_action :set_commodity_category, only: %i[show update]
5
+
6
+ def index
7
+ commodity_categories = Cats::Core::CommodityCategory.all.reject(&:has_children?)
8
+ data = ActiveModelSerializers::SerializableResource.new(commodity_categories)
9
+ render json: { success: true, data: data }
10
+ end
11
+
12
+ def show
13
+ data = ActiveModelSerializers::SerializableResource.new(@commodity_category)
14
+ render json: { success: true, data: data }
15
+ end
16
+
17
+ def children
18
+ parent = Cats::Core::CommodityCategory.find(params[:id])
19
+ data = ActiveModelSerializers::SerializableResource.new(parent.children)
20
+ render json: { success: true, data: data }
21
+ end
22
+
23
+ def create
24
+ obj = Cats::Core::CommodityCategory.new(model_params)
25
+ if obj.save
26
+ data = ActiveModelSerializers::SerializableResource.new(obj)
27
+ render json: { success: true, data: data }, status: :created
28
+ else
29
+ render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
30
+ end
31
+ end
32
+
33
+ def update
34
+ if @commodity_category.update(model_params)
35
+ data = ActiveModelSerializers::SerializableResource.new(@commodity_category)
36
+ render json: { success: true, data: data }
37
+ else
38
+ render json: {
39
+ success: false, error: @commodity_category.errors.full_messages[0]
40
+ }, status: :unprocessable_entity
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def set_commodity_category
47
+ @commodity_category = Cats::Core::CommodityCategory.find(params[:id])
48
+ end
49
+
50
+ def model_params
51
+ params.require('payload').permit(:code, :name, :description, :parent_id)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,46 @@
1
+ module Cats
2
+ module Core
3
+ class CurrenciesController < ApplicationController
4
+ before_action :set_currency, only: %i[show update]
5
+
6
+ def index
7
+ data = ActiveModelSerializers::SerializableResource.new(Cats::Core::Currency.all)
8
+ render json: { success: true, data: data }
9
+ end
10
+
11
+ def show
12
+ data = ActiveModelSerializers::SerializableResource.new(@currency)
13
+ render json: { success: true, data: data }
14
+ end
15
+
16
+ def create
17
+ obj = Cats::Core::Currency.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 @currency.update(model_params)
28
+ data = ActiveModelSerializers::SerializableResource.new(@currency)
29
+ render json: { success: true, data: data }
30
+ else
31
+ render json: { success: false, error: @currency.errors.full_messages[0] }, status: :unprocessable_entity
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def set_currency
38
+ @currency = Cats::Core::Currency.find(params[:id])
39
+ end
40
+
41
+ def model_params
42
+ params.require(:payload).permit(:code, :name)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,53 @@
1
+ module Cats
2
+ module Core
3
+ class LocationsController < ApplicationController
4
+ before_action :set_location, only: %i[show update]
5
+
6
+ def index
7
+ locations = Cats::Core::Location.where(location_type: params[:location_type])
8
+ data = ActiveModelSerializers::SerializableResource.new(locations)
9
+ render json: { success: true, data: data }
10
+ end
11
+
12
+ def show
13
+ data = ActiveModelSerializers::SerializableResource.new(@location)
14
+ render json: { success: true, data: data }
15
+ end
16
+
17
+ def children
18
+ parent = Cats::Core::Location.find(params[:id])
19
+ data = ActiveModelSerializers::SerializableResource.new(parent.children)
20
+ render json: { success: true, data: data }
21
+ end
22
+
23
+ def create
24
+ obj = Cats::Core::Location.new(model_params)
25
+ if obj.save
26
+ data = ActiveModelSerializers::SerializableResource.new(obj)
27
+ render json: { success: true, data: data }, status: :created
28
+ else
29
+ render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
30
+ end
31
+ end
32
+
33
+ def update
34
+ if @location.update(model_params)
35
+ data = ActiveModelSerializers::SerializableResource.new(@location)
36
+ render json: { success: true, data: data }
37
+ else
38
+ render json: { success: false, error: @location.errors.full_messages[0] }, status: :unprocessable_entity
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def set_location
45
+ @location = Cats::Core::Location.find(params[:id])
46
+ end
47
+
48
+ def model_params
49
+ params.require(:payload).permit(:name, :location_type, :description, :parent_id)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,6 +1,8 @@
1
1
  module Cats
2
2
  module Core
3
3
  class CommodityCategory < ApplicationRecord
4
+ has_ancestry
5
+
4
6
  validates :code, presence: true, uniqueness: true
5
7
  validates :name, presence: true
6
8
  end
@@ -10,6 +10,7 @@ module Cats
10
10
  SEASONS = [BELG, MEHER].freeze
11
11
 
12
12
  belongs_to :ration
13
+ has_many :hrp_items
13
14
 
14
15
  validates :reference_no, :year, :status, presence: true
15
16
  validates :season, presence: true, inclusion: { in: SEASONS }
@@ -7,6 +7,10 @@ module Cats
7
7
 
8
8
  validates :beneficiaries, presence: true, numericality: { greater_than: 0 }
9
9
  validates :commodity_amount, presence: true, numericality: { greater_than: 0 }
10
+ validates :hrp_id, uniqueness: { scope: :woreda_id }
11
+
12
+ delegate(:name, to: :woreda, prefix: true)
13
+ delegate(:name, to: :operator, prefix: true)
10
14
  end
11
15
  end
12
16
  end
@@ -0,0 +1,3 @@
1
+ class CommodityCategorySerializer < ActiveModel::Serializer
2
+ attributes :id, :code, :name, :description, :parent_id
3
+ end
@@ -0,0 +1,3 @@
1
+ class CurrencySerializer < ActiveModel::Serializer
2
+ attributes :id, :code, :name
3
+ end
@@ -0,0 +1,3 @@
1
+ class LocationSerializer < ActiveModel::Serializer
2
+ attributes :id, :name, :location_type, :description, :parent_id
3
+ end
data/config/routes.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  Cats::Core::Engine.routes.draw do
2
+ get 'locations/index'
3
+ get 'locations/children'
2
4
  post '/login', controller: :access, action: :login
3
5
  get '/notifications/unread', controller: :notifications, action: :unread
4
6
  get '/notifications/read', controller: :notifications, action: :read
@@ -21,4 +23,15 @@ Cats::Core::Engine.routes.draw do
21
23
  get 'warehouses', controller: :users, action: :warehouses
22
24
  end
23
25
  end
26
+ resources :locations, except: %i[destroy] do
27
+ member do
28
+ get 'children'
29
+ end
30
+ end
31
+ resources :commodity_categories, except: %i[destroy] do
32
+ member do
33
+ get 'children'
34
+ end
35
+ end
36
+ resources :currencies, except: %i[destroy]
24
37
  end
@@ -18,5 +18,7 @@ class CreateCatsCoreHrpItems < ActiveRecord::Migration[6.1]
18
18
 
19
19
  t.timestamps
20
20
  end
21
+
22
+ add_index :cats_core_hrp_items, [:hrp_id, :woreda_id], unique: true
21
23
  end
22
24
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.0.18'.freeze
3
+ VERSION = '1.0.22'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cats_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.18
4
+ version: 1.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-04 00:00:00.000000000 Z
11
+ date: 2021-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -218,6 +218,9 @@ files:
218
218
  - Rakefile
219
219
  - app/controllers/cats/core/access_controller.rb
220
220
  - app/controllers/cats/core/application_controller.rb
221
+ - app/controllers/cats/core/commodity_categories_controller.rb
222
+ - app/controllers/cats/core/currencies_controller.rb
223
+ - app/controllers/cats/core/locations_controller.rb
221
224
  - app/controllers/cats/core/menus_controller.rb
222
225
  - app/controllers/cats/core/notifications_controller.rb
223
226
  - app/controllers/cats/core/roles_controller.rb
@@ -258,6 +261,9 @@ files:
258
261
  - app/models/cats/core/unit_of_measure.rb
259
262
  - app/models/cats/core/user.rb
260
263
  - app/notifications/cats/core/simple_notification.rb
264
+ - app/serializers/cats/core/commodity_category_serializer.rb
265
+ - app/serializers/cats/core/currency_serializer.rb
266
+ - app/serializers/cats/core/location_serializer.rb
261
267
  - app/serializers/cats/core/role_menu_serializer.rb
262
268
  - app/services/cats/core/menu_service.rb
263
269
  - app/services/cats/core/notification_service.rb