forked from aliml92/anor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress.go
76 lines (65 loc) · 1.56 KB
/
address.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
package anor
import (
"context"
"time"
)
type AddressDefaultType string
const (
AddressDefaultTypeShipping AddressDefaultType = "Shipping"
AddressDefaultTypeBilling AddressDefaultType = "Billing"
)
type Address struct {
ID int64
UserID int64
DefaultFor AddressDefaultType
Name string
AddressLine1 string
AddressLine2 string
City string
StateProvince string
PostalCode string
Country string
Phone string
CreatedAt time.Time
UpdatedAt time.Time
}
func (a Address) Equals(b Address) bool {
eq := a.ID == b.ID &&
a.UserID == b.UserID &&
a.Name == b.Name &&
a.AddressLine1 == b.AddressLine1 &&
a.AddressLine2 == b.AddressLine2 &&
a.City == b.City &&
a.StateProvince == b.StateProvince &&
a.PostalCode == b.PostalCode &&
a.Country == b.Country
return eq
}
func (a Address) IsZero() bool {
if a.ID == 0 {
return true
}
return false
}
type AddressCreateParams struct {
UserID int64
DefaultFor AddressDefaultType
Name string
AddressLine1 string
AddressLine2 string
City string
StateProvince string
PostalCode string
Country string
}
type AddressListParams struct {
UserID int64
Page int
PageSize int
}
type AddressService interface {
Create(ctx context.Context, params AddressCreateParams) (Address, error)
Get(ctx context.Context, id int64) (Address, error)
GetDefault(ctx context.Context, userID int64, defaultFor AddressDefaultType) (Address, error)
List(ctx context.Context, params AddressListParams) ([]Address, error)
}