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 +4 -4
- data/app/controllers/cats/core/commodity_categories_controller.rb +55 -0
- data/app/controllers/cats/core/currencies_controller.rb +46 -0
- data/app/controllers/cats/core/locations_controller.rb +53 -0
- data/app/models/cats/core/commodity_category.rb +2 -0
- data/app/models/cats/core/hrp.rb +1 -0
- data/app/models/cats/core/hrp_item.rb +4 -0
- data/app/serializers/cats/core/commodity_category_serializer.rb +3 -0
- data/app/serializers/cats/core/currency_serializer.rb +3 -0
- data/app/serializers/cats/core/location_serializer.rb +3 -0
- data/config/routes.rb +13 -0
- data/db/migrate/20210717032024_create_cats_core_hrp_items.rb +2 -0
- data/lib/cats/core/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7847bbf4c0a83ac387d2b9e7bc1f8f4b4ffe184d12f9611ee60c6f14d1fe3078
|
4
|
+
data.tar.gz: 319c387eeddbd6342b1b4fe14ea921e7c3e686243feded978cad60d96c9756ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/app/models/cats/core/hrp.rb
CHANGED
@@ -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
|
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
|
data/lib/cats/core/version.rb
CHANGED
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.
|
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-
|
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
|