/
campaign.go
46 lines (36 loc) · 1.11 KB
/
campaign.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
package model
import (
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
)
type Campaign struct {
Model `bson:",inline"`
Audience *primitive.ObjectID `json:"audience,omitempty" bson:"audience,omitempty"`
Type string `json:"type" bson:"type"`
Name string `json:"name" bson:"name"`
Metadata primitive.M `json:"metadata,omitempty" bson:"metadata,omitempty"`
Status string `json:"status" bson:"status"`
}
func (Campaign) IsEntity() {}
func (i *Campaign) MarshalBSON() ([]byte, error) {
now := primitive.Timestamp{T: uint32(time.Now().Unix())}
if i.Created.IsZero() {
i.Created = now
}
i.Updated = now
type t Campaign
return bson.Marshal((*t)(i))
}
func (i *Campaign) Collection() string {
return "campaigns"
}
func (i *Campaign) Index() []mongo.IndexModel {
return []mongo.IndexModel{
{Keys: bson.D{{Key: "audience", Value: 1}}},
{Keys: bson.D{{Key: "status", Value: 1}}},
{Keys: bson.D{{Key: "created", Value: 1}}},
{Keys: bson.D{{Key: "updated", Value: 1}}},
}
}