/
utils.go
69 lines (57 loc) · 1.58 KB
/
utils.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
68
69
package follow_content
import (
"context"
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
)
func (self *Model) FilterByFollowRelationshipID(followRelationshipID primitive.ObjectID) bson.D {
return bson.D{
{"follow_relationship_id", followRelationshipID},
}
}
func (self *Model) FilterByUserID(userID primitive.ObjectID) bson.D {
return bson.D{
{"user_id", userID},
}
}
func (self *Model) FilterByContentID(contentID primitive.ObjectID) bson.D {
return bson.D{
{"content_id", contentID},
}
}
func (self *Model) FilterByTypes(types []int) bson.D {
if len(types) == 0 {
return bson.D{}
}
filter := bson.D{
{"type", bson.D{
{"$in", types},
}},
}
return filter
}
func (self *Model) FilterByType(typ int) bson.D {
return bson.D{
{"type", typ},
}
}
func (self *Model) FilterByExtensionID(extensionID primitive.ObjectID) bson.D {
return bson.D{
{"extension_id", extensionID},
}
}
func (self *Model) SetReadedTimeByID(ctx context.Context, id primitive.ObjectID, readedTime time.Time) (*mongo.UpdateResult, error) {
return self.Set(ctx, self.FilterByID(id), bson.D{
{"readed_time", readedTime},
})
}
func (self *Model) SetAllReadedTimeByUserIDAndContentID(ctx context.Context, userID, contentID primitive.ObjectID, readedTime time.Time) (*mongo.UpdateResult, error) {
filter := self.FilterByUserID(userID)
filter = append(filter, self.FilterByContentID(contentID)...)
return self.UpdateMany(ctx, filter, self.DataSet(bson.D{
{"readed_time", readedTime},
{"update_time", time.Now()},
}))
}