dscf-marketplace 0.2.98 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa719a9c13e73b2dd1a928fd2c2e182c4196d6c3831c023a13b612395102cf69
4
- data.tar.gz: 9d66ef00f600abc13ad2df68c2d856077859fb24336f188148d44c0b02ba52fd
3
+ metadata.gz: c6a085b77e0df306ff423707aef06677341c982e2583981b5cb29af086e49a02
4
+ data.tar.gz: 1fe59b7b90e392c0719a53e58da437a45e49627655ace2c9ee83e6cb32501c0a
5
5
  SHA512:
6
- metadata.gz: 59c804e4d74b708ef0d689c5c8c74f8f1681439ea5f6e3661c62868dfe645071857e248305b8c2cbd7ba7c4e29073d5c7d12ac5a6e971db5a4928247e1689640
7
- data.tar.gz: ce84b03ce6d48bc24b11df097504b92763d6cd6d953c3d79ce764b810ea1b313fdb50b7ef398f8fbfcf9575e58d9e85c59aad3780a91950bd66febe1778246a6
6
+ metadata.gz: a8bd980e7ba25145aebdedf2a3d759aefcd1df8a85af56c7740f22fb4a3ab9c90e045049ae596efdd34eab2d571e32fa16edcd0a4ec294437da93bf313a92a50
7
+ data.tar.gz: 7f6cd84b1f789ed6f770ad71f4b47c3d6599307622b46385119898f077c569813e1e0f5f3dacbc1c71609fe05fdacc165b0727021f41ecbf0de04974554da6f5
@@ -4,8 +4,68 @@ module Dscf
4
4
  include Dscf::Core::Common
5
5
 
6
6
  def index
7
- @objs = DeliveryOrder.all
8
- render_success("delivery_orders.index.success", data: @objs, serializer_options: {include: default_serializer_includes[:index]})
7
+ # Custom implementation to avoid JSON field issues
8
+ delivery_orders = @clazz.all
9
+
10
+ # Apply Ransack filtering if q params present
11
+ if params[:q].present?
12
+ # Filter out any parameters that might reference JSON fields
13
+ filtered_params = params[:q].reject { |key, _| key.to_s.include?("optimized_route") }
14
+ if filtered_params.present?
15
+ delivery_orders = delivery_orders.ransack(filtered_params).result
16
+ end
17
+ end
18
+
19
+ # Apply eager loading if defined
20
+ delivery_orders = delivery_orders.includes(eager_loaded_associations) if eager_loaded_associations.present?
21
+
22
+ # Apply pagination if requested
23
+ if params[:page]
24
+ total_count = delivery_orders.count
25
+ delivery_orders = delivery_orders.then(&paginate)
26
+ total_pages = (total_count.to_f / per_page).ceil
27
+ count = delivery_orders.is_a?(Array) ? delivery_orders.length : delivery_orders.count
28
+
29
+ pagination_meta = {
30
+ current_page: page_no,
31
+ per_page: per_page,
32
+ count: count,
33
+ total_count: total_count,
34
+ total_pages: total_pages,
35
+ links: pagination_links(total_pages)
36
+ }
37
+ end
38
+
39
+ # Add serializer includes
40
+ includes = serializer_includes_for_action(:index)
41
+ options = {}
42
+ options[:include] = includes if includes.present?
43
+ options[:pagination] = pagination_meta if params[:page]
44
+
45
+ render_success(data: delivery_orders, serializer_options: options)
46
+ end
47
+
48
+ def filter
49
+ delivery_orders = @clazz.all
50
+
51
+ # Apply Ransack filtering if q params present
52
+ if params[:q].present?
53
+ # Filter out any parameters that might reference JSON fields
54
+ filtered_params = params[:q].reject { |key, _| key.to_s.include?("optimized_route") }
55
+ if filtered_params.present?
56
+ delivery_orders = delivery_orders.ransack(filtered_params).result
57
+ end
58
+ end
59
+
60
+ # Apply eager loading
61
+ delivery_orders = delivery_orders.includes(eager_loaded_associations) if eager_loaded_associations.present?
62
+
63
+ # Add serializer includes
64
+ includes = serializer_includes_for_action(:index)
65
+ options = {}
66
+ options[:include] = includes if includes.present?
67
+
68
+ render_success(data: delivery_orders, serializer_options: options)
9
69
  end
10
70
 
11
71
  def pickup
@@ -3,6 +3,25 @@ module Dscf
3
3
  class OrdersController < ApplicationController
4
4
  include Dscf::Core::Common
5
5
 
6
+ def filter
7
+ orders = @clazz.all
8
+
9
+ # Apply Ransack filtering if q params present
10
+ if params[:q].present?
11
+ orders = orders.ransack(params[:q]).result
12
+ end
13
+
14
+ # Apply eager loading
15
+ orders = orders.includes(eager_loaded_associations) if eager_loaded_associations.present?
16
+
17
+ # Add serializer includes
18
+ includes = serializer_includes_for_action(:index)
19
+ options = {}
20
+ options[:include] = includes if includes.present?
21
+
22
+ render_success(data: orders, serializer_options: options)
23
+ end
24
+
6
25
  def confirm
7
26
  @obj = find_record
8
27
  if @obj.confirm!
@@ -3,6 +3,25 @@ module Dscf
3
3
  class ProductsController < ApplicationController
4
4
  include Dscf::Core::Common
5
5
 
