cats_core 1.0.20 → 1.0.21
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 +4 -4
- data/app/controllers/cats/core/commodity_categories_controller.rb +55 -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_item.rb +3 -0
- data/app/serializers/cats/core/commodity_category_serializer.rb +3 -0
- data/app/serializers/cats/core/location_serializer.rb +3 -0
- data/config/routes.rb +12 -0
- data/lib/cats/core/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc104d1c83591c9db1a70f89044e124322826738e56a7803c5ae0487421e3f17
|
4
|
+
data.tar.gz: 4f80cded8f41799a6d77c87f8c920db0eb3ca86f8bad20a230a246ef35a667ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 067a3510964611f5ab157eb661613082148bbd27b55ce0bd8cf89bea7a6d582099f0f17e44e7b31434acafcff2c68660da58e300c21d381a675a8d38be6c0dec
|
7
|
+
data.tar.gz: b5068dda8fa207fbaa39282fa106c63a84e291777900c660e177b12ca5709059ef2d9c479ed239ea3a08b924b102846d6e5d944bdbe0a69c3d17a53a20c0f04b
|
@@ -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,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
|
@@ -8,6 +8,9 @@ module Cats
|
|
8
8
|
validates :beneficiaries, presence: true, numericality: { greater_than: 0 }
|
9
9
|
validates :commodity_amount, presence: true, numericality: { greater_than: 0 }
|
10
10
|
validates :hrp_id, uniqueness: { scope: :woreda_id }
|
11
|
+
|
12
|
+
delegate(:name, to: :woreda, prefix: true)
|
13
|
+
delegate(:name, to: :operator, prefix: true)
|
11
14
|
end
|
12
15
|
end
|
13
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,14 @@ 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
|
24
36
|
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.21
|
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,8 @@ 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/locations_controller.rb
|
221
223
|
- app/controllers/cats/core/menus_controller.rb
|
222
224
|
- app/controllers/cats/core/notifications_controller.rb
|
223
225
|
- app/controllers/cats/core/roles_controller.rb
|
@@ -258,6 +260,8 @@ files:
|
|
258
260
|
- app/models/cats/core/unit_of_measure.rb
|
259
261
|
- app/models/cats/core/user.rb
|
260
262
|
- app/notifications/cats/core/simple_notification.rb
|
263
|
+
- app/serializers/cats/core/commodity_category_serializer.rb
|
264
|
+
- app/serializers/cats/core/location_serializer.rb
|
261
265
|
- app/serializers/cats/core/role_menu_serializer.rb
|
262
266
|
- app/services/cats/core/menu_service.rb
|
263
267
|
- app/services/cats/core/notification_service.rb
|