-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathorder.go
93 lines (80 loc) · 2.33 KB
/
order.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
package anor
import (
"context"
"github.com/aliml92/anor/relation"
"github.com/shopspring/decimal"
"time"
)
type PaymentMethod string
const (
PaymentMethodStripeCard PaymentMethod = "StripeCard"
PaymentMethodPaypal PaymentMethod = "Paypal"
PaymentMethodAnorInstallment PaymentMethod = "AnorInstallment"
PaymentMethodPayOnDelivery PaymentMethod = "PayOnDelivery"
)
type PaymentStatus string
const (
PaymentStatusPending PaymentStatus = "Pending"
PaymentStatusPaid PaymentStatus = "Paid"
)
type OrderStatus string
const (
OrderStatusPending OrderStatus = "Pending"
OrderStatusProcessing OrderStatus = "Processing"
OrderStatusShipped OrderStatus = "Shipped"
OrderStatusDelivered OrderStatus = "Delivered"
OrderStatusCanceled OrderStatus = "Canceled"
)
type Order struct {
ID int64
UserID int64
CartID int64
PaymentMethod PaymentMethod
PaymentStatus PaymentStatus
Status OrderStatus
ShippingAddressID int64
IsPickup bool
Amount decimal.Decimal
Currency string
CreatedAt time.Time
UpdatedAt time.Time
// Related structs that can be eagerly loaded
OrderItems []*OrderItem
ShippingAddress Address
StripeCardPayment StripeCardPayment
DeliveryDate time.Time
}
type OrderItem struct {
ID int64
OrderID int64
VariantID int64
Qty int32
Price decimal.Decimal
Thumbnail string
ProductName string
VariantAttributes map[string]string
CreatedAt time.Time
UpdatedAt time.Time
}
type OrderCreateParams struct {
Cart Cart
PaymentMethod PaymentMethod
PaymentStatus PaymentStatus
ShippingAddressID int64
IsPickup bool
Amount decimal.Decimal
Currency string
}
type OrderListParams struct {
UserID int64
WithRelations relation.Set
Page int
PageSize int
}
type OrderService interface {
Create(ctx context.Context, params OrderCreateParams) (int64, error)
Get(ctx context.Context, orderID int64, withItems bool) (Order, error)
List(ctx context.Context, params OrderListParams) ([]Order, error)
ListActive(ctx context.Context, params OrderListParams) ([]Order, error)
ListUnpaid(ctx context.Context, params OrderListParams) ([]Order, error)
}