cats_core 1.0.19 → 1.0.23

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: 3c81056f8e17e25f22270c90d0fbca07b2cfaea15edb8fb2b59f443af7267ef7
4
- data.tar.gz: 30075ab64034bf1215a98e3d3c71042904799df668ce378a93105a087d384401
3
+ metadata.gz: fdf3896b40c9ff598fa14a38d5f7a32b6dab30c3e72f7f3b16b480579df3a073
4
+ data.tar.gz: d60e1032a3b708fa85a8372e58e899f45ec41fee42ce909c4b3117278c44ee59
5
5
  SHA512:
6
- metadata.gz: b7d093ba4f079b4adc8681168b9b61b4a369c7ae63e665541c740bce729b5ab2711e60cee89c6cb4d5517da8ef2e79f151ef96c9e3f0a8a4d07fdb8b52d66974
7
- data.tar.gz: abf7696b83657bc03734db204bc78df702d07d74a65850c7d542c86c190d5ea3b58000c3623c22163d05ce26991a23cc5a09f7accfe3c9bc6f266a18ce178825
6
+ metadata.gz: 8364011f2d5dc631bcfa08396111bec092f85d37baba59fc327c993bf73b98a3d555432670be77d0933834be539c4c113df156df0d51378a44a881583d954400
7
+ data.tar.gz: '034875a3d26227194eca732e64a360635696d18141c285ff769f66bccdfc3e09508da840f01d0866a9b76939c8f54ca78be4dfedeb6f0ce5726cb3f2dbb06785'
@@ -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
@@ -13,6 +13,9 @@ module Cats
13
13
  validates :reference_no, uniqueness: true
14
14
  validates :donation_type, inclusion: { in: DONATION_TYPES }
15
15
  validates :currency, :amount, presence: true, if: -> { donation_type == CASH }
16
+
17
+ delegate(:name, to: :donor, prefix: true)
18
+ delegate(:reference_no, to: :hrp, prefix: true)
16
19
  end
17
20
  end
18
21
  end
@@ -6,6 +6,8 @@ module Cats
6
6
 
7
7
  validates :reference_no, presence: true, uniqueness: true
8
8
  validates :gift_date, presence: true
9
+
10
+ delegate(:name, to: :commodity_category, prefix: true)
9
11
  end
10
12
  end
11
13
  end
@@ -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.19'.freeze
3
+ VERSION = '1.0.23'.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.19
4
+ version: 1.0.23
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