47 lines
942 B
Go
47 lines
942 B
Go
package noticerecdmod
|
|
|
|
import (
|
|
"91porn-server/common/pageopt"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
type RecordSlice []NoticeRecord
|
|
|
|
func (r RecordSlice) Len() int {
|
|
return len(r)
|
|
}
|
|
|
|
func (r RecordSlice) Swap(i, j int) {
|
|
r[i], r[j] = r[j], r[i]
|
|
}
|
|
|
|
func (r RecordSlice) Less(i, j int) bool {
|
|
return r[i].LastSendAt.Before(r[j].LastSendAt)
|
|
}
|
|
|
|
type Matcher = pageopt.Matcher
|
|
|
|
type UIDMatch = pageopt.UIDMatch
|
|
|
|
type NoticeCodeInMatch struct {
|
|
NoticeCodes []string
|
|
}
|
|
|
|
func (u *NoticeCodeInMatch) New() Matcher {
|
|
return pageopt.NewInMatch("noticeCode", u.NoticeCodes)
|
|
}
|
|
|
|
func List(sort bson.D, skip, limit int64, matchs ...Matcher) (RecordSlice, error) {
|
|
filter := pageopt.MergeM(matchs)
|
|
opt := (&options.FindOptions{})
|
|
if len(sort) != 0 {
|
|
opt.SetSort(sort)
|
|
}
|
|
opt.SetSkip(skip)
|
|
opt.SetLimit(limit)
|
|
list := make(RecordSlice, 0, limit)
|
|
return list, coll(nil).Find(&list, filter, opt)
|
|
}
|