-
Notifications
You must be signed in to change notification settings - Fork 7
/
category.go
61 lines (48 loc) · 1.61 KB
/
category.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
package model
import (
"gopkg.in/mgo.v2/bson"
)
type Category struct {
Id bson.ObjectId `bson:"_id,omitempty" json:"id,omitempty"`
Name string `bson:"name" json:"name"`
Description string `bson:"description" json:"description"`
Slug string `bson:"slug" json:"slug"`
Color string `bson:"color" json:"color"`
Permissions CategoryAcl `bson:"permissions" json:"permissions"`
Parent bson.ObjectId `bson:"parent,omitempty" json:"parent,omitempty"`
Order int `bson:"order,omitempty" json:"order,omitempty"`
Count int `bson:"count,omitempty" json:"count,omitempty"`
Recent int `bson:"recent,omitempty" json:"recent,omitempty"`
Child []Category `bson:"subcategories,omitempty" json:"subcategories,omitempty"`
}
type CategoryAcl struct {
Read []string `bson:"read" json:"read"`
Write []string `bson:"write" json:"write"`
}
type CategoryCounters struct {
List []CategoryCounter `json:"list"`
}
type CategoryCounter struct {
Slug string `json:"slug"`
Count int `json:"count"`
}
type Categories []Category
func (slice Categories) Len() int {
return len(slice)
}
func (slice Categories) Less(i, j int) bool {
return slice[i].Count > slice[j].Count
}
func (slice Categories) Swap(i, j int) {
slice[i], slice[j] = slice[j], slice[i]
}
type CategoriesOrder []Category
func (slice CategoriesOrder) Len() int {
return len(slice)
}
func (slice CategoriesOrder) Less(i, j int) bool {
return slice[i].Order < slice[j].Order
}
func (slice CategoriesOrder) Swap(i, j int) {
slice[i], slice[j] = slice[j], slice[i]
}