dscf-marketplace 0.2.2 → 0.2.4

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: b03c9932cc3e31e46ea8ac2689f410b4f78b0cd950340a780b52e67abba8693c
4
- data.tar.gz: cef9643cb87044521d76d31f930affdeb899cc35a7ab67f9f129b346fd05dfdf
3
+ metadata.gz: 9c6753e6a99d5fcd1f3a5f3c81e9ea36bef71439a4eb3840ed3f7d8f4deb1f5f
4
+ data.tar.gz: edbf169441292502b45e8d67ab61bee187816d574a17e27c6b8a0a4bfb4b4bf5
5
5
  SHA512:
6
- metadata.gz: cd00154351d1e038a1f375c2016db715d75ddb8808f8a1e30cebb234eb1f25f4dbaa160bdd8446b897a8542a08f064bee63b89e981dc36b05bd589b2638c4533
7
- data.tar.gz: c0f0e1b6c4fb9f5dcc8f1bd442058fc9494f0366819e0561ef228141755e3870217ff8512052894857655c55657114c395dd69aa5e84d77f6163bbd42db01395
6
+ metadata.gz: 367c4df2d4a125126c527c123668eafd975fb52a7082a2f792e69bfbacf6978ecaac8742a745470a2eca82c9db13ee6da6dfa847c434a999e9343c6dbdaed7f5
7
+ data.tar.gz: 5199ecec95982d83a2fb842c95921ff2037cd479f3f0127dc0d930a3c471dea767e743898ff9dc1a1df0c18b3dcff75a15fbe8eab91b04e21665f3f46e7149d7
@@ -32,6 +32,18 @@ module Dscf
32
32
  render_error(error: e.message)
33
33
  end
34
34
 
35
+ def my_businesses
36
+ service = MyResourceService.new(current_user)
37
+ businesses = service.my_businesses(params)
38
+
39
+ options = {
40
+ include: default_serializer_includes[:index] || [],
41
+ meta: {resource_type: "my_businesses"}
42
+ }
43
+
44
+ render_success("businesses.success.index", data: businesses, serializer_options: options)
45
+ end
46
+
35
47
  private
36
48
 
37
49
  def model_params
@@ -30,6 +30,40 @@ module Dscf
30
30
  end
31
31
  end
32
32
 
33
+ def my_listings
34
+ service = MyResourceService.new(current_user)
35
+ listings = service.my_listings(params)
36
+
37
+ options = {
38
+ include: default_serializer_includes[:index] || [],
39
+ meta: {resource_type: "my_listings"}
40
+ }
41
+
42
+ render_success("listings.success.index", data: listings, serializer_options: options)
43
+ end
44
+
45
+ def listings_by_supplier
46
+ supplier_id = params[:supplier_id]
47
+
48
+ # Validate supplier exists
49
+ supplier = Dscf::Core::Business.find_by(id: supplier_id)
50
+ return render_error("Supplier not found") unless supplier
51
+
52
+ service = MyResourceService.new(current_user)
53
+ listings = service.listings_by_supplier(supplier_id, params)
54
+
55
+ options = {
56
+ include: default_serializer_includes[:index] || [],
57
+ meta: {
58
+ resource_type: "listings_by_supplier",
59
+ supplier_id: supplier_id,
60
+ supplier_name: supplier.name
61
+ }
62
+ }
63
+
64
+ render_success("listings.success.index", data: listings, serializer_options: options)
65
+ end
66
+
33
67
  private
34
68
 
35
69
  def model_params
@@ -32,6 +32,18 @@ module Dscf
32
32
  end
33
33
  end
34
34
 
35
+ def my_orders
36
+ service = MyResourceService.new(current_user)
37
+ orders = service.my_orders(params)
38
+
39
+ options = {
40
+ include: default_serializer_includes[:index] || [],
41
+ meta: {resource_type: "my_orders"}
42
+ }
43
+
44
+ render_success("orders.success.index", data: orders, serializer_options: options)
45
+ end
46
+
35
47
  private
36
48
 
37
49
  def model_params
@@ -30,6 +30,18 @@ module Dscf
30
30
  end
31
31
  end
32
32
 
33
+ def my_quotes
34
+ service = MyResourceService.new(current_user)
35
+ quotes = service.my_quotes(params)
36
+
37
+ options = {
38
+ include: default_serializer_includes[:index] || [],
39
+ meta: {resource_type: "my_quotes"}
40
+ }
41
+
42
+ render_success("quotations.success.index", data: quotes, serializer_options: options)
43
+ end
44
+
33
45
  private
34
46
 
35
47
  def model_params
@@ -21,6 +21,18 @@ module Dscf
21
21
  end
22
22
  end
23
23
 
24
+ def my_rfqs
25
+ service = MyResourceService.new(current_user)
26
+ rfqs = service.my_rfqs(params)
27
+
28
+ options = {
29
+ include: default_serializer_includes[:index] || [],
30
+ meta: {resource_type: "my_rfqs"}
31
+ }
32
+
33
+ render_success("request_for_quotations.success.index", data: rfqs, serializer_options: options)
34
+ end
35
+
24
36
  private
25
37
 
26
38
  def model_params
@@ -3,6 +3,18 @@ module Dscf
3
3
  class SupplierProductsController < ApplicationController
4
4
  include Dscf::Core::Common
5
5
 
6
+ def my_products
7
+ service = MyResourceService.new(current_user)
8
+ products = service.my_products(params)
9
+
10
+ options = {
11
+ include: default_serializer_includes[:index] || [],
12
+ meta: {resource_type: "my_products"}
13
+ }
14
+
15
+ render_success("supplier_products.success.index", data: products, serializer_options: options)
16
+ end
17
+
6
18
  private
