Type | State | Method |
---|---|---|
Entity/Aggregate/Value | Yes | Yes |
Service | No | Yes |
order.update_amount(product_id, amount)
items.select { |i| i.pid == product_id }.update_amount(amount)
has_many :items autosave: true
update_amount() => self.amount = amount
OrderItemAmountUpdater
->
prodsuct.stock_available?(amount)
order.update_amount(product.id, amount)
# Product (Context)
# * Context - Store Manager
# * Context - Customer
class Money
attr_reader :value, :currency
def initialize(value, currency)
@value = value
@currency = currency
end
def +(other)
# check currency
new(value + other.value, currency)
end
end
module Store
class Product
belongs_to :store
compose_of :price, class_name: 'Money', mapping: [%i(price value), %i(currency currency)]
end
end
class Order
# ---> product.xxxx
# product_id (Value != Association) --> Link
# product_name
# product_unit_price
end
-> View
-> Controller – User Flow
-> A Case -> Reseller -> No stock check
-> B Case -> Customer -> Check stock
-> Model – Business Logic
class CheckoutController
def create
# Step 1
cart.items.each do |item|
# ... check
item.product_id
end
# Step 2
Order.create_from(cart)
# 拆 Service Object
end
end
# ...
class CheckoutController
rescue_from ...., :on_product_not_available
# ....
def create
# Step 1
ProductAvailableService.new.call(cart)
# raise Error
# Step 2
@order = BuildOrderService.new.call(cart)
@order.save!
# render
end
end
class Reseller::CheckoutController
rescue_from ...., :on_product_not_available
# ....
def create
# Step 1
# ProductAvailableService.new.call(cart)
# raise Error
# Step 2
@order = BuildOrderService.new.call(cart)
@order.save!
# render
end
end
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing