56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package followmod
|
|
|
|
import (
|
|
"91porn-server/common/pageopt"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
"time"
|
|
)
|
|
|
|
type Matcher = pageopt.Matcher
|
|
|
|
// CreatedAtGTEMatch
|
|
type CreatedAtGTEMatch struct {
|
|
GTE *time.Time
|
|
}
|
|
|
|
func (c *CreatedAtGTEMatch) New() Matcher {
|
|
return pageopt.NewGTEMatch("createdAt", c.GTE)
|
|
}
|
|
|
|
// FollowUIDMatch
|
|
type FollowUIDMatch struct {
|
|
FollowUID *uint64
|
|
}
|
|
|
|
func (f *FollowUIDMatch) New() Matcher {
|
|
return pageopt.NewAssignMatch("followUID", f.FollowUID)
|
|
}
|
|
|
|
// List
|
|
func List(sort bson.D, skip, limit int64, matchers ...Matcher) ([]FollowModel, error) {
|
|
filter := pageopt.MergeM(matchers)
|
|
opt := &options.FindOptions{}
|
|
if len(sort) != 0 {
|
|
opt.SetSort(sort)
|
|
}
|
|
opt.SetSkip(skip)
|
|
opt.SetLimit(limit)
|
|
list := make([]FollowModel, 0, limit)
|
|
err := coll(nil).Find(&list, filter, opt)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return list, nil
|
|
}
|
|
|
|
// Count
|
|
func Count(matchers ...Matcher) (int64, error) {
|
|
filter := pageopt.MergeM(matchers)
|
|
count, err := coll(nil).Count(filter)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return count, nil
|
|
}
|