/
products.go
73 lines (62 loc) · 2.92 KB
/
products.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
package db
import (
"context"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"github.com/nam-truong-le/lambda-utils-go/v3/pkg/aws/ssm"
"github.com/nam-truong-le/lambda-utils-go/v3/pkg/mongodb"
)
const colProducts = "products"
func CollectionProducts(ctx context.Context) (*mongo.Collection, error) {
database, err := ssm.GetParameter(ctx, "/mongo/database", false)
if err != nil {
return nil, err
}
return mongodb.Collection(ctx, database, colProducts)
}
type ProductType string
const (
ProductTypeSimple ProductType = "simple"
ProductTypeVariable ProductType = "variable"
)
type ProductAttribute struct {
WPID int `bson:"id" json:"wpId"` // it's ok in patch request because we won't change this
Name string `bson:"name" json:"name"`
Position int `bson:"position" json:"position"`
Variation bool `bson:"variation" json:"variation"`
Visible bool `bson:"visible" json:"visible"`
Options []string `bson:"options" json:"options"`
}
type ProductVariationAttribute struct {
WPID int `bson:"id" json:"wpId"` // it's ok in patch request because we won't change this
Name string `bson:"name" json:"name"`
Option string `bson:"option" json:"option"`
}
type ProductVariation struct {
WPID int `bson:"id" json:"wpId"` // it's ok in patch request because we won't change this
Price string `bson:"price" json:"price"`
RegularPrice string `bson:"regularPrice" json:"regularPrice"`
SalePrice string `bson:"salePrice" json:"salePrice"`
Attributes []ProductVariationAttribute `bson:"attributes" json:"attributes"`
}
type Product struct {
ID primitive.ObjectID `bson:"_id" json:"id"`
WPID int `bson:"id" json:"wpId"` // it's ok in patch request because we won't change this
Name string `bson:"name" json:"name"`
Permalink string `bson:"permalink" json:"permalink"`
Type ProductType `bson:"type" json:"type"`
SKU string `bson:"sku" json:"sku"`
Price string `bson:"price" json:"price"`
RegularPrice string `bson:"regularPrice" json:"regularPrice"`
SalePrice string `bson:"salePrice" json:"salePrice"`
TaxClass string `bson:"taxClass" json:"taxClass"`
Categories []string `bson:"categories" json:"categories"`
Images []string `bson:"images" json:"images"`
Attributes []ProductAttribute `bson:"attributes" json:"attributes"`
Variations []ProductVariation `bson:"variations" json:"variations"`
OutOfStockIn []string `bson:"outOfStockIn" json:"outOfStockIn"`
Pfand string `bson:"pfand" json:"pfand"`
CreatedAt time.Time `bson:"createdAt" json:"createdAt"`
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"`
}