forked from aliml92/anor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.go
162 lines (138 loc) · 3.82 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package anor
import (
"context"
"github.com/aliml92/anor/relation"
"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
Status ProductStatus
CreatedAt time.Time
UpdatedAt time.Time
}
type Product struct {
ID int64
StoreID int32
CategoryID int32
Name string
Brand string
Handle string
ShortInformation []string
ImageUrls map[int]string
Specifications map[string]string
Status ProductStatus
CreatedAt time.Time
UpdatedAt time.Time
Store Store
Category Category
ProductVariants []ProductVariant
Attributes []ProductAttribute
Pricing ProductPricing
Rating Rating
Reviews []ProductRating
SoldCount int
LeftCount int
}
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
Pricing ProductVariantPricing `json:"-"` // TODO: implement
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
Attributes map[string]string `json:"attributes"`
}
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 ListByCategoryParams struct {
With relation.Set
Filter FilterParam
Sort SortParam
Paging Paging
}
type PopularProductListParams struct {
Page int
PageSize int
}
type ProductService interface {
Get(ctx context.Context, id int64, with relation.Set) (*Product, error)
ListByCategory(ctx context.Context, category Category, params ListByCategoryParams) ([]Product, int64, error)
ListAllBrandsByCategory(ctx context.Context, category Category) ([]string, error)
GetMinMaxPricesByCategory(ctx context.Context, category Category) ([2]decimal.Decimal, error)
ListPopularProducts(ctx context.Context, params PopularProductListParams) ([]Product, error)
}