unidom-shopping 2.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/unidom/shopping/application_controller.rb +8 -2
- data/app/helpers/unidom/shopping/application_helper.rb +7 -1
- data/app/jobs/unidom/shopping/application_job.rb +7 -1
- data/app/mailers/unidom/shopping/application_mailer.rb +9 -3
- data/app/models/unidom/shopping/application_record.rb +8 -2
- data/app/models/unidom/shopping/concerns/as_cart_shopper.rb +26 -18
- data/app/models/unidom/shopping/concerns/as_item_shopper.rb +34 -26
- data/app/models/unidom/shopping/concerns/as_shop.rb +21 -13
- data/app/models/unidom/shopping/concerns/as_shopped.rb +40 -32
- data/app/models/unidom/shopping/shopping_cart.rb +28 -22
- data/app/models/unidom/shopping/shopping_item.rb +18 -12
- data/app/views/layouts/unidom/shopping/application.html.erb +1 -1
- data/db/migrate/20020501000000_create_unidom_shopping_carts.rb +2 -2
- data/db/migrate/20020502000000_create_unidom_shopping_items.rb +3 -3
- data/lib/unidom/shopping/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edaaa6056e98d80899e568f4e560c3ddb5b523ee9199485a9ae8a6205aad0cab
|
4
|
+
data.tar.gz: 55661d4d5ffb161836913e4ca20e32a109194f951262231c8b815d137f7a4f3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1450d0f6f35b1ddee35d628dfe87e41bf93f42e6e7602f8f065543f398f1b2d80d8086e2eb5e224b49ed9e7ec17cc6680d70d91ba718439cf188a97efdfe1108
|
7
|
+
data.tar.gz: 919daf5e47c28c18f599dc7f20e173aef698f9771c6c87786b06573ada9e1889fd2f892b9597780dbda9f7593b647669db5443912b2ec741d88f86994343ad09
|
@@ -1,6 +1,12 @@
|
|
1
1
|
##
|
2
2
|
# Application controller 是模块内所有控制器的基类。
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
6
|
+
|
7
|
+
class ApplicationController < ActionController::Base
|
8
|
+
protect_from_forgery with: :exception
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
6
12
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
##
|
2
2
|
# Application mailer 是模块内所有电子邮件发送类的基类。
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
6
|
+
|
7
|
+
class ApplicationMailer < ActionMailer::Base
|
8
|
+
default from: 'from@example.com'
|
9
|
+
layout 'mailer'
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
7
13
|
end
|
@@ -1,6 +1,12 @@
|
|
1
1
|
##
|
2
2
|
# Application record 是模块内所有模型的抽象基类。
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
6
|
+
|
7
|
+
class ApplicationRecord < ActiveRecord::Base
|
8
|
+
self.abstract_class = true
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
6
12
|
end
|
@@ -1,33 +1,41 @@
|
|
1
1
|
##
|
2
2
|
# As Cart Shopper 是购物车所有者的领域逻辑关注点。
|
3
3
|
|
4
|
-
module Unidom
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
6
|
+
module Concerns
|
5
7
|
|
6
|
-
|
7
|
-
include Unidom::Common::Concerns::ArgumentValidation
|
8
|
+
module AsCartShopper
|
8
9
|
|
9
|
-
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
include Unidom::Common::Concerns::ArgumentValidation
|
10
12
|
|
11
|
-
|
13
|
+
included do |includer|
|
12
14
|
|
13
|
-
|
14
|
-
# 以购物者的身份,从指定的商店 from 获取购物车。时间为 at ,缺省为当前时间。如:
|
15
|
-
# current_person.get_cart! from: shop
|
16
|
-
def get_cart!(from: nil, at: Time.now)
|
15
|
+
has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shopper
|
17
16
|
|
18
|
-
|
17
|
+
##
|
18
|
+
# 以购物者的身份,从指定的商店 from 获取购物车。时间为 at ,缺省为当前时间。如:
|
19
|
+
# current_person.get_cart! from: shop
|
20
|
+
def get_cart!(from: nil, at: Time.now)
|
19
21
|
|
20
|
-
|
22
|
+
assert_present! :from, from
|
21
23
|
|
22
|
-
|
24
|
+
shopping_carts.shop_is(from).valid_at(now: at).alive.first_or_create! opened_at: at
|
23
25
|
|
24
|
-
|
25
|
-
shopping_carts.shop_is(from).valid_at(now: at).alive.exists?
|
26
|
-
end
|
26
|
+
end
|
27
27
|
|
28
|
-
|
28
|
+
def get_cart?(from: nil, at: Time.now)
|
29
|
+
shopping_carts.shop_is(from).valid_at(now: at).alive.exists?
|
30
|
+
end
|
29
31
|
|
30
|
-
|
31
|
-
end
|
32
|
+
end
|
32
33
|
|
34
|
+
module ClassMethods
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
33
41
|
end
|
@@ -1,40 +1,48 @@
|
|
1
1
|
##
|
2
2
|
# As Item Shopper 是购物项所有者的领域逻辑关注点。
|
3
3
|
|
4
|
-
module Unidom
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
6
|
+
module Concerns
|
5
7
|
|
6
|
-
|
7
|
-
include Unidom::Common::Concerns::ArgumentValidation
|
8
|
+
module AsItemShopper
|
8
9
|
|
9
|
-
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
include Unidom::Common::Concerns::ArgumentValidation
|
10
12
|
|
11
|
-
|
13
|
+
included do |includer|
|
12
14
|
|
13
|
-
|
14
|
-
# 以购物者的身份,将商品 it ,放入购物车 into 。购物时间是 at ,缺省为当前时间。单价是 unit_price ,缺省为 0 。数量是 quantity ,缺省为 1 。如:
|
15
|
-
# current_person.add! coca_cola, into: shopping_cart, unit_price: 3.50, quantity: 3
|
16
|
-
def add!(it, into: nil, at: Time.now, unit_price: 0, quantity: 1)
|
15
|
+
has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopper
|
17
16
|
|
18
|
-
|
17
|
+
##
|
18
|
+
# 以购物者的身份,将商品 it ,放入购物车 into 。购物时间是 at ,缺省为当前时间。单价是 unit_price ,缺省为 0 。数量是 quantity ,缺省为 1 。如:
|
19
|
+
# current_person.add! coca_cola, into: shopping_cart, unit_price: 3.50, quantity: 3
|
20
|
+
def add!(it, into: nil, at: Time.now, unit_price: 0, quantity: 1)
|
19
21
|
|
20
|
-
|
21
|
-
item = query.first
|
22
|
-
if item.present?
|
23
|
-
item.unit_price = unit_price
|
24
|
-
item.increment! :quantity, quantity
|
25
|
-
else
|
26
|
-
item = shopping_items.create! shopping_cart: into, shopped: it, unit_price: unit_price, quantity: quantity, opened_at: at
|
27
|
-
end
|
28
|
-
item
|
29
|
-
end
|
22
|
+
assert_present! :it, it
|
30
23
|
|
31
|
-
|
32
|
-
|
33
|
-
|
24
|
+
query = shopping_items.shopping_cart_is(into).shopped_is(it).valid_at(now: at).alive
|
25
|
+
item = query.first
|
26
|
+
if item.present?
|
27
|
+
item.unit_price = unit_price
|
28
|
+
item.increment! :quantity, quantity
|
29
|
+
else
|
30
|
+
item = shopping_items.create! shopping_cart: into, shopped: it, unit_price: unit_price, quantity: quantity, opened_at: at
|
31
|
+
end
|
32
|
+
item
|
33
|
+
end
|
34
34
|
|
35
|
-
|
35
|
+
def add?(it, into: nil, at: Time.now)
|
36
|
+
shopping_items.shopping_cart_is(into).shopped_is(it).valid_at(now: at).alive.exists?
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
end
|
39
|
+
end
|
39
40
|
|
41
|
+
module ClassMethods
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
40
48
|
end
|
@@ -1,24 +1,32 @@
|
|
1
1
|
##
|
2
2
|
# As Shop 是购物场所的领域逻辑关注点。
|
3
3
|
|
4
|
-
module Unidom
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
6
|
+
module Concerns
|
5
7
|
|
6
|
-
|
8
|
+
module AsShop
|
7
9
|
|
8
|
-
|
10
|
+
extend ActiveSupport::Concern
|
9
11
|
|
10
|
-
|
12
|
+
included do |includer|
|
11
13
|
|
12
|
-
|
13
|
-
# 从当前商店中,获取购物车。购物者为 by 。获取时间为 at ,缺省为当前时间。如:
|
14
|
-
# shop.get_cart! by: current_person
|
15
|
-
def get_cart!(by: nil, at: Time.now)
|
16
|
-
shopping_carts.shopped_by(by).valid_at(now: at).alive.first_or_create! opened_at: at
|
17
|
-
end
|
14
|
+
has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shop
|
18
15
|
|
19
|
-
|
16
|
+
##
|
17
|
+
# 从当前商店中,获取购物车。购物者为 by 。获取时间为 at ,缺省为当前时间。如:
|
18
|
+
# shop.get_cart! by: current_person
|
19
|
+
def get_cart!(by: nil, at: Time.now)
|
20
|
+
shopping_carts.shopped_by(by).valid_at(now: at).alive.first_or_create! opened_at: at
|
21
|
+
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
+
end
|
24
|
+
|
25
|
+
module ClassMethods
|
26
|
+
end
|
23
27
|
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
24
32
|
end
|
@@ -1,40 +1,48 @@
|
|
1
1
|
##
|
2
2
|
# As Shopped 是被购买的商品的领域逻辑关注点。
|
3
3
|
|
4
|
-
module Unidom
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
6
|
+
module Concerns
|
7
|
+
|
8
|
+
module AsShopped
|
9
|
+
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
included do |includer|
|
13
|
+
|
14
|
+
has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopped
|
15
|
+
|
16
|
+
##
|
17
|
+
# 将当前商品放入购物车 into ,购物者是 by 。购物时间是 at ,缺省为当前时间。单价是 unit_price ,缺省为 0 。数量是 quantity ,缺省为 1 。如:
|
18
|
+
# coca_cola.is_added! into: shopping_cart, by: current_person, unit_price: 3.50, quantity: 2
|
19
|
+
def is_added!(into: nil, by: nil, at: Time.now, unit_price: 0, quantity: 1)
|
20
|
+
query = shopping_items.shopping_cart_is(into).valid_at(now: at).alive
|
21
|
+
item = query.first
|
22
|
+
if item.present?
|
23
|
+
item.unit_price = unit_price
|
24
|
+
item.shopper = by
|
25
|
+
item.increment! :quantity, quantity
|
26
|
+
else
|
27
|
+
item = shopping_items.create! shopping_cart: into, shopper: by, unit_price: unit_price, quantity: quantity, opened_at: at
|
28
|
+
end
|
29
|
+
item
|
30
|
+
end
|
31
|
+
|
32
|
+
def is_added?(into: nil, by: nil, at: Time.now)
|
33
|
+
query = shopping_items.shopping_cart_is(into)
|
34
|
+
query = query.shopped_by(by) if by.present?
|
35
|
+
query = query.valid_at(now: at).alive
|
36
|
+
query.exists?
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
module ClassMethods
|
42
|
+
end
|
43
|
+
|
24
44
|
end
|
25
|
-
item
|
26
|
-
end
|
27
45
|
|
28
|
-
def is_added?(into: nil, by: nil, at: Time.now)
|
29
|
-
query = shopping_items.shopping_cart_is(into)
|
30
|
-
query = query.shopped_by(by) if by.present?
|
31
|
-
query = query.valid_at(now: at).alive
|
32
|
-
query.exists?
|
33
46
|
end
|
34
|
-
|
35
47
|
end
|
36
|
-
|
37
|
-
module ClassMethods
|
38
|
-
end
|
39
|
-
|
40
48
|
end
|
@@ -1,34 +1,40 @@
|
|
1
1
|
##
|
2
2
|
# Shopping Cart 是购物车。
|
3
3
|
|
4
|
-
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
5
6
|
|
6
|
-
|
7
|
+
class ShoppingCart < ApplicationRecord
|
7
8
|
|
8
|
-
|
9
|
+
self.table_name = 'unidom_shopping_carts'
|
9
10
|
|
10
|
-
|
11
|
-
belongs_to :shop, polymorphic: true
|
11
|
+
include Unidom::Common::Concerns::ModelExtension
|
12
12
|
|
13
|
-
|
13
|
+
belongs_to :shopper, polymorphic: true
|
14
|
+
belongs_to :shop, polymorphic: true
|
14
15
|
|
15
|
-
|
16
|
-
scope :shop_is, ->(shop) { where shop: shop }
|
16
|
+
has_many :items, class_name: 'Unidom::Shopping::ShoppingItem'
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
# shopping_cart.add! coca_cola, by: current_person, unit_price: 3.50, quantity: 2
|
21
|
-
def add!(shopped, by: nil, unit_price: 0, quantity: 1, at: Time.now)
|
18
|
+
scope :shopped_by, ->(shopper) { where shopper: shopper }
|
19
|
+
scope :shop_is, ->(shop) { where shop: shop }
|
22
20
|
|
23
|
-
|
21
|
+
##
|
22
|
+
# 将商品 shopped 放入购物车。购物者为 by 。单价为 unit_price ,缺省值为 0 。数量为 quantity ,缺省值是 1 。时间为 at ,缺省为当前时间。如:
|
23
|
+
# shopping_cart.add! coca_cola, by: current_person, unit_price: 3.50, quantity: 2
|
24
|
+
def add!(shopped, by: nil, unit_price: 0, quantity: 1, at: Time.now)
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
assert_present! :shopped, shopped
|
27
|
+
|
28
|
+
item = items.shopped_is(shopped).valid_at.alive.first
|
29
|
+
if item.present?
|
30
|
+
item.attributes = { shopper: by||shopper, unit_price: unit_price, quantity: quantity+item.quantity }
|
31
|
+
item.save!
|
32
|
+
else
|
33
|
+
items.create! shopped: shopped, shopper: by||shopper, unit_price: unit_price, quantity: quantity, opened_at: at
|
34
|
+
end
|
35
|
+
end
|
33
36
|
|
34
|
-
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Shopping::ShoppingCart'
|
37
|
+
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Shopping::ShoppingCart'
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -1,21 +1,27 @@
|
|
1
1
|
##
|
2
2
|
# Shopping Item 是购物项。
|
3
3
|
|
4
|
-
|
4
|
+
module Unidom
|
5
|
+
module Shopping
|
5
6
|
|
6
|
-
|
7
|
+
class ShoppingItem < ApplicationRecord
|
7
8
|
|
8
|
-
|
9
|
+
self.table_name = 'unidom_shopping_items'
|
9
10
|
|
10
|
-
|
11
|
-
validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Unidom::Common::MAXIMUM_AMOUNT }
|
11
|
+
include Unidom::Common::Concerns::ModelExtension
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
belongs_to :shopped, polymorphic: true
|
13
|
+
validates :unit_price, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Unidom::Common::MAXIMUM_AMOUNT }
|
14
|
+
validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Unidom::Common::MAXIMUM_AMOUNT }
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
belongs_to :shopping_cart, class_name: 'Unidom::Shopping::ShoppingCart'
|
17
|
+
belongs_to :shopper, polymorphic: true
|
18
|
+
belongs_to :shopped, polymorphic: true
|
20
19
|
|
21
|
-
|
20
|
+
scope :shopping_cart_is, ->(shopping_cart) { where shopping_cart: shopping_cart }
|
21
|
+
scope :shopped_by, ->(shopper) { where shopper: shopper }
|
22
|
+
scope :shopped_is, ->(shopped) { where shopped: shopped }
|
23
|
+
|
24
|
+
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Shopping::ShoppingItem'
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateUnidomShoppingCarts < ActiveRecord::Migration
|
1
|
+
class CreateUnidomShoppingCarts < ActiveRecord::Migration[6.0]
|
2
2
|
|
3
3
|
def change
|
4
4
|
|
@@ -9,7 +9,7 @@ class CreateUnidomShoppingCarts < ActiveRecord::Migration
|
|
9
9
|
t.references :shop, type: :uuid, null: false,
|
10
10
|
polymorphic: { null: false, default: '', limit: 200 }
|
11
11
|
|
12
|
-
t.column :state, 'char(1)', null: false, default:
|
12
|
+
t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
|
13
13
|
t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
|
14
14
|
t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
|
15
15
|
t.boolean :defunct, null: false, default: false
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateUnidomShoppingItems < ActiveRecord::Migration
|
1
|
+
class CreateUnidomShoppingItems < ActiveRecord::Migration[6.0]
|
2
2
|
|
3
3
|
def change
|
4
4
|
|
@@ -13,7 +13,7 @@ class CreateUnidomShoppingItems < ActiveRecord::Migration
|
|
13
13
|
t.decimal :unit_price, null: false, default: 0.0, precision: 12, scale: 2
|
14
14
|
t.decimal :quantity, null: false, default: 0.0, precision: 12, scale: 2
|
15
15
|
|
16
|
-
t.column :state, 'char(1)', null: false, default:
|
16
|
+
t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
|
17
17
|
t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
|
18
18
|
t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
|
19
19
|
t.boolean :defunct, null: false, default: false
|
@@ -23,7 +23,7 @@ class CreateUnidomShoppingItems < ActiveRecord::Migration
|
|
23
23
|
|
24
24
|
end
|
25
25
|
|
26
|
-
add_index :unidom_shopping_items, :shopping_cart_id
|
26
|
+
#add_index :unidom_shopping_items, :shopping_cart_id
|
27
27
|
add_index :unidom_shopping_items, :shopper_id
|
28
28
|
add_index :unidom_shopping_items, :shopped_id
|
29
29
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unidom-shopping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|
@@ -68,11 +68,11 @@ files:
|
|
68
68
|
- lib/unidom/shopping/types_rspec.rb
|
69
69
|
- lib/unidom/shopping/validators_rspec.rb
|
70
70
|
- lib/unidom/shopping/version.rb
|
71
|
-
homepage: https://
|
71
|
+
homepage: https://gitee.com/Unidom/unidom-shopping
|
72
72
|
licenses:
|
73
73
|
- MIT
|
74
74
|
metadata: {}
|
75
|
-
post_install_message:
|
75
|
+
post_install_message:
|
76
76
|
rdoc_options: []
|
77
77
|
require_paths:
|
78
78
|
- lib
|
@@ -87,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
requirements: []
|
90
|
-
rubygems_version: 3.
|
91
|
-
signing_key:
|
90
|
+
rubygems_version: 3.2.3
|
91
|
+
signing_key:
|
92
92
|
specification_version: 4
|
93
93
|
summary: Unidom Shopping Domain Model Engine 购物领域模型引擎
|
94
94
|
test_files: []
|