@@ -0,0 +1,98 @@
|
||||
package noticefmtmod
|
||||
|
||||
import (
|
||||
"91porn-server/common/pageopt"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type Matcher = pageopt.Matcher
|
||||
|
||||
// EnableMatch
|
||||
type EnableMatch struct {
|
||||
Enable *bool
|
||||
}
|
||||
|
||||
func (t *EnableMatch) New() Matcher {
|
||||
return pageopt.NewAssignMatch("enable", t.Enable)
|
||||
}
|
||||
|
||||
// TitleMatch
|
||||
type TitleMatch struct {
|
||||
Title *string
|
||||
}
|
||||
|
||||
func (t *TitleMatch) New() Matcher {
|
||||
return pageopt.NewAssignMatch("title", t.Title)
|
||||
}
|
||||
|
||||
// NoticeCodeMatch
|
||||
type NoticeCodeMatch struct {
|
||||
NoticeCode *string
|
||||
}
|
||||
|
||||
func (t *NoticeCodeMatch) New() Matcher {
|
||||
return pageopt.NewAssignMatch("noticeCode", t.NoticeCode)
|
||||
}
|
||||
|
||||
// SenderMatch
|
||||
type SenderMatch struct {
|
||||
Sender *Sender
|
||||
}
|
||||
|
||||
func (t *SenderMatch) New() Matcher {
|
||||
return pageopt.NewAssignMatch("sender", t.Sender)
|
||||
}
|
||||
|
||||
// ReceiverMatch
|
||||
type ReceiverMatch struct {
|
||||
Receiver *Receiver
|
||||
}
|
||||
|
||||
func (t *ReceiverMatch) New() Matcher {
|
||||
return pageopt.NewAssignMatch("receiver", t.Receiver)
|
||||
}
|
||||
|
||||
// NoticeTypeMatch
|
||||
type NoticeTypeMatch struct {
|
||||
NoticeType *NoticeType
|
||||
}
|
||||
|
||||
func (t *NoticeTypeMatch) New() Matcher {
|
||||
return pageopt.NewAssignMatch("noticeType", t.NoticeType)
|
||||
}
|
||||
|
||||
type UIDListMatch struct {
|
||||
UID *uint64
|
||||
}
|
||||
|
||||
func (u *UIDListMatch) New() Matcher {
|
||||
return pageopt.NewAssignMatch("uidList", u.UID)
|
||||
}
|
||||
|
||||
type UIDListInMatch struct {
|
||||
UIDList []uint64
|
||||
}
|
||||
|
||||
func (u *UIDListInMatch) New() Matcher {
|
||||
return pageopt.NewInMatch("uidList", u.UIDList)
|
||||
}
|
||||
|
||||
func List(sort bson.D, skip, limit int64, matchs ...Matcher) ([]NoticeFmt, error) {
|
||||
filter := pageopt.MergeM(matchs)
|
||||
opt := (&options.FindOptions{})
|
||||
if len(sort) != 0 {
|
||||
opt.SetSort(sort)
|
||||
}
|
||||
opt.SetSkip(skip)
|
||||
opt.SetLimit(limit)
|
||||
|
||||
list := make([]NoticeFmt, 0, limit)
|
||||
return list, coll(nil).Find(&list, filter, opt)
|
||||
}
|
||||
|
||||
func Count(matchs ...Matcher) (int64, error) {
|
||||
filter := pageopt.MergeM(matchs)
|
||||
return coll(nil).Count(filter)
|
||||
}
|
||||
Reference in New Issue
Block a user