Class: Dscf::Marketplace::ListingsController
Instance Method Summary
collapse
#bypass_permissions_for_demo?, #pundit_user
Instance Method Details
#activate ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'app/controllers/dscf/marketplace/listings_controller.rb', line 6
def activate
@obj = find_record
authorize @obj, :activate?
if @obj.update(status: :active)
render_success("listings.success.activated", data: @obj)
else
render_error("listings.errors.activate_failed")
end
end
|
#listings_by_supplier ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'app/controllers/dscf/marketplace/listings_controller.rb', line 90
def listings_by_supplier
authorize @clazz.new, :listings_by_supplier?
supplier_id = params[:supplier_id]
supplier = Dscf::Core::Business.find_by(id: supplier_id)
return render_error("listings.errors.supplier_not_found") unless supplier
service = MyResourceService.new(current_user)
listings = service.listings_by_supplier(supplier_id, params)
options = {
include: default_serializer_includes[:index] || [],
meta: {
resource_type: "listings_by_supplier",
supplier_id: supplier_id,
supplier_name: supplier.name
}
}
render_success("listings.success.index", data: listings, serializer_options: options)
end
|
#my_listings ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'app/controllers/dscf/marketplace/listings_controller.rb', line 77
def my_listings
authorize @clazz.new, :my_listings?
service = MyResourceService.new(current_user)
listings = service.my_listings(params)
options = {
include: default_serializer_includes[:index] || [],
meta: { resource_type: "my_listings" }
}
render_success("listings.success.index", data: listings, serializer_options: options)
end
|
#pause ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'app/controllers/dscf/marketplace/listings_controller.rb', line 16
def pause
@obj = find_record
authorize @obj, :pause?
if @obj.update(status: :paused)
render_success("listings.success.paused", data: @obj)
else
render_error("listings.errors.pause_failed")
end
end
|
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'app/controllers/dscf/marketplace/listings_controller.rb', line 36
def promote
@obj = find_record
authorize @obj, :promote?
if @obj.update(
orchestrator_promoted: true,
orchestrator_promoted_at: Time.current,
promoted_by: current_user
)
render_success("listings.success.promoted", data: @obj)
else
render_error("listings.errors.promote_failed")
end
end
|
#sold_out ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/dscf/marketplace/listings_controller.rb', line 26
def sold_out
@obj = find_record
authorize @obj, :sold_out?
if @obj.update(status: :sold_out)
render_success("listings.success.sold_out", data: @obj)
else
render_error("listings.errors.sold_out_failed")
end
end
|
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'app/controllers/dscf/marketplace/listings_controller.rb', line 50
def unpromote
@obj = find_record
authorize @obj, :unpromote?
if @obj.update(
orchestrator_promoted: false,
orchestrator_promoted_at: nil,
promoted_by: nil
)
render_success("listings.success.unpromoted", data: @obj)
else
render_error("listings.errors.unpromote_failed")
end
end
|
#visible ⇒ Object
Public feed: only visible listings (computed by 3 conditions)
65
66
67
68
69
70
71
72
73
74
75
|
# File 'app/controllers/dscf/marketplace/listings_controller.rb', line 65
def visible
authorize @clazz.new, :visible?
listings = @clazz.visible.includes(eager_loaded_associations)
options = {
include: default_serializer_includes[:index] || [],
meta: { resource_type: "visible_listings" }
}
render_success(data: listings, serializer_options: options)
end
|