/
board.go
60 lines (50 loc) · 2 KB
/
board.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
package model
import (
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
)
type Board struct {
Model `bson:",inline"`
UID primitive.ObjectID `json:"uid" bson:"uid"`
Organization *primitive.ObjectID `json:"organization,omitempty" bson:"organization,omitempty"`
Portfolio *primitive.ObjectID `json:"portfolio,omitempty" bson:"portfolio,omitempty"`
Type string `json:"type" bson:"type"`
Title string `json:"title" bson:"title"`
Description *string `json:"description,omitempty" bson:"description,omitempty"`
IsTemplate bool `json:"is_template,omitempty" bson:"is_template,omitempty"`
End *primitive.DateTime `json:"end,omitempty" bson:"end,omitempty"`
Starred bool `json:"starred,omitempty" bson:"starred,omitempty"`
Background string `json:"background,omitempty" bson:"background,omitempty"`
Order *int `json:"order,omitempty" bson:"order,omitempty"`
Status string `json:"status" bson:"status"`
}
func (Board) IsEntity() {}
func (i *Board) MarshalBSON() ([]byte, error) {
now := primitive.Timestamp{T: uint32(time.Now().Unix())}
if i.Created.IsZero() {
i.Created = now
}
i.Updated = now
type t Board
return bson.Marshal((*t)(i))
}
func (i *Board) Collection() string {
return "boards"
}
func (i *Board) Index() []mongo.IndexModel {
return []mongo.IndexModel{
{Keys: bson.D{{Key: "uid", Value: 1}}},
{Keys: bson.D{{Key: "organization", Value: 1}}},
{Keys: bson.D{{Key: "type", Value: 1}}},
{Keys: bson.D{{Key: "starred", Value: 1}}},
{Keys: bson.D{{Key: "order", Value: 1}}},
{Keys: bson.D{{Key: "status", Value: 1}}},
{Keys: bson.D{{Key: "is_template", Value: 1}}},
{Keys: bson.D{{Key: "end", Value: 1}}},
{Keys: bson.D{{Key: "created", Value: 1}}},
{Keys: bson.D{{Key: "updated", Value: 1}}},
{Keys: bson.D{{Key: "deleted", Value: 1}}},
}
}