/
collaborator.go
47 lines (37 loc) · 1.14 KB
/
collaborator.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
package model
import (
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
)
type Collaborator struct {
Model `bson:",inline"`
UID primitive.ObjectID `json:"uid" bson:"uid"`
Board primitive.ObjectID `json:"board,omitempty" bson:"board,omitempty"`
Permission string `json:"permission" bson:"permission"`
Status string `json:"status" bson:"status"`
}
func (Collaborator) IsEntity() {}
func (i *Collaborator) MarshalBSON() ([]byte, error) {
now := primitive.Timestamp{T: uint32(time.Now().Unix())}
if i.Created.IsZero() {
i.Created = now
}
i.Updated = now
type t Collaborator
return bson.Marshal((*t)(i))
}
func (i *Collaborator) Collection() string {
return "collaborators"
}
func (i *Collaborator) Index() []mongo.IndexModel {
return []mongo.IndexModel{
{Keys: bson.D{{Key: "uid", Value: 1}}},
{Keys: bson.D{{Key: "board", Value: 1}}},
{Keys: bson.D{{Key: "status", Value: 1}}},
{Keys: bson.D{{Key: "created", Value: 1}}},
{Keys: bson.D{{Key: "updated", Value: 1}}},
{Keys: bson.D{{Key: "deleted", Value: 1}}},
}
}