-
Notifications
You must be signed in to change notification settings - Fork 0
/
product.go
144 lines (123 loc) · 3.7 KB
/
product.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package anor
import (
"context"
"time"
"github.com/shopspring/decimal"
)
type ProductStatus string
const (
ProductStatusDraft ProductStatus = "Draft"
ProductStatusPendingApproval ProductStatus = "PendingApproval"
ProductStatusPublished ProductStatus = "Published"
)
type SortParam string
const (
SortParamPopular SortParam = "popular"
SortParamPriceHighToLow SortParam = "price_high_to_low"
SortParamPriceLowToHigh SortParam = "price_low_to_high"
SortParamHighestRated SortParam = "highest_rated"
SortParamNewArrivals SortParam = "new_arrivals"
SortParamBestSellers SortParam = "best_sellers"
)
type FilterParam struct {
Rating int
PriceFrom decimal.Decimal
PriceTo decimal.Decimal
Brands []string
Colors []string
Sizes []string
}
func (p FilterParam) IsZero() bool {
return p.Rating == 0 &&
p.PriceFrom.IsZero() &&
p.PriceTo.IsZero() &&
len(p.Brands) == 0
}
type Paging struct {
Page int
PageSize int
}
type BaseProduct struct {
ID int64
StoreID int32
CategoryID int32
Name string
Brand string
Handle string
ShortInformation []string
ImageUrls map[int]string
Specifications map[string]string // product item specifications, e.g. Ebay
Status ProductStatus
CreatedAt time.Time
UpdatedAt time.Time
}
type Product struct {
BaseProduct
Store Store
Category Category
ProductVariants []ProductVariant
Pricing ProductPricing
Rating Rating
Reviews []ProductRating // Product Reviews
SoldCount int
LeftCount int
Attributes []ProductAttribute
}
type ProductAttribute struct {
Attribute string
Values []string
}
type ProductVariant struct {
ID int64 `json:"id"`
SKU string `json:"sku"`
Qty int32 `json:"quantity"`
IsCustomPriced bool `json:"-"` // TODO: implement
ImageIdentifiers []int16 `json:"-"` // TODO: implement
Attributes map[string]string `json:"attributes"`
Pricing ProductVariantPricing `json:"-"` // TODO: implement
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
}
type ProductPricing struct {
ProductID int64
BasePrice decimal.Decimal
CurrencyCode string
Discount decimal.Decimal
DiscountedPrice decimal.Decimal
IsOnSale bool
}
type ProductVariantPricing struct {
VariantID int64
BasePrice decimal.Decimal
CurrencyCode string
Discount decimal.Decimal
DiscountedPrice decimal.Decimal
IsOnSale bool
}
type ProductRating struct {
ID int64
ProductID int64
UserID int64
Rating int16
Review string
ImageUrls []string
CreatedAt time.Time
}
type Rating struct {
Rating float32
RatingCount int
}
type GetProductsByCategoryParams struct {
Filter FilterParam
Sort SortParam
Paging Paging
}
type ProductService interface {
GetProduct(ctx context.Context, id int64) (*Product, error)
GetProductsByLeafCategoryID(ctx context.Context, categoryID int32, params GetProductsByCategoryParams) ([]Product, int64, error)
GetProductsByNonLeafCategoryID(ctx context.Context, categoryID int32, params GetProductsByCategoryParams) ([]Product, int64, error)
GetProductsByCategory(ctx context.Context, category Category, params GetProductsByCategoryParams) ([]Product, int64, error)
GetProductBrandsByCategory(ctx context.Context, category Category) ([]string, error)
GetMinMaxPricesByCategory(ctx context.Context, category Category) ([2]decimal.Decimal, error)
GetNewArrivals(ctx context.Context, limit int) ([]Product, error)
}