-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Marketplace: Refactor to turn Checkout into a Command
#831 This "Demotes" `Checkout` from an Active Record and makes it serve more as a Command object than a Domain Model. It's still ActiveModel'y so it can be rendered using `render checkout` or routed to using `redirect_to checkout.location`, but otherwise it's not holding any data or what not.
- Loading branch information
Showing
26 changed files
with
142 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Marketplace | ||
class Model | ||
include ActiveModel::Model | ||
include WithinLocation | ||
|
||
def self.model_name | ||
@_model_name ||= ActiveModel::Name.new(self, ::Marketplace) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,24 @@ | ||
class Marketplace | ||
class Order < Checkout | ||
class Order < Record | ||
self.table_name = "marketplace_carts" | ||
self.location_parent = :marketplace | ||
|
||
belongs_to :marketplace, inverse_of: :orders | ||
delegate :space, :room, to: :marketplace | ||
|
||
belongs_to :shopper, inverse_of: :orders | ||
|
||
has_many :ordered_products, inverse_of: :order, foreign_key: :cart_id | ||
has_many :products, through: :ordered_products, inverse_of: :orders | ||
|
||
enum status: { | ||
paid: "paid" | ||
} | ||
|
||
def price_total | ||
ordered_products.sum(0) do |ordered_product| | ||
ordered_product.product.price * ordered_product.quantity | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
class Marketplace | ||
class OrderedProduct < CartProduct | ||
include WithinLocation | ||
self.location_parent = :checkout | ||
class OrderedProduct < Record | ||
self.table_name = "marketplace_cart_products" | ||
|
||
has_one :checkout, through: :cart | ||
self.location_parent = :order | ||
|
||
belongs_to :order, inverse_of: :ordered_products, foreign_key: :cart_id | ||
|
||
belongs_to :product, inverse_of: :ordered_products | ||
delegate :name, :description, :price, :price_cents, to: :product | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Marketplace | ||
class Record < ApplicationRecord | ||
self.abstract_class = true | ||
|
||
def self.model_name | ||
@_model_name ||= ActiveModel::Name.new(self, ::Marketplace) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Marketplace | ||
class Shopper < ApplicationRecord | ||
class Shopper < Record | ||
self.table_name = "marketplace_shoppers" | ||
|
||
belongs_to :person, optional: true | ||
has_many :carts, inverse_of: :shopper | ||
has_many :checkouts, inverse_of: :shopper | ||
has_many :orders, inverse_of: :shopper | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
class ApplicationRecord < ActiveRecord::Base | ||
self.abstract_class = true | ||
include WithinLocation | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class DropCheckoutsTable < ActiveRecord::Migration[7.0] | ||
def change | ||
drop_table "marketplace_checkouts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| | ||
t.uuid "cart_id" | ||
t.uuid "shopper_id" | ||
t.datetime "created_at", null: false | ||
t.datetime "updated_at", null: false | ||
t.string "status", default: "pre_checkout", null: false | ||
t.string "stripe_session_id" | ||
t.index ["cart_id"], name: "index_marketplace_checkouts_on_cart_id" | ||
t.index ["shopper_id"], name: "index_marketplace_checkouts_on_shopper_id" | ||
end | ||
|
||
add_column "marketplace_carts", :stripe_session_id, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.