-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
67 lines (58 loc) · 1.1 KB
/
common.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
package model
type SortBy string
type SortOrder int
type History int
type QueryParameters struct {
ProductId string
Limit int
Offset int
History History
SortOrder SortOrder
SortBy SortBy
Category string
Error string
}
const (
Default SortBy = "" // ID
Name SortBy = "name"
Price SortBy = "price" // Latest price
Category SortBy = "category" // Category name
Ascending SortOrder = 1
Descending SortOrder = -1
Full History = 0
Last History = 1
None History = 2
)
func SortableBy() map[string]SortBy {
return map[string]SortBy{
"": Default,
"name": Name,
"price": Price,
"category": Category,
}
}
func SortOrders() map[string]SortOrder {
return map[string]SortOrder{
"asc": Ascending,
"desc": Descending,
}
}
func ResultHistory() map[string]History {
return map[string]History{
"full": Full,
"last": Last,
"none": None,
}
}
func MapQueryParamToDbField(param SortBy) string {
switch param {
case "name":
return "name"
case "price":
return "price-in-time.price"
case "category":
return "category-name"
default:
return ""
}
}