Skip to content

Commit

Permalink
🚧✨ Marketplace: Orders expose their Events
Browse files Browse the repository at this point in the history
- #1710

Next steps:

- Tidy the UI! It gross
- Add Specs! It needs them!
- ???
  • Loading branch information
zspencer committed Jul 27, 2023
1 parent 6451f8e commit f4a9de2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/furniture/marketplace/event_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Marketplace
class EventPolicy < Policy

class Scope < ApplicationScope
end
end
end
3 changes: 3 additions & 0 deletions app/furniture/marketplace/order/events/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%- events.each do |event| %>
<%= event.description%> - <% l(event.created_at, format: :long_ordinal) %>
<%- end %>
13 changes: 13 additions & 0 deletions app/furniture/marketplace/order/events_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Marketplace
class Order::EventsController < Controller
expose :order, scope: -> { OrderPolicy::Scope.new(shopper, marketplace.orders).resolve }, model: Order
helper_method def events
policy_scope(order.events)
end

def index
skip_authorization

end
end
end
4 changes: 4 additions & 0 deletions app/furniture/marketplace/orders/_order.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@
<hr class="col-span-6 mb-2" />
<div class="col-span-4">Total</div>
<div class="col-span-2 text-right"><%= humanized_money_with_symbol(order.price_total) %></div>

<%- if policy(order.events).index? %>
<%= link_to(t('marketplace.order.events.index.link_to'), order.location(child: :events)) %>
<%- end %>
<%- end %>
4 changes: 3 additions & 1 deletion app/furniture/marketplace/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ def self.append_routes(router)

router.resources :delivery_areas
router.resources :notification_methods
router.resources :orders, only: [:show, :index]
router.resources :orders, only: [:show, :index] do
router.resources :events, only: [:index], controller: "order/events"
end
router.resources :products
router.resource :stripe_account, only: [:show, :new, :create]
router.resources :stripe_events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

expect(order.events).to exist(description: "Payment Received")
expect(order.events).to exist(description: "Notifications to Vendor and Distributor Sent")
expect(order.events).to exist(description: "Notification to Buyer Sent")
expect(order.events).to exist(description: "Notification to Buyer Sent")

expect(Stripe::Transfer).to(have_received(:create).with({amount: order.price_total.cents - balance_transaction.fee, currency: "usd", destination: marketplace.stripe_account, transfer_group: order.id}, {api_key: marketplace.stripe_api_key}))
expect(order.events).to exist(description: "Payment Split")
Expand Down

0 comments on commit f4a9de2

Please sign in to comment.