-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.go
88 lines (71 loc) · 2.45 KB
/
user.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
package user
import (
"github.com/vmihailenco/msgpack"
"time"
)
type Level uint8
const (
JWTExpirationTime = time.Hour * 24 * 10 // 10 days
LevelStringAdmin string = "admin"
LevelStringRegular string = "regular"
LevelRegular Level = 0
LevelAdmin Level = 1
)
type View struct {
ID string `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Password string `json:"password"`
UserLevel string `json:"user_level"`
Favorites *PersonalFavorites `json:"favorites"`
LastLoginTime string `json:"lastLoginTime"`
}
type Credential struct {
Username string `json:"username"`
Password string `json:"password"`
Email string `json:"email"`
WithOAuth bool `json:"withOAuth"`
}
type PasswordResetRequest struct {
Email string `json:"email"`
VerificationCode string `json:"code"`
NewPassword string `json:"new_password"`
}
type PersonalFavorites struct {
SearchHistory map[string]LastSearchRecord `json:"searchHistory"`
}
type LastSearchRecord struct {
Location string `json:"location"`
Count int `json:"count"`
LastSearchTimestamp string `json:"lastSearchTimestamp"`
}
func (p *PersonalFavorites) MarshalBinary() ([]byte, error) {
return msgpack.Marshal(p)
}
func (p *PersonalFavorites) UnmarshalBinary(data []byte) error {
return msgpack.Unmarshal(data, p)
}
// TravelPlaceView reflect what users see on Front-end result tables
type TravelPlaceView struct {
ID string `json:"id"`
TimePeriod string `json:"time_period"`
PlaceName string `json:"place_name"`
Address string `json:"address"`
URL string `json:"url"`
}
type TravelPlanView struct {
ID string `json:"id"`
OriginalPlanID string `json:"original_plan_id"`
CreatedAt string `json:"created_at"`
TravelDate string `json:"travel_date"`
Destination string `json:"destination"`
Places []TravelPlaceView `json:"places"`
}
type ByCreatedAt []TravelPlanView
func (plans ByCreatedAt) Len() int { return len(plans) }
func (plans ByCreatedAt) Swap(i, j int) { plans[i], plans[j] = plans[j], plans[i] }
func (plans ByCreatedAt) Less(i, j int) bool {
createdAtI, _ := time.Parse(time.RFC3339, plans[i].CreatedAt)
createdAtJ, _ := time.Parse(time.RFC3339, plans[j].CreatedAt)
return createdAtI.After(createdAtJ)
}