7
19
 
8
20
  def model_params
@@ -0,0 +1,70 @@
1
+ module Dscf
2
+ module Marketplace
3
+ class MyResourceService
4
+ def initialize(current_user)
5
+ @current_user = current_user
6
+ end
7
+
8
+ def my_orders(params = {})
9
+ orders = Dscf::Marketplace::Order.where(user: @current_user)
10
+ .includes(:quotation, :listing, :user, :delivery_order, :order_items)
11
+
12
+ apply_filters(orders, params)
13
+ end
14
+
15
+ def my_rfqs(params = {})
16
+ rfqs = Dscf::Marketplace::RequestForQuotation.where(user: @current_user)
17
+ .includes(:user, :selected_quotation, :rfq_items, :quotations)
18
+
19
+ apply_filters(rfqs, params)
20
+ end
21
+
22
+ def my_quotes(params = {})
23
+ quotes = Dscf::Marketplace::Quotation.joins(:request_for_quotation)
24
+ .where(dscf_marketplace_request_for_quotations: {user_id: @current_user.id})
25
+ .includes(:request_for_quotation, :business, :quotation_items, :order)
26
+
27
+ apply_filters(quotes, params)
28
+ end
29
+
30
+ def my_businesses(params = {})
31
+ @current_user.businesses.includes(:business_type, :user, :documents)
32
+ end
33
+
34
+ def my_listings(params = {})
35
+ listings = Dscf::Marketplace::Listing.joins(:business)
36
+ .where(dscf_core_businesses: {user_id: @current_user.id})
37
+ .includes(:business, :supplier_product, :order_items)
38
+
39
+ apply_filters(listings, params)
40
+ end
41
+
42
+ def my_products(params = {})
43
+ products = Dscf::Marketplace::SupplierProduct.joins(:business)
44
+ .where(dscf_core_businesses: {user_id: @current_user.id})
45
+ .includes(:business, :product, :listings)
46
+
47
+ apply_filters(products, params)
48
+ end
49
+
50
+ def listings_by_supplier(supplier_id, params = {})
51
+ listings = Dscf::Marketplace::Listing.joins(:supplier_product)
52
+ .where(dscf_marketplace_supplier_products: {business_id: supplier_id})
53
+ .includes(:business, :supplier_product, :order_items)
54
+
55
+ apply_filters(listings, params)
56
+ end
57
+
58
+ private
59
+
60
+ def apply_filters(query, params)
61
+ # Apply Ransack filtering
62
+ if params[:q].present?
63
+ query = query.ransack(params[:q]).result
64
+ end
65
+
66
+ query
67
+ end
68
+ end
69
+ end
70
+ end
data/config/routes.rb CHANGED
@@ -19,12 +19,16 @@ Dscf::Marketplace::Engine.routes.draw do
19
19
  resources :businesses do
20
20
  collection do
21
21
  get "has_business"
22
+ get "my_businesses"
22
23
  end
23
24
  end
24
25
 
25
26
  # Trading Models
26
27
  resources :supplier_products do
27
28
  resources :listings, only: [ :index ]
29
+ collection do
30
+ get "my_products"
31
+ end
28
32
  end
29
33
 
30
34
  resources :listings do
@@ -33,6 +37,10 @@ Dscf::Marketplace::Engine.routes.draw do
33
37
  post "pause"
34
38
  post "sold_out"
35
39
  end
40
+ collection do
41
+ get "my_listings"
42
+ get "by_supplier/:supplier_id", to: "listings#listings_by_supplier"
43
+ end
36
44
  end
37
45
 
38
46
  # RFQ System
@@ -43,6 +51,9 @@ Dscf::Marketplace::Engine.routes.draw do
43
51
  post "send_rfq"
44
52
  post "close"
45
53
  end
54
+ collection do
55
+ get "my_rfqs"
56
+ end
46
57
  end
47
58
 
48
59
  resources :rfq_items, only: [ :index, :show, :update, :create, :destroy ]
@@ -54,6 +65,9 @@ Dscf::Marketplace::Engine.routes.draw do
54
65
  post "reject"
55
66
  post "send_quotation"
56
67
  end
68
+ collection do
69
+ get "my_quotes"
70
+ end
57
71
  end
58
72
 
59
73
  resources :quotation_items, only: [ :index, :show, :update, :create, :destroy ]
@@ -66,6 +80,9 @@ Dscf::Marketplace::Engine.routes.draw do
66
80
  post "cancel"
67
81
  post "complete"
68
82
  end
83
+ collection do
84
+ get "my_orders"
85
+ end
69
86
  end
70
87
 
71
88
  resources :order_items, only: [ :index, :show, :update, :create, :destroy ]
@@ -1,5 +1,5 @@
1
1
  module Dscf
2
2
  module Marketplace
3
- VERSION = "0.2.2".freeze
3
+ VERSION = "0.2.4".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.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Asrat
@@ -468,6 +468,7 @@ files:
468
468
  - app/serializers/dscf/marketplace/supplier_product_serializer.rb
469
469
  - app/serializers/dscf/marketplace/unit_conversion_serializer.rb
470
470
  - app/serializers/dscf/marketplace/unit_serializer.rb
471
+ - app/services/dscf/marketplace/my_resource_service.rb
471
472
  - config/locales/en.yml
472
473
  - config/routes.rb
473
474
  - db/migrate/20250827172043_create_dscf_marketplace_categories.rb