cats_core 1.0.34 → 1.0.35

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: 5f642691ce490f46cc23534f368644b7bd6cc2069736cae534994aafb8018d40
4
- data.tar.gz: a3967aca1998cf19cbfa55af249e8023c664bb4066bb0c40224a209225584485
3
+ metadata.gz: 3b2945064c03295f5dcd5971f0e6ce570b50e4616166030f17fa5a6bd869d5cd
4
+ data.tar.gz: 3a6e091d8830f0d30ef67285547b64e2fa327e3efbbaad99449daf4cce0c67fa
5
5
  SHA512:
6
- metadata.gz: 8147dfe37fbe8ad5c1ae9e3945b71936e5c0c135a00633fba2c9e3f1a6aeac4ce482d3f4d81e965c0a3cb00d8ac9bec58033b2d8c418a750f9b68b63c61c4788
7
- data.tar.gz: d501edb9668b0372c6c6a91092619d467379083cc7c7ef3201856a43f1a53abcb5dcd0a97411d7e083ba8771f9ea66235213b283f5cdac64d870142bc1635840
6
+ metadata.gz: 58327459e7bbf5c43a08787c53d7ad8b9e08a7b8b6453e1ed06493e173a45cac45d82f0cdf3ddfbd5b6c106df31932e0ac637a0a3dd35a2d9493dc56ee1ad37a
7
+ data.tar.gz: 3065d7e0fceee9696d93851cb6c35be27fef7e3fd0779e783a490f8fe548eed6dc96348fe1be64be7f318fb845417ad0bbc23f1d0551cdcb4e56a1d669b3bc8a
@@ -0,0 +1,11 @@
1
+ module Cats
2
+ module Core
3
+ class SpacesController < ApplicationController
4
+ def available_space
5
+ service = SpaceService.new
6
+ space = service.available_space(params[:id], params[:level])
7
+ render json: { success: true, data: space }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ module Cats
2
+ module Core
3
+ class SpaceService
4
+ HUB = 'Hub'.freeze
5
+ WAREHOUSE = 'Warehouse'.freeze
6
+ STORE = 'Store'.freeze
7
+
8
+ def available_space(id, level)
9
+ case level
10
+ when HUB
11
+ warehouse_ids = Cats::Core::Location.find(id).children.map(&:id)
12
+ stores = Cats::Core::Store.joins(:warehouse)
13
+ .where(
14
+ cats_core_locations: {
15
+ location_type: Cats::Core::Location::WAREHOUSE,
16
+ id: warehouse_ids
17
+ }
18
+ ).group_by(&:warehouse_id)
19
+ wh_details = []
20
+ stores.each do |key, value|
21
+ total_space = value.inject(0) { |sum, val| sum + val.available_space }
22
+ details = value.map { |val| { store_id: val.id, total_space: val.available_space } }
23
+ wh_details << { warehouse_id: key, total_space: total_space, details: details }
24
+ end
25
+ hub_space = wh_details.inject(0) { |sum, val| sum + val[:total_space] }
26
+ space = { hub_id: id, total_space: hub_space, details: wh_details }
27
+ when WAREHOUSE
28
+ stores = Cats::Core::Store.where(warehouse_id: id)
29
+ details = stores.map { |store| { store_id: store.id, total_space: store.available_space } }
30
+ total_space = stores.inject(0) { |sum, val| sum + val.available_space }
31
+ space = { warehouse_id: id, total_space: total_space, details: details }
32
+ when STORE
33
+ store = Cats::Core::Store.find(id)
34
+ space = { store_id: store.id, total_space: store.available_space }
35
+ end
36
+ space
37
+ end
38
+ end
39
+ end
40
+ end
data/config/routes.rb CHANGED
@@ -28,6 +28,20 @@ Cats::Core::Engine.routes.draw do
28
28
  get 'children'
29
29
  end
30
30
  end
31
+
32
+ get '/hubs/:id/space',
33
+ to: 'spaces#available_space',
34
+ as: :hub_space,
35
+ defaults: { level: Cats::Core::SpaceService::HUB }
36
+ get '/warehousess/:id/space',
37
+ to: 'spaces#available_space',
38
+ as: :warehouse_space,
39
+ defaults: { level: Cats::Core::SpaceService::WAREHOUSE }
40
+ get '/store/:id/space',
41
+ to: 'spaces#available_space',
42
+ as: :store_space,
43
+ defaults: { level: Cats::Core::SpaceService::STORE }
44
+
31
45
  resources :commodity_categories, except: %i[destroy] do
32
46
  member do
33
47
  get 'children'
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.0.34'.freeze
3
+ VERSION = '1.0.35'.freeze
4
4
  end
5
5
  end
@@ -5,6 +5,11 @@ FactoryBot.define do
5
5
  ancestry { nil }
6
6
  end
7
7
 
8
+ factory :hub, parent: :location, class: 'Cats::Core::Location' do
9
+ location_type { Cats::Core::Location::HUB }
10
+ parent
11
+ end
12
+
8
13
  factory :warehouse, parent: :location, class: 'Cats::Core::Location' do
9
14
  location_type { Cats::Core::Location::WAREHOUSE }
10
15
  parent
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.34
4
+ version: 1.0.35
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-16 00:00:00.000000000 Z
11
+ date: 2021-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -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/spaces_controller.rb
227
228
  - app/controllers/cats/core/unit_of_measures_controller.rb
228
229
  - app/controllers/cats/core/users_controller.rb
229
230
  - app/jobs/cats/core/application_job.rb
@@ -271,6 +272,7 @@ files:
271
272
  - app/serializers/cats/core/unit_of_measure_serializer.rb
272
273
  - app/services/cats/core/menu_service.rb
273
274
  - app/services/cats/core/notification_service.rb
275
+ - app/services/cats/core/space_service.rb
274
276
  - app/services/cats/core/token_auth_service.rb
275
277
  - config/routes.rb
276
278
  - db/migrate/20210715114238_create_cats_core_application_modules.rb