6
+ def filter
7
+ products = @clazz.all
8
+
9
+ # Apply Ransack filtering if q params present
10
+ if params[:q].present?
11
+ products = products.ransack(params[:q]).result
12
+ end
13
+
14
+ # Apply eager loading
15
+ products = products.includes(eager_loaded_associations) if eager_loaded_associations.present?
16
+
17
+ # Add serializer includes
18
+ includes = serializer_includes_for_action(:index)
19
+ options = {}
20
+ options[:include] = includes if includes.present?
21
+
22
+ render_success(data: products, serializer_options: options)
23
+ end
24
+
6
25
  private
7
26
 
8
27
  def model_params
@@ -3,6 +3,25 @@ module Dscf
3
3
  class QuotationsController < ApplicationController
4
4
  include Dscf::Core::Common
5
5
 
6
+ def filter
7
+ quotations = @clazz.all
8
+
9
+ # Apply Ransack filtering if q params present
10
+ if params[:q].present?
11
+ quotations = quotations.ransack(params[:q]).result
12
+ end
13
+
14
+ # Apply eager loading
15
+ quotations = quotations.includes(eager_loaded_associations) if eager_loaded_associations.present?
16
+
17
+ # Add serializer includes
18
+ includes = serializer_includes_for_action(:index)
19
+ options = {}
20
+ options[:include] = includes if includes.present?
21
+
22
+ render_success(data: quotations, serializer_options: options)
23
+ end
24
+
6
25
  def accept
7
26
  @obj = find_record
8
27
  if @obj.accept!
@@ -3,6 +3,25 @@ module Dscf
3
3
  class RequestForQuotationsController < ApplicationController
4
4
  include Dscf::Core::Common
5
5
 
6
+ def filter
7
+ rfqs = @clazz.all
8
+
9
+ # Apply Ransack filtering if q params present
10
+ if params[:q].present?
11
+ rfqs = rfqs.ransack(params[:q]).result
12
+ end
13
+
14
+ # Apply eager loading
15
+ rfqs = rfqs.includes(eager_loaded_associations) if eager_loaded_associations.present?
16
+
17
+ # Add serializer includes
18
+ includes = serializer_includes_for_action(:index)
19
+ options = {}
20
+ options[:include] = includes if includes.present?
21
+
22
+ render_success(data: rfqs, serializer_options: options)
23
+ end
24
+
6
25
  def create
7
26
  obj = @clazz.new(model_params)
8
27
  if obj.save
@@ -23,10 +23,31 @@ module Dscf::Marketplace
23
23
  %w[id driver_id pickup_address_id delivery_vehicle_id status vehicle_type estimated_delivery_price actual_delivery_price estimated_delivery_time actual_delivery_time delivery_notes created_at updated_at]
24
24
  end
25
25
 
26
- # Override ransack to handle JSON fields
26
+ # Override ransack to handle JSON fields and filtering
27
27
  def self.ransack(params = {}, options = {})
28
28
  params ||= {}
29
- super(params.except("optimized_route"), options)
29
+
30
+ # Remove JSON fields that can't be filtered
31
+ filtered_params = params.except("optimized_route")
32
+
33
+ # Also remove any q parameters that reference JSON fields
34
+ if filtered_params["q"].present?
35
+ q_params = filtered_params["q"]
36
+ # Remove any predicates that reference the optimized_route field
37
+ q_params = q_params.reject { |key, _| key.to_s.include?("optimized_route") }
38
+ filtered_params["q"] = q_params
39
+ end
40
+
41
+ # Call super with filtered params
42
+ result = super(filtered_params, options)
43
+
44
+ # If result is a relation, ensure we don't select JSON fields that might cause issues
45
+ if result.is_a?(ActiveRecord::Relation)
46
+ # Force selection of only the columns we want to avoid JSON field issues
47
+ result = result.select(column_names - [ "optimized_route" ])
48
+ end
49
+
50
+ result
30
51
  end
31
52
 
32
53
  def self.ransackable_associations(_auth_object = nil)
data/config/routes.rb CHANGED
@@ -8,6 +8,9 @@ Dscf::Marketplace::Engine.routes.draw do
8
8
  resources :products do
9
9
  resources :listings, only: [ :index ]
10
10
  get "supplier_products", on: :member
11
+ collection do
12
+ get "filter"
13
+ end
11
14
  end
12
15
 
13
16
  resources :units do
@@ -54,6 +57,7 @@ Dscf::Marketplace::Engine.routes.draw do
54
57
  end
55
58
  collection do
56
59
  get "my_rfqs"
60
+ get "filter"
57
61
  end
58
62
  end
59
63
 
@@ -68,6 +72,7 @@ Dscf::Marketplace::Engine.routes.draw do
68
72
  end
69
73
  collection do
70
74
  get "my_quotes"
75
+ get "filter"
71
76
  end
72
77
  end
73
78
 
@@ -83,6 +88,7 @@ Dscf::Marketplace::Engine.routes.draw do
83
88
  end
84
89
  collection do
85
90
  get "my_orders"
91
+ get "filter"
86
92
  end
87
93
  end
88
94
 
@@ -97,6 +103,9 @@ Dscf::Marketplace::Engine.routes.draw do
97
103
  post "complete_delivery"
98
104
  post "mark_failed"
99
105
  end
106
+ collection do
107
+ get "filter"
108
+ end
100
109
  end
101
110
 
102
111
  resources :delivery_order_items, only: [ :index, :show, :update, :create ] do
@@ -1,5 +1,5 @@
1
1
  module Dscf
2
2
  module Marketplace
3
- VERSION = "0.2.98".freeze
3
+ VERSION = "0.3.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dscf-marketplace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.98
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Asrat