45 lines
914 B
Go
45 lines
914 B
Go
package visitlogmod
|
|
|
|
import (
|
|
"91porn-server/common/pageopt"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
type VisitLogSlice []VisitLog
|
|
|
|
func (v VisitLogSlice) ToUIDs() []uint64 {
|
|
uids := make([]uint64, len(v))
|
|
for i, l := range v {
|
|
uids[i] = l.UID
|
|
}
|
|
return uids
|
|
}
|
|
|
|
type Matcher = pageopt.Matcher
|
|
|
|
// CreatedAtGTEAndLTMatch
|
|
type CreatedAtGTEAndLTMatch = pageopt.CreatedAtGTEAndLTMatch
|
|
|
|
func List(sort bson.D, skip, limit *int64, mats ...Matcher) (VisitLogSlice, error) {
|
|
opt := (&options.FindOptions{})
|
|
if len(sort) != 0 {
|
|
opt.SetSort(sort)
|
|
}
|
|
if skip != nil {
|
|
opt.SetSkip(*skip)
|
|
}
|
|
if limit != nil {
|
|
opt.SetLimit(*limit)
|
|
}
|
|
filter := pageopt.MergeM(mats)
|
|
list := VisitLogSlice{}
|
|
return list, coll(nil).Find(&list, filter, opt)
|
|
}
|
|
|
|
func Count(matchs ...pageopt.Matcher) (int64, error) {
|
|
filter := pageopt.MergeM(matchs)
|
|
return coll(nil).Count(filter)
|
|
}
|